diff options
-rw-r--r-- | tikzit/src/data/graph.h | 2 | ||||
-rw-r--r-- | tikzit/src/data/tikzdocument.h | 3 | ||||
-rw-r--r-- | tikzit/src/gui/mainwindow.cpp | 4 | ||||
-rw-r--r-- | tikzit/src/gui/tikzscene.cpp | 27 | ||||
-rw-r--r-- | tikzit/src/gui/tikzscene.h | 11 | ||||
-rw-r--r-- | tikzit/src/gui/tikzview.h | 2 |
6 files changed, 29 insertions, 20 deletions
diff --git a/tikzit/src/data/graph.h b/tikzit/src/data/graph.h index 952b8b4..3f4e8d3 100644 --- a/tikzit/src/data/graph.h +++ b/tikzit/src/data/graph.h @@ -1,5 +1,5 @@ /** - * A tikz graph. This serves as the model in the MVC (Graph, TikzView, TikzScene). + * A graph defined by tikz code. */ #ifndef GRAPH_H diff --git a/tikzit/src/data/tikzdocument.h b/tikzit/src/data/tikzdocument.h index 7d81742..8bd4143 100644 --- a/tikzit/src/data/tikzdocument.h +++ b/tikzit/src/data/tikzdocument.h @@ -1,5 +1,6 @@ /** - * Contains a tikz Graph, source code, file info, and undo stack. + * This class contains a tikz Graph, source code, file info, and undo stack. It serves as the model + * in the MVC triple (TikzDocument, TikzView, TikzScene). */ #ifndef TIKZDOCUMENT_H diff --git a/tikzit/src/gui/mainwindow.cpp b/tikzit/src/gui/mainwindow.cpp index 980a312..0520af2 100644 --- a/tikzit/src/gui/mainwindow.cpp +++ b/tikzit/src/gui/mainwindow.cpp @@ -22,7 +22,7 @@ MainWindow::MainWindow(QWidget *parent) : ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose, true); _tikzDocument = new TikzDocument(this); - _tikzScene = new TikzScene(_tikzDocument->graph(), this); + _tikzScene = new TikzScene(_tikzDocument, this); ui->tikzView->setScene(_tikzScene); _fileName = ""; _pristine = true; @@ -49,7 +49,7 @@ void MainWindow::open(QString fileName) if (_tikzDocument->parseSuccess()) { statusBar()->showMessage("TiKZ parsed successfully", 2000); setWindowTitle("TiKZiT - " + _tikzDocument->shortName()); - _tikzScene->setGraph(_tikzDocument->graph()); + _tikzScene->setTikzDocument(_tikzDocument); } else { statusBar()->showMessage("Cannot read TiKZ source"); } diff --git a/tikzit/src/gui/tikzscene.cpp b/tikzit/src/gui/tikzscene.cpp index 5722d0d..d01ab90 100644 --- a/tikzit/src/gui/tikzscene.cpp +++ b/tikzit/src/gui/tikzscene.cpp @@ -6,8 +6,8 @@ #include <QDebug> -TikzScene::TikzScene(Graph *graph, QObject *parent) : - QGraphicsScene(parent), _graph(graph) +TikzScene::TikzScene(TikzDocument *tikzDocument, QObject *parent) : + QGraphicsScene(parent), _tikzDocument(tikzDocument) { } @@ -16,13 +16,7 @@ TikzScene::~TikzScene() { Graph *TikzScene::graph() const { - return _graph; -} - -void TikzScene::setGraph(Graph *graph) -{ - _graph = graph; - graphReplaced(); + return _tikzDocument->graph(); } void TikzScene::graphReplaced() @@ -39,13 +33,13 @@ void TikzScene::graphReplaced() } _edgeItems.clear(); - foreach (Edge *e, _graph->edges()) { + foreach (Edge *e, graph()->edges()) { EdgeItem *ei = new EdgeItem(e); _edgeItems << ei; addItem(ei); } - foreach (Node *n, _graph->nodes()) { + foreach (Node *n, graph()->nodes()) { NodeItem *ni = new NodeItem(n); _nodeItems << ni; addItem(ni); @@ -134,6 +128,17 @@ void TikzScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) } } +TikzDocument *TikzScene::tikzDocument() const +{ + return _tikzDocument; +} + +void TikzScene::setTikzDocument(TikzDocument *tikzDocument) +{ + _tikzDocument = tikzDocument; + graphReplaced(); +} + QVector<EdgeItem *> TikzScene::edgeItems() const { return _edgeItems; diff --git a/tikzit/src/gui/tikzscene.h b/tikzit/src/gui/tikzscene.h index b12c749..9d598ad 100644 --- a/tikzit/src/gui/tikzscene.h +++ b/tikzit/src/gui/tikzscene.h @@ -1,6 +1,6 @@ /** * Manage the scene, which contains a single Graph, and respond to user input. This serves as - * the controller for the MVC (Graph, TikzView, TikzScene). + * the controller for the MVC (TikzDocument, TikzView, TikzScene). */ #ifndef TIKZSCENE_H @@ -9,6 +9,7 @@ #include "graph.h" #include "nodeitem.h" #include "edgeitem.h" +#include "tikzdocument.h" #include <QWidget> #include <QGraphicsScene> @@ -22,14 +23,16 @@ class TikzScene : public QGraphicsScene { Q_OBJECT public: - TikzScene(Graph *graph, QObject *parent); + TikzScene(TikzDocument *tikzDocument, QObject *parent); ~TikzScene(); Graph *graph() const; - void setGraph(Graph *graph); QVector<NodeItem *> nodeItems() const; QVector<EdgeItem *> edgeItems() const; + TikzDocument *tikzDocument() const; + void setTikzDocument(TikzDocument *tikzDocument); + public slots: void graphReplaced(); protected: @@ -37,7 +40,7 @@ protected: void mouseMoveEvent(QGraphicsSceneMouseEvent *event); void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); private: - Graph *_graph; + TikzDocument *_tikzDocument; QVector<NodeItem*> _nodeItems; QVector<EdgeItem*> _edgeItems; QMap<Node*,QPointF> _oldNodePositions; diff --git a/tikzit/src/gui/tikzview.h b/tikzit/src/gui/tikzview.h index 6d09b21..fc3cba4 100644 --- a/tikzit/src/gui/tikzview.h +++ b/tikzit/src/gui/tikzview.h @@ -1,6 +1,6 @@ /** * Display a Graph, and manage any user input that purely changes the view (e.g. Zoom). This - * serves as the view in the MVC (Graph, TikzView, TikzScene). + * serves as the view in the MVC (TikzDocument, TikzView, TikzScene). */ #ifndef TIKZVIEW_H |