diff options
author | Aleks Kissinger <aleks0@gmail.com> | 2018-01-04 16:00:52 +0100 |
---|---|---|
committer | Aleks Kissinger <aleks0@gmail.com> | 2018-01-04 16:00:52 +0100 |
commit | 738ecbd5fad2b46836bfd6a94aeebf165ae2bbca (patch) | |
tree | df04709807cc9ec8481a3ebc7d80ac25e5b2f457 /src/data/tikzdocument.cpp | |
parent | 0421a96749743868554d44585050b1b3d04864d2 (diff) |
relocated source code to the root
Diffstat (limited to 'src/data/tikzdocument.cpp')
-rw-r--r-- | src/data/tikzdocument.cpp | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/src/data/tikzdocument.cpp b/src/data/tikzdocument.cpp new file mode 100644 index 0000000..13d4c6e --- /dev/null +++ b/src/data/tikzdocument.cpp @@ -0,0 +1,82 @@ +#include <QFile> +#include <QFileInfo> +#include <QSettings> +#include <QTextStream> +#include <QMessageBox> + +#include "tikzdocument.h" +#include "tikzgraphassembler.h" + +TikzDocument::TikzDocument(QObject *parent) : QObject(parent) +{ + _graph = new Graph(this); + _parseSuccess = true; + _fileName = ""; + _shortName = ""; + _undoStack = new QUndoStack(); +} + +TikzDocument::~TikzDocument() +{ + delete _graph; + delete _undoStack; +} + +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; +} |