Permalink
Browse files

Various project, rule and graph improvements

The Edit class now correctly sets the first opened file as the current
file when the project is open rather than waiting for the user to click
on one of the tree widget items.
GPFile tracks internal file changes in order to prevent the file system
watcher from triggering an external edit flag during the save operation.
The Graph object can now extract all of the variables contained within
its elements as a QStringList
GraphScene better handles reloading existing RHS graphs, it now ensures
that all phantom nodes and edges are marked as deleted in the
visualisation.
List can now output a QStringList of all of the identifiers in this
particular list.
Rule now trims the documentation string to prevent an ever increasing
set of new lines and spaces.
RuleEdit populates the variables table based on the variables contained
in both graphs.
Switched a +() in ruleparser.cpp to a *() to allow for completely empty
conditions.
  • Loading branch information...
aelliott committed Apr 18, 2013
1 parent f17b8c1 commit 242bbc1b94f477c38cde9053e80fbf3bed4a934e
View
@@ -13,6 +13,7 @@ Edit::Edit(QWidget *parent)
: QWidget(parent)
, _ui(new Ui::Edit)
, _project(0)
, _currentFile(0)
{
_ui->setupUi(this);
@@ -41,15 +42,49 @@ void Edit::setProject(Project *project)
return;
}
_project = project;
_currentFile = 0;
// Set up rule edit
if(_project->rules().count() > 0)
_ui->ruleEdit->setRule(_project->rules().at(0));
{
Rule *rule = _project->rules().at(0);
_ui->ruleEdit->setRule(rule);
if(_ui->stackedWidget->currentIndex() == 0)
{
_project->setCurrentFile(rule->absolutePath(), Project::RuleFile);
_currentFile = rule;
}
}
else
_ui->ruleEdit->setEnabled(false);
// Set up program edit
if(_project->programs().count() > 0)
_ui->programEdit->setProgram(_project->programs().at(0));
{
Program *prog = _project->programs().at(0);
_ui->programEdit->setProgram(prog);
if(_ui->stackedWidget->currentIndex() == 1)
{
_project->setCurrentFile(prog->absolutePath(), Project::ProgramFile);
_currentFile = prog;
}
}
else
_ui->graphEdit->setEnabled(false);
if(_project->graphs().count() > 0)
_ui->graphEdit->setGraph(_project->graphs().at(0));
{
Graph *graph = _project->graphs().at(0);
_ui->graphEdit->setGraph(graph);
if(_ui->stackedWidget->currentIndex() == 2)
{
_project->setCurrentFile(graph->absolutePath(), Project::GraphFile);
_currentFile = graph;
}
}
else
_ui->graphEdit->setEnabled(false);
connect(_project, SIGNAL(fileListChanged()), this, SLOT(fileListChanged()));
connect(_project, SIGNAL(fileStatusChanged(QString,int)),
@@ -67,24 +102,51 @@ void Edit::fileClicked(QTreeWidgetItem *item)
// Handle a clicked rule
if(parent->text(0) == tr("Rules"))
{
Rule *rule = _project->rule(item->text(0));
if(rule == 0)
{
qDebug() << "Edit::fileClicked() could not find rule: "
<< item->text(0);
return;
}
_ui->ruleEdit->setEnabled(true);
_ui->stackedWidget->setCurrentIndex(0);
_ui->ruleEdit->setRule(_project->rule(item->text(0)));
_ui->ruleEdit->setRule(rule);
_currentFile = rule;
_project->setCurrentFile(item->text(0), Project::RuleFile);
}
// Handle a clicked program
if(parent->text(0) == tr("Programs"))
{
Program *prog = _project->program(item->text(0));
if(prog == 0)
{
qDebug() << "Edit::fileClicked() could not find program: "
<< item->text(0);
return;
}
_ui->programEdit->setEnabled(true);
_ui->stackedWidget->setCurrentIndex(1);
_ui->programEdit->setProgram(_project->program(item->text(0)));
_ui->programEdit->setProgram(prog);
_currentFile = prog;
_project->setCurrentFile(item->text(0), Project::ProgramFile);
}
// Handle a clicked graph
if(parent->text(0) == tr("Graphs"))
{
Graph *graph = _project->graph(item->text(0));
if(graph == 0)
{
qDebug() << "Edit::fileClicked() could not find graph: "
<< item->text(0);
return;
}
_ui->graphEdit->setEnabled(true);
_ui->stackedWidget->setCurrentIndex(2);
_ui->graphEdit->setGraph(_project->graph(item->text(0)));
_ui->graphEdit->setGraph(graph);
_currentFile = graph;
_project->setCurrentFile(item->text(0), Project::GraphFile);
}
}
@@ -227,15 +289,24 @@ void Edit::fileListChanged()
void Edit::fileStatusChanged(QString path, int status)
{
if(!_treeMap.contains(_project->file(path)))
GPFile *file = _project->file(path);
if(file == 0)
{
qDebug() << "Edit::fileStatusChanged() could not locate the file with "
<< "the provided path: " << path;
return;
}
if(!_treeMap.contains(file))
{
qDebug() << "Edit::fileStatusChanged called but could not locate file.";
qDebug() << "path = " << path;
qDebug() << "status = " << status;
return;
}
QTreeWidgetItem *item = _treeMap[_project->file(path)];
QTreeWidgetItem *item = _treeMap[file];
if(item == 0)
return;
@@ -258,6 +329,7 @@ void Edit::fileStatusChanged(QString path, int status)
item->setIcon(0, QIcon());
break;
default:
qDebug() << "Unhandled status: " << status;
// Do nothing
break;
}
View
@@ -90,6 +90,7 @@ public slots:
Ui::Edit *_ui;
Project *_project;
QMap<GPFile *, QTreeWidgetItem *> _treeMap;
GPFile *_currentFile;
};
}
View
@@ -15,6 +15,7 @@ GPFile::GPFile(const QString &filePath, QObject *parent)
, _fileWatcher(0)
, _fp(0)
, _status(GPFile::Modified)
, _internalChanges(0)
{
_fileWatcher = new QFileSystemWatcher(this);
connect(_fileWatcher, SIGNAL(fileChanged(QString)),
@@ -177,6 +178,12 @@ bool GPFile::open()
void GPFile::fileChanged(const QString &filePath)
{
if(_internalChanges > 0)
{
--_internalChanges;
return;
}
if(filePath != _path)
{
qDebug() << "File path mismatch:";
@@ -188,6 +195,7 @@ void GPFile::fileChanged(const QString &filePath)
// This might need logic for when a change is made within the application
// The status should only change for external edits
_status = GPFile::ExternallyModified;
emit statusChanged(_status);
}
}
View
@@ -198,6 +198,8 @@ protected slots:
* \brief The file's current status
*/
FileStatus _status;
int _internalChanges;
};
}
View
@@ -41,6 +41,7 @@ bool Graph::save()
}
_fp->close();
++_internalChanges;
_fp->open(QFile::Truncate | QFile::WriteOnly);
qDebug() << "Saving graph file: " << _fp->fileName();
@@ -68,6 +69,7 @@ bool Graph::save()
break;
}
++_internalChanges;
int status = _fp->write(QVariant(saveText).toByteArray());
if(status <= 0)
{
@@ -124,11 +126,13 @@ bool Graph::saveAs(const QString &filePath)
return false;
}
// Update the file watcher
bool ret = GPFile::saveAs(_path);
// Delete the old file as the move was successful
QFile(pathCache).remove();
// Update the file watcher
return GPFile::saveAs(_path);
return ret;
}
bool Graph::exportTo(const QString &filePath, GraphTypes outputType)
@@ -370,6 +374,27 @@ std::vector<Edge *> Graph::edgesTo(const QString &id) const
return result;
}
QStringList Graph::variables() const
{
QStringList result;
for(nodeConstIter iter = _nodes.begin(); iter != _nodes.end(); ++iter)
{
Node *n = *iter;
result += n->label().variables();
}
for(edgeConstIter iter = _edges.begin(); iter != _edges.end(); ++iter)
{
Edge *e = *iter;
result += e->label().variables();
}
result.removeDuplicates();
return result;
}
bool Graph::contains(const QString &id) const
{
return (containsNode(id) || containsEdge(id));
@@ -543,13 +568,16 @@ QString Graph::toAlternative() const
result += ")";
// Add the nodes
bool added = false;
bool first = true;
for(size_t i = 0; i < _nodes.size(); ++i)
{
Node *n = _nodes.at(i);
if(n->isPhantomNode())
continue;
added = true;
if(first)
{
first = false;
@@ -562,15 +590,20 @@ QString Graph::toAlternative() const
+ QVariant(n->pos().x()).toString()
+ ", " + QVariant(n->pos().y()).toString() + ") )";
}
if(!added)
result += "\n |";
// Add the edges
added = false;
first = true;
for(size_t i = 0; i < _edges.size(); ++i)
{
Edge *e = _edges.at(i);
if(e->isPhantomEdge())
continue;
added = true;
if(first)
{
first = false;
@@ -582,6 +615,8 @@ QString Graph::toAlternative() const
result += "(" + e->id() + ", " + e->from()->id() + ", " + e->to()->id()
+ ", " + e->label().toString() + ")";
}
if(!added)
result += "\n |";
result += "\n";
View
@@ -39,6 +39,7 @@ class Graph : public GPFile
std::vector<Edge *> edges(const QString &id = QString()) const;
std::vector<Edge *> edgesFrom(const QString &id) const;
std::vector<Edge *> edgesTo(const QString &id) const;
QStringList variables() const;
bool contains(const QString &id) const;
bool containsNode(const QString &id) const;
@@ -97,6 +97,8 @@ void GraphScene::setGraph(Graph *newGraph)
// isn't then this one is invalid
if(!_linkedGraph->containsNode(n->id()))
nodeItem->setItemState(GraphItem::GraphItem_Invalid);
else if(n->isPhantomNode())
nodeItem->setItemState(GraphItem::GraphItem_Deleted);
}
}
@@ -183,6 +185,8 @@ void GraphScene::setGraph(Graph *newGraph)
// isn't then this one is invalid
if(!_linkedGraph->containsEdge(e->id()))
edgeItem->setItemState(GraphItem::GraphItem_Invalid);
else if(e->isPhantomEdge())
edgeItem->setItemState(GraphItem::GraphItem_Deleted);
}
}
}
View
@@ -4,6 +4,7 @@
#include "list.hpp"
#include <QRegExp>
#include <QStringList>
namespace Developer {
@@ -276,4 +277,19 @@ label_t List::toLabel() const
return label;
}
QStringList List::variables() const
{
QStringList result;
for(List::const_iterator iter = begin(); iter != end(); ++iter)
{
ListValue value = *iter;
if(value.type() == GP_Variable)
result << value.variable();
}
return result;
}
}
View
@@ -68,6 +68,7 @@ class List : public QVector<ListValue>
QString toString() const;
label_t toLabel() const;
QStringList variables() const;
};
}
@@ -390,17 +390,14 @@ void MainWindow::openProject(QString path)
return;
}
setProject(newProject);
if(_activeProject != 0)
{
// As above ^ (see \todo)
delete _activeProject;
}
_activeProject = newProject;
connect(_activeProject, SIGNAL(currentFileChanged(GPFile*)),
this, SLOT(currentFileChanged(GPFile*)));
setProject(newProject);
addRecentProject(_activeProject->absolutePath());
setProjectActive(true);
}
Oops, something went wrong.

0 comments on commit 242bbc1

Please sign in to comment.