1
/***************************************************************************
2
* Copyright (C) 2005 by Alexander Dymo *
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. *
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. *
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
***************************************************************************/
23
#include <qlineedit.h>
25
#include <qfiledialog.h>
26
#include <qtextedit.h>
28
#include <qtextstream.h>
29
#include <qlistview.h>
30
#include <qtabwidget.h>
33
#include <qmakedriver.h>
34
#include <qmakeastvisitor.h>
36
using namespace QMake;
38
Viewer::Viewer(QWidget *parent, const char *name)
39
:ViewerBase(parent, name), projectAST(0)
41
if (QFile::exists(QDir::currentDirPath() + "/" + "qtlist"))
43
QFile f(QDir::currentDirPath() + "/" + "qtlist");
47
files->insertItem(str.readLine());
50
// parentProject.push((QListViewItem*)0);
53
void Viewer::addAll_clicked()
55
if (allLocation->text().isEmpty())
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);
64
void Viewer::choose_clicked()
66
QString fileName = QFileDialog::getOpenFileName(QDir::currentDirPath(), "*.pro *.pri", this);
67
if (!fileName.isEmpty())
68
files->insertItem(fileName);
71
void Viewer::files_currentChanged(QListBoxItem* item)
75
QFile f(item->text());
78
source->setText(str.read());
81
int result = QMake::Driver::parseFile(item->text().ascii(), &projectAST, 0);
82
if (projectAST && (result == 0))
84
processAST(projectAST);
86
if (tabWidget2->currentPageIndex() == 1)
87
tabWidget2_selected("Source to be written back");
90
void Viewer::tabWidget2_selected(const QString& text)
92
if ((text == "Source to Be Written Back") && projectAST)
95
projectAST->writeBack(buffer);
96
writeBack->setText(buffer);
100
class ViewerVisitor: public ASTVisitor {
102
ViewerVisitor(Viewer *v): ASTVisitor()
105
parentProject.push((QListViewItem*)0);
108
virtual void processProject(ProjectAST *project)
110
ASTVisitor::processProject(project);
113
virtual void enterRealProject(ProjectAST *project)
115
QListViewItem *projectIt;
116
if (!parentProject.top())
118
projectIt = new QListViewItem(v->ast, "Project");
119
projectIt->setOpen(true);
120
parentProject.push(projectIt);
123
ASTVisitor::enterRealProject(project);
125
virtual void enterScope(ProjectAST *scope)
127
QListViewItem *projectIt = new QListViewItem(parentProject.top(), scope->scopedID, "scope");
128
parentProject.push(projectIt);
129
ASTVisitor::enterScope(scope);
131
virtual void leaveScope(ProjectAST *scope)
135
virtual void enterFunctionScope(ProjectAST *fscope)
137
QListViewItem *projectIt = new QListViewItem(parentProject.top(),
138
fscope->scopedID + "(" + fscope->args + ")", "function scope");
139
parentProject.push(projectIt);
140
ASTVisitor::enterFunctionScope(fscope);
142
virtual void leaveFunctionScope(ProjectAST *fscope)
146
virtual void processAssignment(AssignmentAST *assignment)
148
QListViewItem *item = new QListViewItem(parentProject.top(),
149
assignment->scopedID, assignment->op, assignment->values.join("|"),
151
item->setMultiLinesEnabled(true);
153
ASTVisitor::processAssignment(assignment);
155
virtual void processNewLine(NewLineAST *newline)
157
new QListViewItem(parentProject.top(), "<newline>");
158
ASTVisitor::processNewLine(newline);
160
virtual void processComment(CommentAST *comment)
162
new QListViewItem(parentProject.top(), "<comment>");
163
ASTVisitor::processComment(comment);
165
virtual void processInclude(IncludeAST *include)
167
new QListViewItem(parentProject.top(), "<include>", include->projectName);
168
QMake::ASTVisitor::processInclude(include);
172
QValueStack<QListViewItem *> parentProject;
176
void Viewer::processAST(QMake::ProjectAST *projectAST, QListViewItem *globAfter)
178
ViewerVisitor visitor(this);
179
visitor.processProject(projectAST);
182
#include "viewer.moc"