From 5816cd5d5e3edf7ee7a7273c7c3a3d907dc54a4a Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Tue, 5 Dec 2017 17:55:04 +0000 Subject: Qt --- tikzit/src/data/tikzdocument.cpp | 75 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 tikzit/src/data/tikzdocument.cpp (limited to 'tikzit/src/data/tikzdocument.cpp') diff --git a/tikzit/src/data/tikzdocument.cpp b/tikzit/src/data/tikzdocument.cpp new file mode 100644 index 0000000..c8d4ce9 --- /dev/null +++ b/tikzit/src/data/tikzdocument.cpp @@ -0,0 +1,75 @@ +#include +#include +#include +#include +#include + +#include "tikzdocument.h" +#include "tikzgraphassembler.h" + +TikzDocument::TikzDocument(QObject *parent) : QObject(parent) +{ + _graph = new Graph(this); + _parseSuccess = true; + _fileName = ""; + _shortName = ""; +} + +QUndoStack *TikzDocument::undoStack() const +{ + return _undoStack; +} + +Graph *TikzDocument::graph() const +{ + return _graph; +} + +QString TikzDocument::tikz() const +{ + return _tikz; +} + +void TikzDocument::open(QString fileName) +{ + _fileName = fileName; + QFile file(fileName); + QFileInfo fi(file); + _shortName = fi.fileName(); + QSettings settings("tikzit", "tikzit"); + settings.setValue("previous-file-path", fi.absolutePath()); + + if (!file.open(QIODevice::ReadOnly)) { +// QMessageBox::critical(this, tr("Error"), +// tr("Could not open file")); + _parseSuccess = false; + return; + } + + QTextStream in(&file); + _tikz = in.readAll(); + file.close(); + + Graph *newGraph = new Graph(this); + TikzGraphAssembler ass(newGraph); + if (ass.parse(_tikz)) { + delete _graph; + _graph = newGraph; + foreach (Node *n, _graph->nodes()) n->attachStyle(); + foreach (Edge *e, _graph->edges()) e->updateControls(); + _parseSuccess = true; + } else { + delete newGraph; + _parseSuccess = false; + } +} + +QString TikzDocument::shortName() const +{ + return _shortName; +} + +bool TikzDocument::parseSuccess() const +{ + return _parseSuccess; +} -- cgit v1.2.3