summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleks Kissinger <aleks0@gmail.com>2018-01-26 22:34:15 +0900
committerAleks Kissinger <aleks0@gmail.com>2018-01-26 22:34:15 +0900
commit768e097abd17d07dd2748894b4dc1b09471dd6da (patch)
treec0b5a8774293d21ddace2c8afee8152bdd3a386c
parentd163561b49accb90dd9eb9028d9aa7c05266a539 (diff)
started implementing project loader
-rw-r--r--src/data/project.cpp13
-rw-r--r--src/data/project.h21
-rw-r--r--src/data/tikzassembler.cpp54
-rw-r--r--src/data/tikzassembler.h42
-rw-r--r--src/data/tikzdocument.cpp4
-rw-r--r--src/data/tikzgraphassembler.cpp33
-rw-r--r--src/data/tikzgraphassembler.h31
-rw-r--r--src/data/tikzlexer.l3
-rw-r--r--src/data/tikzparser.y15
-rw-r--r--src/data/tikzparserdefs.h2
-rw-r--r--src/gui/mainwindow.cpp2
-rw-r--r--src/gui/propertypalette.ui3
-rw-r--r--src/test/testparser.cpp14
-rw-r--r--src/test/testtikzoutput.cpp4
-rw-r--r--src/tikzit.cpp2
-rw-r--r--src/tikzit.h2
-rw-r--r--stylepalette.cpp7
-rw-r--r--stylepalette.h3
-rw-r--r--stylepalette.ui96
-rw-r--r--tikzit.pro16
-rw-r--r--tikzlexer.h4
21 files changed, 276 insertions, 95 deletions
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 <QObject>
+#include <QString>
+
+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 <QObject>
+#include <QHash>
+
+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<QString,Node*> _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 <QMessageBox>
#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 <QObject>
-#include <QHash>
-
-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<QString,Node*> _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 <QString>
#include <QRectF>
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 @@
<height>341</height>
</rect>
</property>
+ <property name="floating">
+ <bool>false</bool>
+ </property>
<property name="windowTitle">
<string>Properties</string>
</property>
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 <QTest>
#include <QVector>
@@ -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 <QTest>
#include <QRectF>
@@ -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 <QObject>
@@ -83,6 +84,7 @@ private:
MainMenu *_mainMenu;
ToolPalette *_toolPalette;
PropertyPalette *_propertyPalette;
+ StylePalette *_stylePalette;
QVector<MainWindow*> _windows;
MainWindow *_activeWindow;
QVector<NodeStyle*> _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 <QDebug>
+
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 @@
-<?xml version='1.0'?>
+<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>StylePalette</class>
- <widget name="StylePalette" class="QDockWidget">
+ <widget class="QDockWidget" name="StylePalette">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
- <width>400</width>
- <height>300</height>
+ <width>250</width>
+ <height>350</height>
</rect>
</property>
+ <property name="minimumSize">
+ <size>
+ <width>250</width>
+ <height>350</height>
+ </size>
+ </property>
<property name="windowTitle">
- <string>DockWidget</string>
+ <string>Styles</string>
</property>
- <widget name="dockWidgetContents" class="QWidget"/>
+ <widget class="QWidget" name="dockWidgetContents">
+ <widget class="QLabel" name="label">
+ <property name="geometry">
+ <rect>
+ <x>10</x>
+ <y>12</y>
+ <width>51</width>
+ <height>16</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Project:</string>
+ </property>
+ </widget>
+ <widget class="QLabel" name="label_2">
+ <property name="geometry">
+ <rect>
+ <x>60</x>
+ <y>13</y>
+ <width>131</width>
+ <height>16</height>
+ </rect>
+ </property>
+ <property name="font">
+ <font>
+ <family>Courier</family>
+ <weight>75</weight>
+ <bold>true</bold>
+ </font>
+ </property>
+ <property name="text">
+ <string>[default]</string>
+ </property>
+ </widget>
+ <widget class="QToolButton" name="newProjectButton">
+ <property name="geometry">
+ <rect>
+ <x>195</x>
+ <y>10</y>
+ <width>22</width>
+ <height>22</height>
+ </rect>
+ </property>
+ <property name="toolTip">
+ <string>New Project</string>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ <property name="icon">
+ <iconset resource="tikzit.qrc">
+ <normaloff>:/images/document-new.png</normaloff>:/images/document-new.png</iconset>
+ </property>
+ </widget>
+ <widget class="QToolButton" name="openProjectButton">
+ <property name="geometry">
+ <rect>
+ <x>220</x>
+ <y>10</y>
+ <width>22</width>
+ <height>22</height>
+ </rect>
+ </property>
+ <property name="toolTip">
+ <string>New Project</string>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ <property name="icon">
+ <iconset resource="tikzit.qrc">
+ <normaloff>:/images/document-open.png</normaloff>:/images/document-open.png</iconset>
+ </property>
+ </widget>
+ </widget>
</widget>
+ <resources>
+ <include location="tikzit.qrc"/>
+ </resources>
+ <connections/>
</ui>
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 <unistd.h>
#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