From 768e097abd17d07dd2748894b4dc1b09471dd6da Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Fri, 26 Jan 2018 22:34:15 +0900 Subject: started implementing project loader --- src/data/project.cpp | 13 ++++++ src/data/project.h | 21 +++++++++ src/data/tikzassembler.cpp | 54 +++++++++++++++++++++++ src/data/tikzassembler.h | 42 ++++++++++++++++++ src/data/tikzdocument.cpp | 4 +- src/data/tikzgraphassembler.cpp | 33 -------------- src/data/tikzgraphassembler.h | 31 ------------- src/data/tikzlexer.l | 3 +- src/data/tikzparser.y | 15 ++++++- src/data/tikzparserdefs.h | 2 +- src/gui/mainwindow.cpp | 2 +- src/gui/propertypalette.ui | 3 ++ src/test/testparser.cpp | 14 +++--- src/test/testtikzoutput.cpp | 4 +- src/tikzit.cpp | 2 + src/tikzit.h | 2 + stylepalette.cpp | 7 +++ stylepalette.h | 3 ++ stylepalette.ui | 96 ++++++++++++++++++++++++++++++++++++++--- tikzit.pro | 16 ++++--- tikzlexer.h | 4 +- 21 files changed, 276 insertions(+), 95 deletions(-) create mode 100644 src/data/project.cpp create mode 100644 src/data/project.h create mode 100644 src/data/tikzassembler.cpp create mode 100644 src/data/tikzassembler.h delete mode 100644 src/data/tikzgraphassembler.cpp delete mode 100644 src/data/tikzgraphassembler.h diff --git a/src/data/project.cpp b/src/data/project.cpp new file mode 100644 index 0000000..b129dc0 --- /dev/null +++ b/src/data/project.cpp @@ -0,0 +1,13 @@ +#include "project.h" + +#include "QDebug" + +Project::Project(QObject *parent) : QObject(parent) +{ + +} + +void Project::addStyle(QString name, GraphElementData *properties) +{ + qDebug() << "got style {" << name << "} = [" << properties << "]"; +} diff --git a/src/data/project.h b/src/data/project.h new file mode 100644 index 0000000..cbc2cb9 --- /dev/null +++ b/src/data/project.h @@ -0,0 +1,21 @@ +#ifndef PROJECT_H +#define PROJECT_H + +#include "graphelementdata.h" + +#include +#include + +class Project : public QObject +{ + Q_OBJECT +public: + explicit Project(QObject *parent = 0); + void addStyle(QString name, GraphElementData *properties); + +signals: + +public slots: +}; + +#endif // PROJECT_H diff --git a/src/data/tikzassembler.cpp b/src/data/tikzassembler.cpp new file mode 100644 index 0000000..456464a --- /dev/null +++ b/src/data/tikzassembler.cpp @@ -0,0 +1,54 @@ +#include "tikzassembler.h" + +#include "tikzparserdefs.h" +#include "tikzparser.parser.hpp" +#include "tikzlexer.h" + +int yyparse(void *scanner); + +TikzAssembler::TikzAssembler(Graph *graph, QObject *parent) : + QObject(parent), _graph(graph), _project(0) +{ + yylex_init(&scanner); + yyset_extra(this, scanner); +} + +TikzAssembler::TikzAssembler(Project *project, QObject *parent) : + QObject(parent), _graph(0), _project(project) +{ + yylex_init(&scanner); + yyset_extra(this, scanner); +} + +void TikzAssembler::addNodeToMap(Node *n) { _nodeMap.insert(n->name(), n); } +Node *TikzAssembler::nodeWithName(QString name) { return _nodeMap[name]; } + +bool TikzAssembler::parse(const QString &tikz) +{ + yy_scan_string(tikz.toLatin1().data(), scanner); + int result = yyparse(scanner); + + if (result == 0) return true; + else return false; +} + +Graph *TikzAssembler::graph() const +{ + return _graph; +} + +Project *TikzAssembler::project() const +{ + return _project; +} + +bool TikzAssembler::isGraph() const +{ + return _graph != 0; +} + +bool TikzAssembler::isProject() const +{ + return _project != 0; +} + diff --git a/src/data/tikzassembler.h b/src/data/tikzassembler.h new file mode 100644 index 0000000..8dbbc9b --- /dev/null +++ b/src/data/tikzassembler.h @@ -0,0 +1,42 @@ +/** + * Convenience class to hold the parser state while loading tikz graphs or projects. + */ + +#ifndef TIKZASSEMBLER_H +#define TIKZASSEMBLER_H + +#include "node.h" +#include "graph.h" +#include "project.h" + +#include +#include + +class TikzAssembler : public QObject +{ + Q_OBJECT +public: + explicit TikzAssembler(Graph *graph, QObject *parent = 0); + explicit TikzAssembler(Project *project, QObject *parent = 0); + void addNodeToMap(Node *n); + Node *nodeWithName(QString name); + bool parse(const QString &tikz); + + Graph *graph() const; + Project *project() const; + bool isGraph() const; + bool isProject() const; + + +signals: + +public slots: + +private: + QHash _nodeMap; + Graph *_graph; + Project *_project; + void *scanner; +}; + +#endif // TIKZASSEMBLER_H diff --git a/src/data/tikzdocument.cpp b/src/data/tikzdocument.cpp index 13d4c6e..a3fa961 100644 --- a/src/data/tikzdocument.cpp +++ b/src/data/tikzdocument.cpp @@ -5,7 +5,7 @@ #include #include "tikzdocument.h" -#include "tikzgraphassembler.h" +#include "tikzassembler.h" TikzDocument::TikzDocument(QObject *parent) : QObject(parent) { @@ -58,7 +58,7 @@ void TikzDocument::open(QString fileName) file.close(); Graph *newGraph = new Graph(this); - TikzGraphAssembler ass(newGraph); + TikzAssembler ass(newGraph); if (ass.parse(_tikz)) { delete _graph; _graph = newGraph; diff --git a/src/data/tikzgraphassembler.cpp b/src/data/tikzgraphassembler.cpp deleted file mode 100644 index c05a5c8..0000000 --- a/src/data/tikzgraphassembler.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include "tikzgraphassembler.h" - -#include "tikzparserdefs.h" -#include "tikzparser.parser.hpp" -#include "tikzlexer.h" - -int yyparse(void *scanner); - - -TikzGraphAssembler::TikzGraphAssembler(Graph *graph, QObject *parent) : - QObject(parent), _graph(graph) -{ - yylex_init(&scanner); - yyset_extra(this, scanner); -} - -void TikzGraphAssembler::addNodeToMap(Node *n) { _nodeMap.insert(n->name(), n); } -Node *TikzGraphAssembler::nodeWithName(QString name) { return _nodeMap[name]; } - -bool TikzGraphAssembler::parse(const QString &tikz) -{ - yy_scan_string(tikz.toLatin1().data(), scanner); - int result = yyparse(scanner); - - if (result == 0) return true; - else return false; -} - -Graph *TikzGraphAssembler::graph() const -{ - return _graph; -} - diff --git a/src/data/tikzgraphassembler.h b/src/data/tikzgraphassembler.h deleted file mode 100644 index 79b89b0..0000000 --- a/src/data/tikzgraphassembler.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef TIKZGRAPHASSEMBLER_H -#define TIKZGRAPHASSEMBLER_H - -#include "node.h" -#include "graph.h" - -#include -#include - -class TikzGraphAssembler : public QObject -{ - Q_OBJECT -public: - explicit TikzGraphAssembler(Graph *graph, QObject *parent = 0); - void addNodeToMap(Node *n); - Node *nodeWithName(QString name); - bool parse(const QString &tikz); - - Graph *graph() const; - -signals: - -public slots: - -private: - QHash _nodeMap; - Graph *_graph; - void *scanner; -}; - -#endif // TIKZGRAPHASSEMBLER_H diff --git a/src/data/tikzlexer.l b/src/data/tikzlexer.l index 800ef8e..faf0d43 100644 --- a/src/data/tikzlexer.l +++ b/src/data/tikzlexer.l @@ -38,11 +38,12 @@ %} %option reentrant bison-bridge bison-locations 8bit +%option bison-locations 8bit %option nounput %option yylineno %option noyywrap %option header-file="tikzlexer.h" -%option extra-type="TikzGraphAssembler *" +%option extra-type="TikzAssembler *" %s props %s xcoord diff --git a/src/data/tikzparser.y b/src/data/tikzparser.y index aa6ac76..a4db3dd 100644 --- a/src/data/tikzparser.y +++ b/src/data/tikzparser.y @@ -62,7 +62,7 @@ #include "graphelementproperty.h" #include "tikzlexer.h" -#import "tikzgraphassembler.h" +#import "tikzassembler.h" /* the assembler (used by this parser) is stored in the lexer state as "extra" data */ #define assembler yyget_extra(scanner) @@ -127,9 +127,20 @@ void yyerror(YYLTYPE *yylloc, void *scanner, const char *str) { %% + +tikz: tikzstyles | tikzpicture; + +tikzstyles: tikzstyles tikzstyle | ; +tikzstyle: "\\tikzstyle" DELIMITEDSTRING "=" "[" properties "]" + { + if (assembler->isProject()) { + assembler->project()->addStyle(QString($2), $5); + } + } + tikzpicture: "\\begin{tikzpicture}" optproperties tikzcmds "\\end{tikzpicture}" { - if ($2) { + if (assembler->isGraph() && $2) { assembler->graph()->setData($2); } }; diff --git a/src/data/tikzparserdefs.h b/src/data/tikzparserdefs.h index 9d4bfe8..b51a8c9 100644 --- a/src/data/tikzparserdefs.h +++ b/src/data/tikzparserdefs.h @@ -4,7 +4,7 @@ #include "graphelementproperty.h" #include "graphelementdata.h" #include "node.h" -#include "tikzgraphassembler.h" +#include "tikzassembler.h" #include #include diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 19b6a59..54474ae 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -1,6 +1,6 @@ #include "mainwindow.h" #include "ui_mainwindow.h" -#include "tikzgraphassembler.h" +#include "tikzassembler.h" #include "toolpalette.h" #include "tikzit.h" diff --git a/src/gui/propertypalette.ui b/src/gui/propertypalette.ui index 83d586e..a8ba5d2 100644 --- a/src/gui/propertypalette.ui +++ b/src/gui/propertypalette.ui @@ -10,6 +10,9 @@ 341 + + false + Properties diff --git a/src/test/testparser.cpp b/src/test/testparser.cpp index e220e2e..284930e 100644 --- a/src/test/testparser.cpp +++ b/src/test/testparser.cpp @@ -1,6 +1,6 @@ #include "testparser.h" #include "graph.h" -#include "tikzgraphassembler.h" +#include "tikzassembler.h" #include #include @@ -18,7 +18,7 @@ void TestParser::parseEmptyGraph() { Graph *g = new Graph(); - TikzGraphAssembler ga(g); + TikzAssembler ga(g); bool res = ga.parse("\\begin{tikzpicture}\n\\end{tikzpicture}"); QVERIFY(res); QVERIFY(g->nodes().size() == 0); @@ -29,7 +29,7 @@ void TestParser::parseEmptyGraph() void TestParser::parseNodeGraph() { Graph *g = new Graph(); - TikzGraphAssembler ga(g); + TikzAssembler ga(g); bool res = ga.parse( "\\begin{tikzpicture}\n" " \\node (node0) at (1.1, -2.2) {};\n" @@ -50,7 +50,7 @@ void TestParser::parseNodeGraph() void TestParser::parseEdgeGraph() { Graph *g = new Graph(); - TikzGraphAssembler ga(g); + TikzAssembler ga(g); bool res = ga.parse( "\\begin{tikzpicture}\n" " \\begin{pgfonlayer}{nodelayer}\n" @@ -81,7 +81,7 @@ void TestParser::parseEdgeGraph() void TestParser::parseEdgeNode() { Graph *g = new Graph(); - TikzGraphAssembler ga(g); + TikzAssembler ga(g); bool res = ga.parse( "\\begin{tikzpicture}\n" " \\begin{pgfonlayer}{nodelayer}\n" @@ -106,7 +106,7 @@ void TestParser::parseEdgeNode() void TestParser::parseEdgeBends() { Graph *g = new Graph(); - TikzGraphAssembler ga(g); + TikzAssembler ga(g); bool res = ga.parse( "\\begin{tikzpicture}\n" " \\begin{pgfonlayer}{nodelayer}\n" @@ -136,7 +136,7 @@ void TestParser::parseEdgeBends() void TestParser::parseBbox() { Graph *g = new Graph(); - TikzGraphAssembler ga(g); + TikzAssembler ga(g); bool res = ga.parse( "\\begin{tikzpicture}\n" " \\path [use as bounding box] (-1.5,-1.5) rectangle (1.5,1.5);\n" diff --git a/src/test/testtikzoutput.cpp b/src/test/testtikzoutput.cpp index f086786..1c25439 100644 --- a/src/test/testtikzoutput.cpp +++ b/src/test/testtikzoutput.cpp @@ -2,7 +2,7 @@ #include "graphelementproperty.h" #include "graphelementdata.h" #include "graph.h" -#include "tikzgraphassembler.h" +#include "tikzassembler.h" #include #include @@ -58,7 +58,7 @@ void TestTikzOutput::graphEmpty() void TestTikzOutput::graphFromTikz() { Graph *g = new Graph(); - TikzGraphAssembler ga(g); + TikzAssembler ga(g); QString tikz = "\\begin{tikzpicture}\n" diff --git a/src/tikzit.cpp b/src/tikzit.cpp index 42d16e8..a488b8a 100644 --- a/src/tikzit.cpp +++ b/src/tikzit.cpp @@ -18,11 +18,13 @@ Tikzit::Tikzit() _toolPalette = new ToolPalette(dummy); _propertyPalette = new PropertyPalette(dummy); + _stylePalette = new StylePalette(dummy); loadStyles(); _toolPalette->show(); _propertyPalette->show(); + _stylePalette->show(); _windows << new MainWindow(); _windows[0]->show(); diff --git a/src/tikzit.h b/src/tikzit.h index dc47a27..a241a78 100644 --- a/src/tikzit.h +++ b/src/tikzit.h @@ -36,6 +36,7 @@ #include "toolpalette.h" #include "propertypalette.h" +#include "stylepalette.h" #include "nodestyle.h" #include @@ -83,6 +84,7 @@ private: MainMenu *_mainMenu; ToolPalette *_toolPalette; PropertyPalette *_propertyPalette; + StylePalette *_stylePalette; QVector _windows; MainWindow *_activeWindow; QVector _nodeStyles; diff --git a/stylepalette.cpp b/stylepalette.cpp index ba0cd0d..2781a90 100644 --- a/stylepalette.cpp +++ b/stylepalette.cpp @@ -1,6 +1,8 @@ #include "stylepalette.h" #include "ui_stylepalette.h" +#include + StylePalette::StylePalette(QWidget *parent) : QDockWidget(parent), ui(new Ui::StylePalette) @@ -12,3 +14,8 @@ StylePalette::~StylePalette() { delete ui; } + +void StylePalette::on_buttonOpenProject_clicked() +{ + qDebug() << "got click"; +} diff --git a/stylepalette.h b/stylepalette.h index 8a90d95..99afe51 100644 --- a/stylepalette.h +++ b/stylepalette.h @@ -15,6 +15,9 @@ public: explicit StylePalette(QWidget *parent = 0); ~StylePalette(); +public slots: + void on_buttonOpenProject_clicked(); + private: Ui::StylePalette *ui; }; diff --git a/stylepalette.ui b/stylepalette.ui index dd4190e..941212b 100644 --- a/stylepalette.ui +++ b/stylepalette.ui @@ -1,18 +1,102 @@ - + StylePalette - + 0 0 - 400 - 300 + 250 + 350 + + + 250 + 350 + + - DockWidget + Styles - + + + + + 10 + 12 + 51 + 16 + + + + Project: + + + + + + 60 + 13 + 131 + 16 + + + + + Courier + 75 + true + + + + [default] + + + + + + 195 + 10 + 22 + 22 + + + + New Project + + + + + + + :/images/document-new.png:/images/document-new.png + + + + + + 220 + 10 + 22 + 22 + + + + New Project + + + + + + + :/images/document-open.png:/images/document-open.png + + + + + + + diff --git a/tikzit.pro b/tikzit.pro index 2e71e73..d3a9c62 100644 --- a/tikzit.pro +++ b/tikzit.pro @@ -35,7 +35,6 @@ SOURCES += src/gui/mainwindow.cpp \ src/data/graph.cpp \ src/data/node.cpp \ src/data/edge.cpp \ - src/data/tikzgraphassembler.cpp \ src/data/graphelementdata.cpp \ src/data/graphelementproperty.cpp \ src/gui/propertypalette.cpp \ @@ -49,7 +48,9 @@ SOURCES += src/gui/mainwindow.cpp \ src/gui/undocommands.cpp \ src/gui/mainmenu.cpp \ src/util.cpp \ - stylepalette.cpp + stylepalette.cpp \ + src/data/project.cpp \ + src/data/tikzassembler.cpp HEADERS += src/gui/mainwindow.h \ src/gui/toolpalette.h \ @@ -57,7 +58,6 @@ HEADERS += src/gui/mainwindow.h \ src/data/graph.h \ src/data/node.h \ src/data/edge.h \ - src/data/tikzgraphassembler.h \ src/data/graphelementdata.h \ src/data/graphelementproperty.h \ src/gui/propertypalette.h \ @@ -72,11 +72,13 @@ HEADERS += src/gui/mainwindow.h \ src/gui/undocommands.h \ src/gui/mainmenu.h \ src/util.h \ - stylepalette.h + stylepalette.h \ + src/data/project.h \ + src/data/tikzassembler.h -FORMS += src/gui/mainwindow.ui \ - src/gui/propertypalette.ui \ - src/gui/mainmenu.ui \ +FORMS += src/gui/mainwindow.ui \ + src/gui/propertypalette.ui \ + src/gui/mainmenu.ui \ stylepalette.ui INCLUDEPATH += src src/gui src/data diff --git a/tikzlexer.h b/tikzlexer.h index 6598601..73df7b6 100644 --- a/tikzlexer.h +++ b/tikzlexer.h @@ -234,7 +234,7 @@ void yyfree (void * ,yyscan_t yyscanner ); #include #endif -#define YY_EXTRA_TYPE TikzGraphAssembler * +#define YY_EXTRA_TYPE TikzAssembler * int yylex_init (yyscan_t* scanner); @@ -338,7 +338,7 @@ extern int yylex \ #undef YY_DECL #endif -#line 174 "src/data/tikzlexer.l" +#line 188 "src/data/tikzlexer.l" #line 344 "tikzlexer.h" #undef yyIN_HEADER -- cgit v1.2.3