~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to buildtools/lib/parsers/qmake/tests/viewer.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2010-05-05 07:21:55 UTC
  • mfrom: (1.2.3 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100505072155-h78lx19pu04sbhtn
Tags: 4:4.0.0-2
* Upload to unstable (Closes: #579947, #481832).
* Acknowledge obsolete NMU fixes (Closes: #562410, #546961).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
 *   Copyright (C) 2005 by Alexander Dymo                                  *
3
 
 *   adymo@kdevelop.org                                                    *
4
 
 *                                                                         *
5
 
 *   This program is free software; you can redistribute it and/or modify  *
6
 
 *   it under the terms of the GNU Library General Public License as       *
7
 
 *   published by the Free Software Foundation; either version 2 of the    *
8
 
 *   License, or (at your option) any later version.                       *
9
 
 *                                                                         *
10
 
 *   This program is distributed in the hope that it will be useful,       *
11
 
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12
 
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13
 
 *   GNU General Public License for more details.                          *
14
 
 *                                                                         *
15
 
 *   You should have received a copy of the GNU Library General Public     *
16
 
 *   License along with this program; if not, write to the                 *
17
 
 *   Free Software Foundation, Inc.,                                       *
18
 
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19
 
 ***************************************************************************/
20
 
#include "viewer.h"
21
 
 
22
 
#include <qdir.h>
23
 
#include <qlineedit.h>
24
 
#include <qlistbox.h>
25
 
#include <qfiledialog.h>
26
 
#include <qtextedit.h>
27
 
#include <qfile.h>
28
 
#include <qtextstream.h>
29
 
#include <qlistview.h>
30
 
#include <qtabwidget.h>
31
 
 
32
 
#include <qmakeast.h>
33
 
#include <qmakedriver.h>
34
 
#include <qmakeastvisitor.h>
35
 
 
36
 
using namespace QMake;
37
 
 
38
 
Viewer::Viewer(QWidget *parent, const char *name)
39
 
    :ViewerBase(parent, name), projectAST(0)
40
 
{
41
 
    if (QFile::exists(QDir::currentDirPath() + "/" + "qtlist"))
42
 
    {
43
 
        QFile f(QDir::currentDirPath() + "/" + "qtlist");
44
 
        f.open(IO_ReadOnly);
45
 
        QTextStream str(&f);
46
 
        while (!str.eof())
47
 
            files->insertItem(str.readLine());
48
 
    }
49
 
    ast->setSorting(-1);
50
 
//    parentProject.push((QListViewItem*)0);
51
 
}
52
 
 
53
 
void Viewer::addAll_clicked()
54
 
{
55
 
    if (allLocation->text().isEmpty())
56
 
        return;
57
 
    QDir d(allLocation->text());
58
 
    QStringList l = d.entryList("*.pro *.pri");
59
 
    for (QStringList::iterator it = l.begin(); it != l.end(); ++it)
60
 
        (*it) = QDir::cleanDirPath(allLocation->text() + "/" + (*it));
61
 
    files->insertStringList(l);
62
 
}
63
 
 
64
 
void Viewer::choose_clicked()
65
 
{
66
 
    QString fileName = QFileDialog::getOpenFileName(QDir::currentDirPath(), "*.pro *.pri", this);
67
 
    if (!fileName.isEmpty())
68
 
        files->insertItem(fileName);
69
 
}
70
 
 
71
 
void Viewer::files_currentChanged(QListBoxItem* item)
72
 
{
73
 
    ast->clear();
74
 
 
75
 
    QFile f(item->text());
76
 
    f.open(IO_ReadOnly);
77
 
    QTextStream str(&f);
78
 
    source->setText(str.read());
79
 
    f.close();
80
 
 
81
 
    int result = QMake::Driver::parseFile(item->text().ascii(), &projectAST, 0);
82
 
    if (projectAST && (result == 0))
83
 
    {
84
 
        processAST(projectAST);
85
 
    }
86
 
    if (tabWidget2->currentPageIndex() == 1)
87
 
        tabWidget2_selected("Source to be written back");
88
 
}
89
 
 
90
 
void Viewer::tabWidget2_selected(const QString& text)
91
 
{
92
 
    if ((text == "Source to Be Written Back") && projectAST)
93
 
    {
94
 
        QString buffer;
95
 
        projectAST->writeBack(buffer);
96
 
        writeBack->setText(buffer);
97
 
    }
98
 
}
99
 
 
100
 
class ViewerVisitor: public ASTVisitor {
101
 
public:
102
 
    ViewerVisitor(Viewer *v): ASTVisitor()
103
 
    {
104
 
        this->v = v;
105
 
        parentProject.push((QListViewItem*)0);
106
 
    }
107
 
 
108
 
    virtual void processProject(ProjectAST *project)
109
 
    {
110
 
        ASTVisitor::processProject(project);
111
 
    }
112
 
 
113
 
    virtual void enterRealProject(ProjectAST *project)
114
 
    {
115
 
        QListViewItem *projectIt;
116
 
        if (!parentProject.top())
117
 
        {
118
 
            projectIt = new QListViewItem(v->ast, "Project");
119
 
            projectIt->setOpen(true);
120
 
            parentProject.push(projectIt);
121
 
        }
122
 
 
123
 
        ASTVisitor::enterRealProject(project);
124
 
    }
125
 
    virtual void enterScope(ProjectAST *scope)
126
 
    {
127
 
        QListViewItem *projectIt = new QListViewItem(parentProject.top(), scope->scopedID, "scope");
128
 
        parentProject.push(projectIt);
129
 
        ASTVisitor::enterScope(scope);
130
 
    }
131
 
    virtual void leaveScope(ProjectAST *scope)
132
 
    {
133
 
        parentProject.pop();
134
 
    }
135
 
    virtual void enterFunctionScope(ProjectAST *fscope)
136
 
    {
137
 
        QListViewItem *projectIt = new QListViewItem(parentProject.top(),
138
 
            fscope->scopedID + "(" + fscope->args + ")", "function scope");
139
 
        parentProject.push(projectIt);
140
 
        ASTVisitor::enterFunctionScope(fscope);
141
 
    }
142
 
    virtual void leaveFunctionScope(ProjectAST *fscope)
143
 
    {
144
 
        parentProject.pop();
145
 
    }
146
 
    virtual void processAssignment(AssignmentAST *assignment)
147
 
    {
148
 
        QListViewItem *item = new QListViewItem(parentProject.top(),
149
 
                assignment->scopedID, assignment->op, assignment->values.join("|"),
150
 
                "assignment");
151
 
        item->setMultiLinesEnabled(true);
152
 
 
153
 
        ASTVisitor::processAssignment(assignment);
154
 
    }
155
 
    virtual void processNewLine(NewLineAST *newline)
156
 
    {
157
 
        new QListViewItem(parentProject.top(), "<newline>");
158
 
        ASTVisitor::processNewLine(newline);
159
 
    }
160
 
    virtual void processComment(CommentAST *comment)
161
 
    {
162
 
        new QListViewItem(parentProject.top(), "<comment>");
163
 
        ASTVisitor::processComment(comment);
164
 
    }
165
 
    virtual void processInclude(IncludeAST *include)
166
 
    {
167
 
        new QListViewItem(parentProject.top(), "<include>", include->projectName);
168
 
        QMake::ASTVisitor::processInclude(include);
169
 
    }
170
 
 
171
 
    Viewer *v;
172
 
    QValueStack<QListViewItem *> parentProject;
173
 
};
174
 
 
175
 
 
176
 
void Viewer::processAST(QMake::ProjectAST *projectAST, QListViewItem *globAfter)
177
 
{
178
 
    ViewerVisitor visitor(this);
179
 
    visitor.processProject(projectAST);
180
 
}
181
 
 
182
 
#include "viewer.moc"