Permalink
Browse files

Initial (incomplete) save support for rules

Switching between rules now works correctly - there was a bug in linked
graphs not being cleared properly
FirstRunDialog has some cross/tick icons as well as integer counts to
show when the next page is available
NodeItem indicates invalid state with an icon
  • Loading branch information...
aelliott committed Apr 18, 2013
1 parent 5656243 commit f17b8c139b18d6c805530b2b96e7aa7cc4e89f98
View
@@ -41,21 +41,16 @@ void Edit::setProject(Project *project)
return;
}
// Handle this!
_project = project;
//_ui->ruleEdit->setRule();
if(_project->rules().count() > 0)
_ui->ruleEdit->setRule(_project->rules().at(0));
if(_project->programs().count() > 0)
{
_ui->programEdit->setEnabled(true);
if(_project->rules().count() > 0)
_ui->ruleEdit->setRule(_project->rules().at(0));
if(_project->programs().count() > 0)
_ui->programEdit->setProgram(_project->programs().at(0));
if(_project->graphs().count() > 0)
if(_project->graphs().count() > 0)
_ui->graphEdit->setGraph(_project->graphs().at(0));
}
else
_ui->programEdit->setEnabled(false);
connect(_project, SIGNAL(fileListChanged()), this, SLOT(fileListChanged()));
connect(_project, SIGNAL(fileStatusChanged(QString,int)),
this, SLOT(fileStatusChanged(QString,int))
@@ -7,6 +7,7 @@
#include <QFile>
#include "graphview/graphwidget.hpp"
#include "graphview/graphscene.hpp"
#include "graph.hpp"
namespace Developer
@@ -69,6 +70,10 @@ void FirstRunDialog::setPage(int page)
_rhsGraph = new Graph(":/templates/example_graph_rhs.gpg");
_ui->graphWidget->setGraph(_rhsGraph);
_ui->graphWidget->setLinkedGraph(_initialGraph);
// Cheat a bit and set it as read-writable to enable editing, really
// we still can't save it but that's ok because we don't offer them
// that option anyway
_ui->graphWidget->graphScene()->setReadOnly(false);
}
_ui->backButton->setEnabled(true);
_ui->nextButton->setVisible(false);
@@ -150,6 +155,9 @@ void FirstRunDialog::nodeAdded()
if(_nodeCount > 2)
{
_addingNodesLock = true;
_ui->nodeCountIndicator->setPixmap(
QPixmap(":/icons/small_tick.png")
);
_ui->nextButton->setEnabled(true);
}
}
@@ -161,6 +169,10 @@ void FirstRunDialog::nodeRemoved()
{
++_nodeCount;
_ui->nodeDeleteCount->setText(QVariant(_nodeCount).toString());
if(_nodeCount > 2)
_ui->nodeDeleteCountIndicator->setPixmap(
QPixmap(":/icons/small_tick.png")
);
if(_nodeCount > 2 && _edgeCount > 2)
{
_deletingElementsLock = true;
@@ -179,6 +191,9 @@ void FirstRunDialog::edgeAdded()
if(_edgeCount > 2)
{
_addingEdgesLock = true;
_ui->edgeCountIndicator->setPixmap(
QPixmap(":/icons/small_tick.png")
);
_ui->nextButton->setEnabled(true);
}
}
@@ -190,6 +205,10 @@ void FirstRunDialog::edgeRemoved()
{
++_edgeCount;
_ui->edgeDeleteCount->setText(QVariant(_edgeCount).toString());
if(_edgeCount > 2)
_ui->edgeDeleteCountIndicator->setPixmap(
QPixmap(":/icons/small_tick.png")
);
if(_nodeCount > 2 && _edgeCount > 2)
{
_deletingElementsLock = true;
@@ -89,7 +89,7 @@
</item>
<item>
<widget class="QStackedWidget" name="stackedWidget">
<widget class="QWidget" name="introduction" native="true">
<widget class="QWidget" name="introduction">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
@@ -150,6 +150,16 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="nodeCountIndicator">
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="icons.qrc">:/icons/small_cross.png</pixmap>
</property>
</widget>
</item>
</layout>
</item>
<item>
@@ -160,18 +170,12 @@
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>125</height>
<height>124</height>
</size>
</property>
</spacer>
</item>
</layout>
<zorder>label_4</zorder>
<zorder>label_5</zorder>
<zorder>nodeCount</zorder>
<zorder>label_5</zorder>
<zorder>verticalSpacer_2</zorder>
<zorder></zorder>
</widget>
<widget class="QWidget" name="addingEdges">
<layout class="QVBoxLayout" name="verticalLayout_4">
@@ -207,6 +211,16 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="edgeCountIndicator">
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="icons.qrc">:/icons/small_cross.png</pixmap>
</property>
</widget>
</item>
</layout>
</item>
<item>
@@ -306,6 +320,16 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="nodeDeleteCountIndicator">
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="icons.qrc">:/icons/small_cross.png</pixmap>
</property>
</widget>
</item>
</layout>
</item>
<item>
@@ -324,6 +348,16 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="edgeDeleteCountIndicator">
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="icons.qrc">:/icons/small_cross.png</pixmap>
</property>
</widget>
</item>
</layout>
</item>
<item>
@@ -334,7 +368,7 @@
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>224</height>
<height>222</height>
</size>
</property>
</spacer>
@@ -457,7 +491,7 @@
</property>
<property name="sizeHint" stdset="0">
<size>
<width>282</width>
<width>272</width>
<height>20</height>
</size>
</property>
@@ -491,7 +525,11 @@
<item>
<widget class="QPushButton" name="beginButton">
<property name="text">
<string>Begin</string>
<string>End</string>
</property>
<property name="icon">
<iconset resource="icons.qrc">
<normaloff>:/icons/small_tick.png</normaloff>:/icons/small_tick.png</iconset>
</property>
</widget>
</item>
@@ -254,7 +254,25 @@ Graph *GraphScene::linkedGraph() const
void GraphScene::setLinkedGraph(Graph *linkGraph)
{
if(linkGraph == _graph)
{
qDebug() << "Attempted to set linked graph to the current graph.";
qDebug() << "This makes no sense";
}
if(_linkedGraph)
{
disconnect(_linkedGraph, SIGNAL(nodeAdded(Node*)),
this, SLOT(linkedGraphAddedNode(Node*)));
disconnect(_linkedGraph, SIGNAL(edgeAdded(Edge*)),
this, SLOT(linkedGraphAddedEdge(Edge*)));
}
_linkedGraph = linkGraph;
if(_linkedGraph == 0)
return;
connect(_linkedGraph, SIGNAL(nodeAdded(Node*)),
this, SLOT(linkedGraphAddedNode(Node*)));
connect(_linkedGraph, SIGNAL(edgeAdded(Edge*)),
@@ -274,6 +292,16 @@ void GraphScene::setLinkedGraph(Graph *linkGraph)
setGraph(_graph);
}
bool GraphScene::readOnly() const
{
return _readOnly;
}
void GraphScene::setReadOnly(bool readOnlyFlag)
{
_readOnly = readOnlyFlag;
}
void GraphScene::addNodeItem(NodeItem *nodeItem, const QPointF &position)
{
addItem(nodeItem);
@@ -535,15 +563,30 @@ void GraphScene::resizeToContents()
_graph->setCanvas(boundingRect.toRect());
}
void GraphScene::addNode(const QPointF &position)
void GraphScene::addNode(const QPointF &position, bool automatic)
{
QString label = QString("n") + QVariant(static_cast<int>(_graph->nodes().size()+1)
).toString();
Node *n = _graph->addNode(label, position);
NodeItem *nodeItem = new NodeItem(n);
if(_linkedGraph != 0)
{
if(!_linkedGraph->contains(n->id()))
{
nodeItem->setItemState(GraphItem::GraphItem_New);
}
else if(_linkedGraph->containsEdge(n->id()))
{
nodeItem->setItemState(GraphItem::GraphItem_Invalid);
}
else if(!automatic)
{
nodeItem->setItemState(GraphItem::GraphItem_Deleted);
}
}
// Offset the click position by half of the item's width and height to
// center it on the mouse press
QRectF boundingRect = nodeItem->boundingRect();
@@ -975,8 +1018,20 @@ void GraphScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
qDebug() << "Edge creation failed to find nodes.";
return;
}
Edge *edge = _graph->addEdge(from, to, newLabel);
EdgeItem *edgeItem = new EdgeItem(edge, _fromNode, node);
Edge *e = _graph->addEdge(from, to, newLabel);
EdgeItem *edgeItem = new EdgeItem(e, _fromNode, node);
if(_linkedGraph != 0)
{
if(!_linkedGraph->contains(e->id()))
{
edgeItem->setItemState(GraphItem::GraphItem_New);
}
else if(_linkedGraph->containsNode(e->id()))
{
edgeItem->setItemState(GraphItem::GraphItem_Invalid);
}
}
addEdgeItem(edgeItem);
return;
}
@@ -27,6 +27,8 @@ class GraphScene : public QGraphicsScene
void setGraph(Graph *newGraph);
Graph *linkedGraph() const;
void setLinkedGraph(Graph *linkGraph);
bool readOnly() const;
void setReadOnly(bool readOnlyFlag);
NodeItem *node(const QString &id) const;
EdgeItem *edge(const QString &id) const;
@@ -51,7 +53,7 @@ class GraphScene : public QGraphicsScene
void resizeToContents();
public slots:
void addNode(const QPointF &position);
void addNode(const QPointF &position, bool automatic = false);
void addNode(qreal x, qreal y);
void removeEdge(EdgeItem *edge);
@@ -35,6 +35,11 @@ Graph *GraphWidget::graph() const
return _scene->graph();
}
GraphScene *GraphWidget::graphScene() const
{
return _scene;
}
void GraphWidget::setGraph(Graph *newGraph)
{
_scene->setGraph(newGraph);
@@ -110,6 +115,16 @@ void GraphWidget::layoutGEM()
_scene->layoutGEM();
}
void GraphWidget::mouseMoveEvent(QMouseEvent *event)
{
if(event->modifiers() & Qt::SHIFT)
setDragMode(QGraphicsView::ScrollHandDrag);
else
setDragMode(QGraphicsView::NoDrag);
QGraphicsView::mouseMoveEvent(event);
}
void GraphWidget::keyPressEvent(QKeyEvent *event)
{
if(event->modifiers() & Qt::SHIFT)
@@ -27,6 +27,7 @@ class GraphWidget : public QGraphicsView
explicit GraphWidget(QWidget *parent = 0);
Graph *graph() const;
GraphScene *graphScene() const;
void setGraph(Graph *newGraph);
void setLinkedGraph(Graph *linkGraph);
@@ -45,6 +46,7 @@ class GraphWidget : public QGraphicsView
void layoutGEM();
protected:
void mouseMoveEvent(QMouseEvent *event);
void keyPressEvent(QKeyEvent *event);
void keyReleaseEvent(QKeyEvent *event);
void wheelEvent(QWheelEvent *event);
@@ -270,6 +270,19 @@ void NodeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QRectF pathRect = path.boundingRect();
painter->drawPath(path);
if(itemState() == GraphItem_Invalid)
{
QRectF destRect(pathRect.width()-16, pathRect.height()-16, 16, 16);
QRectF sourceRect(0, 0, 16, 16);
painter->drawPixmap(
destRect,
QPixmap(":/icons/small_exclamation.png"),
sourceRect
);
setToolTip(tr("Node shares an ID with an edge in the LHS graph, this "
"is not permitted."));
}
painter->setPen(textColour);
painter->setFont(font);
painter->drawText(QRectF(leftPadding+borderWidth, topPadding+borderWidth,
Oops, something went wrong.

0 comments on commit f17b8c1

Please sign in to comment.