summaryrefslogtreecommitdiff
path: root/tikzit
diff options
context:
space:
mode:
authorAleks Kissinger <aleks0@gmail.com>2017-01-21 11:18:41 +0100
committerAleks Kissinger <aleks0@gmail.com>2017-01-21 11:18:41 +0100
commit48e69ae28bb8b40d5a2281f0ea26141220b3bf5e (patch)
treea606cd0d8d0251b6899d1ae8909b34099abc270d /tikzit
parentb70be76db70730f42250bc066a578710aa4a3038 (diff)
added testing
Diffstat (limited to 'tikzit')
-rw-r--r--tikzit/bison.pri2
-rw-r--r--tikzit/src/data/edge.cpp36
-rw-r--r--tikzit/src/data/edge.h15
-rw-r--r--tikzit/src/data/graph.cpp16
-rw-r--r--tikzit/src/data/graph.h6
-rw-r--r--tikzit/src/data/graphelementdata.cpp7
-rw-r--r--tikzit/src/data/graphelementdata.h1
-rw-r--r--tikzit/src/data/node.cpp24
-rw-r--r--tikzit/src/data/node.h14
-rw-r--r--tikzit/src/data/tikzgraphassembler.cpp9
-rw-r--r--tikzit/src/data/tikzgraphassembler.h6
-rw-r--r--tikzit/src/data/tikzlexer.l20
-rw-r--r--tikzit/src/data/tikzparser.y63
-rw-r--r--tikzit/src/data/tikzparserdefs.h16
-rw-r--r--tikzit/src/test/testtest.cpp17
-rw-r--r--tikzit/tikzit.pro12
16 files changed, 212 insertions, 52 deletions
diff --git a/tikzit/bison.pri b/tikzit/bison.pri
index 3fcfc36..b5d30da 100644
--- a/tikzit/bison.pri
+++ b/tikzit/bison.pri
@@ -7,7 +7,7 @@ bison.variable_out = GENERATED_SOURCES
silent:bison.commands = @echo Bison ${QMAKE_FILE_IN} && $$bison.commands
QMAKE_EXTRA_COMPILERS += bison
bison_header.input = BISONSOURCES
-bison_header.output = ${QMAKE_FILE_PATH}/${QMAKE_FILE_BASE}.parser.hpp
+bison_header.output = ${QMAKE_FILE_PATH}/${QMAKE_FILE_BASE}.parser.h
bison_header.commands = bison -d -o ${QMAKE_FILE_PATH}/${QMAKE_FILE_BASE}.parser.cpp ${QMAKE_FILE_IN}
bison_header.CONFIG += target_predeps no_link
silent:bison_header.commands = @echo Bison ${QMAKE_FILE_IN} && $$bison.commands
diff --git a/tikzit/src/data/edge.cpp b/tikzit/src/data/edge.cpp
index bea96b8..c8d1cfc 100644
--- a/tikzit/src/data/edge.cpp
+++ b/tikzit/src/data/edge.cpp
@@ -3,7 +3,12 @@
Edge::Edge(Node *s, Node *t, QObject *parent) :
QObject(parent), _source(s), _target(t)
{
+ _data = new GraphElementData();
+}
+Edge::~Edge()
+{
+ delete _data;
}
Node *Edge::source() const
@@ -16,4 +21,35 @@ Node *Edge::target() const
return _target;
}
+GraphElementData *Edge::data() const
+{
+ return _data;
+}
+
+void Edge::setData(GraphElementData *data)
+{
+ delete _data;
+ _data = data;
+}
+
+QString Edge::sourceAnchor() const
+{
+ return _sourceAnchor;
+}
+
+void Edge::setSourceAnchor(const QString &sourceAnchor)
+{
+ _sourceAnchor = sourceAnchor;
+}
+
+QString Edge::targetAnchor() const
+{
+ return _targetAnchor;
+}
+
+void Edge::setTargetAnchor(const QString &targetAnchor)
+{
+ _targetAnchor = targetAnchor;
+}
+
diff --git a/tikzit/src/data/edge.h b/tikzit/src/data/edge.h
index 2153f30..5884b90 100644
--- a/tikzit/src/data/edge.h
+++ b/tikzit/src/data/edge.h
@@ -1,6 +1,8 @@
#ifndef EDGE_H
#define EDGE_H
+#include "graphelementdata.h"
+
#include <QObject>
class Node;
@@ -10,10 +12,20 @@ class Edge : public QObject
Q_OBJECT
public:
explicit Edge(Node *s, Node *t, QObject *parent = 0);
+ ~Edge();
Node *source() const;
Node *target() const;
+ GraphElementData *data() const;
+ void setData(GraphElementData *data);
+
+ QString sourceAnchor() const;
+ void setSourceAnchor(const QString &sourceAnchor);
+
+ QString targetAnchor() const;
+ void setTargetAnchor(const QString &targetAnchor);
+
signals:
public slots:
@@ -21,6 +33,9 @@ public slots:
private:
Node *_source;
Node *_target;
+ GraphElementData *_data;
+ QString _sourceAnchor;
+ QString _targetAnchor;
};
#endif // EDGE_H
diff --git a/tikzit/src/data/graph.cpp b/tikzit/src/data/graph.cpp
index 0db20e1..8a995d2 100644
--- a/tikzit/src/data/graph.cpp
+++ b/tikzit/src/data/graph.cpp
@@ -2,7 +2,12 @@
Graph::Graph(QObject *parent) : QObject(parent)
{
+ _data = new GraphElementData();
+}
+Graph::~Graph()
+{
+ delete _data;
}
void Graph::removeNode(Node *n) {
@@ -21,6 +26,17 @@ void Graph::removeEdge(Edge *e)
}
+GraphElementData *Graph::data() const
+{
+ return _data;
+}
+
+void Graph::setData(GraphElementData *data)
+{
+ delete _data;
+ _data = data;
+}
+
Node *Graph::addNode() {
Node *n = new Node(this);
nodes << n;
diff --git a/tikzit/src/data/graph.h b/tikzit/src/data/graph.h
index f55b3c9..1f26486 100644
--- a/tikzit/src/data/graph.h
+++ b/tikzit/src/data/graph.h
@@ -3,6 +3,7 @@
#include "node.h"
#include "edge.h"
+#include "graphelementdata.h"
#include <QObject>
#include <QVector>
@@ -13,11 +14,15 @@ class Graph : public QObject
Q_OBJECT
public:
explicit Graph(QObject *parent = 0);
+ ~Graph();
Node *addNode();
void removeNode(Node *n);
Edge *addEdge(Node *s, Node*t);
void removeEdge(Edge *e);
+ GraphElementData *data() const;
+ void setData(GraphElementData *data);
+
signals:
public slots:
@@ -27,6 +32,7 @@ private:
QVector<Edge*> edges;
QMultiHash<Node*,Edge*> inEdges;
QMultiHash<Node*,Edge*> outEdges;
+ GraphElementData *_data;
};
#endif // GRAPH_H
diff --git a/tikzit/src/data/graphelementdata.cpp b/tikzit/src/data/graphelementdata.cpp
index 8e4a7cc..8f81e31 100644
--- a/tikzit/src/data/graphelementdata.cpp
+++ b/tikzit/src/data/graphelementdata.cpp
@@ -32,11 +32,16 @@ void GraphElementData::unsetProperty(QString key)
_properties.remove(i);
}
-void GraphElementData::operator <<(GraphElementProperty p)
+void GraphElementData::add(GraphElementProperty p)
{
_properties << p;
}
+void GraphElementData::operator <<(GraphElementProperty p)
+{
+ add(p);
+}
+
void GraphElementData::setAtom(QString atom)
{
GraphElementProperty a(atom);
diff --git a/tikzit/src/data/graphelementdata.h b/tikzit/src/data/graphelementdata.h
index e3d7a68..82279cf 100644
--- a/tikzit/src/data/graphelementdata.h
+++ b/tikzit/src/data/graphelementdata.h
@@ -50,6 +50,7 @@ public:
// const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE;
void operator <<(GraphElementProperty p);
+ void add(GraphElementProperty p);
signals:
public slots:
diff --git a/tikzit/src/data/node.cpp b/tikzit/src/data/node.cpp
index 2c1c7ee..b3b2155 100644
--- a/tikzit/src/data/node.cpp
+++ b/tikzit/src/data/node.cpp
@@ -4,22 +4,22 @@
Node::Node(QObject *parent) : QObject(parent)
{
- qDebug() << "Node()";
+ _data = new GraphElementData();
}
Node::~Node()
{
- qDebug() << "~Node()";
+ delete _data;
}
-QPointF Node::pos() const
+QPointF Node::point() const
{
- return _pos;
+ return _point;
}
-void Node::setPos(const QPointF &pos)
+void Node::setPoint(const QPointF &point)
{
- _pos = pos;
+ _point = point;
}
QString Node::name() const
@@ -41,3 +41,15 @@ void Node::setLabel(const QString &label)
{
_label = label;
}
+
+GraphElementData *Node::data() const
+{
+ return _data;
+}
+
+void Node::setData(GraphElementData *data)
+{
+ delete _data;
+ _data = data;
+}
+
diff --git a/tikzit/src/data/node.h b/tikzit/src/data/node.h
index 8eae520..6205732 100644
--- a/tikzit/src/data/node.h
+++ b/tikzit/src/data/node.h
@@ -1,6 +1,8 @@
#ifndef NODE_H
#define NODE_H
+#include "graphelementdata.h"
+
#include <QObject>
#include <QPointF>
#include <QString>
@@ -12,8 +14,8 @@ public:
explicit Node(QObject *parent = 0);
~Node();
- QPointF pos() const;
- void setPos(const QPointF &pos);
+ QPointF point() const;
+ void setPoint(const QPointF &point);
QString name() const;
void setName(const QString &name);
@@ -21,14 +23,20 @@ public:
QString label() const;
void setLabel(const QString &label);
+
+
+ GraphElementData *data() const;
+ void setData(GraphElementData *data);
+
signals:
public slots:
private:
- QPointF _pos;
+ QPointF _point;
QString _name;
QString _label;
+ GraphElementData *_data;
};
#endif // NODE_H
diff --git a/tikzit/src/data/tikzgraphassembler.cpp b/tikzit/src/data/tikzgraphassembler.cpp
index a785d85..d8e3963 100644
--- a/tikzit/src/data/tikzgraphassembler.cpp
+++ b/tikzit/src/data/tikzgraphassembler.cpp
@@ -1,9 +1,16 @@
#include "tikzgraphassembler.h"
-TikzGraphAssembler::TikzGraphAssembler(QObject *parent) : QObject(parent)
+TikzGraphAssembler::TikzGraphAssembler(Graph *graph, QObject *parent) :
+ _graph(graph), QObject(parent)
{
}
void TikzGraphAssembler::addNodeToMap(Node *n) { _nodeMap.insert(n->name(), n); }
Node *TikzGraphAssembler::nodeWithName(QString name) { return _nodeMap[name]; }
+
+Graph *TikzGraphAssembler::graph() const
+{
+ return _graph;
+}
+
diff --git a/tikzit/src/data/tikzgraphassembler.h b/tikzit/src/data/tikzgraphassembler.h
index 5869d95..2ae42fd 100644
--- a/tikzit/src/data/tikzgraphassembler.h
+++ b/tikzit/src/data/tikzgraphassembler.h
@@ -2,6 +2,7 @@
#define TIKZGRAPHASSEMBLER_H
#include "node.h"
+#include "graph.h"
#include <QObject>
#include <QHash>
@@ -10,16 +11,19 @@ class TikzGraphAssembler : public QObject
{
Q_OBJECT
public:
- explicit TikzGraphAssembler(QObject *parent = 0);
+ explicit TikzGraphAssembler(Graph *graph, QObject *parent = 0);
void addNodeToMap(Node *n);
Node *nodeWithName(QString name);
+ Graph *graph() const;
+
signals:
public slots:
private:
QHash<QString,Node*> _nodeMap;
+ Graph *_graph;
};
#endif // TIKZGRAPHASSEMBLER_H
diff --git a/tikzit/src/data/tikzlexer.l b/tikzit/src/data/tikzlexer.l
index 0a5ca6f..adb6fef 100644
--- a/tikzit/src/data/tikzlexer.l
+++ b/tikzit/src/data/tikzlexer.l
@@ -20,10 +20,10 @@
*/
#include "tikzparserdefs.h"
-#include "tikzparser.h"
+#include "tikzparser.parser.hpp"
+
+#include <sstream>
-#include <QString>
-#include <stringstream>
#define YY_USER_ACTION \
yylloc->first_line = yylloc->last_line; \
@@ -80,12 +80,12 @@ to { return TO; }
BEGIN(xcoord);
}
<xcoord>{FLOAT} {
- yylval->pt.x=(float)strtod(yytext,NULL);
+ yylval->pt->setX(strtod(yytext,NULL));
BEGIN(ycoord);
}
<ycoord>, { }
<ycoord>{FLOAT} {
- yylval->pt.y=(float)strtod(yytext,NULL);
+ yylval->pt->setY(strtod(yytext,NULL));
}
<ycoord>\) {
BEGIN(INITIAL);
@@ -103,7 +103,7 @@ to { return TO; }
property names or values, but in practice this is unlikely and
screws up our line counting */
<props>[^=,\{\] \t\n]([^=,\{\]\n]*[^=,\{\] \t\n])? {
- yylval->nsstr=[NSString stringWithUTF8String:yytext];
+ yylval->qstr= new QString(yytext);
return PROPSTRING;
}
<props>\] {
@@ -121,7 +121,7 @@ to { return TO; }
/* we assume node names (and anchor names) never contain
newlines */
<noderef>[^\.\{\)\n]+ {
- yylval->qstr=QString(yytext);
+ yylval->qstr = new QString(yytext);
return REFSTRING;
}
<noderef>\) {
@@ -134,7 +134,7 @@ to { return TO; }
unsigned int brace_depth = 1;
unsigned int escape = 0;
while (1) {
- char c = input(yyscanner);
+ char c = yyinput(yyscanner);
// eof reached before closing brace
if (c == '\0' || c == EOF) {
return UNCLOSED_DELIM_STR;
@@ -157,8 +157,10 @@ to { return TO; }
}
buf << c;
}
+
+
- yylval->qstr = QString(buf.str());
+ yylval->qstr = new QString(QString::fromStdString(buf.str()));
return DELIMITEDSTRING;
}
diff --git a/tikzit/src/data/tikzparser.y b/tikzit/src/data/tikzparser.y
index ca3b4e4..39d89c6 100644
--- a/tikzit/src/data/tikzparser.y
+++ b/tikzit/src/data/tikzparser.y
@@ -41,12 +41,12 @@
/* possible data types for semantic values */
%union {
- QString qstr;
+ QString *qstr;
GraphElementProperty *prop;
GraphElementData *data;
Node *node;
- QPointF pt;
- struct noderef noderef;
+ QPointF *pt;
+ struct noderef noderef;
}
%{
@@ -123,7 +123,7 @@ void yyerror(YYLTYPE *yylloc, void *scanner, const char *str) {
tikzpicture: "\\begin{tikzpicture}" optproperties tikzcmds "\\end{tikzpicture}"
{
if ($2) {
- assembler->graph()->setData($2);
+ assembler->graph()->setData($2);
}
};
tikzcmds: tikzcmds tikzcmd | ;
@@ -139,40 +139,53 @@ optproperties:
| { $$ = 0; };
properties: extraproperties property
{
- $1 << $2;
+ $1->add(*$2);
+ delete $2;
$$ = $1;
};
extraproperties:
extraproperties property ","
{
- $1 << $2;
+ $1->add(*$2);
+ delete $2;
$$ = $1;
}
- | { $$ = GraphElementData(); };
+ | { $$ = new GraphElementData(); };
property:
val "=" val
- { $$ = GraphElementProperty($1,$3); }
+ {
+ GraphElementProperty *p = new GraphElementProperty(*$1,*$3);
+ delete $1, $3;
+ $$ = p;
+ }
| val
- { $$ = GraphElementProperty($1); };
+ {
+ GraphElementProperty *a = new GraphElementProperty(*$1);
+ delete $1;
+ $$ = a;
+ };
val: PROPSTRING { $$ = $1; } | DELIMITEDSTRING { $$ = $1; };
nodename: "(" REFSTRING ")" { $$ = $2; };
node: "\\node" optproperties nodename "at" COORD DELIMITEDSTRING ";"
{
Node *node = assembler->graph()->addNode();
- if ($2)
- node->setData($2);
- node->setName($3);
- node->setPoint($5);
- node->setLabel($6);
+ if ($2) {
+ node->setData($2);
+ }
+ node->setName(*$3);
+ node->setPoint(*$5);
+ node->setLabel(*$6);
+ delete $3, $5, $6;
assembler->addNodeToMap(node);
};
optanchor: { $$ = 0; } | "." REFSTRING { $$ = $2; };
noderef: "(" REFSTRING optanchor ")"
{
- $$.node = assembler->nodeWithName($2);
- $$.anchor = $3;
+ $$.node = assembler->nodeWithName(*$2);
+ delete $2;
+ $$.anchor = $3;
};
optnoderef:
noderef { $$ = $1; }
@@ -193,25 +206,29 @@ edge: "\\draw" optproperties noderef "to" optedgenode optnoderef ";"
Node *t;
Node *en;
+ QString sa;
+ QString ta;
+
// TODO: anchors and edge nodes
s = $3.node;
+ sa = *$3.anchor;
+ delete $3.anchor;
if ($6.node) {
t = $6.node;
- //[edge setTargetAnchor:$6.anchor];
+ ta = *$6.anchor;
+ delete $6.anchor;
} else {
- t = $3.node;
- //[edge setTargetAnchor:$3.anchor];
+ t = s;
+ ta = sa;
}
Edge *edge = assembler->graph()->addEdge(s, t);
if ($2)
edge->setData($2);
- // [edge setSourceAnchor:$3.anchor];
- // [edge setEdgeNode:$5];
-
- // [edge setAttributesFromData];
+ edge->setSourceAnchor(sa);
+ edge->setTargetAnchor(ta);
};
ignoreprop: val | val "=" val;
diff --git a/tikzit/src/data/tikzparserdefs.h b/tikzit/src/data/tikzparserdefs.h
index f721ba5..7ba5bc5 100644
--- a/tikzit/src/data/tikzparserdefs.h
+++ b/tikzit/src/data/tikzparserdefs.h
@@ -1,2 +1,16 @@
-// nothing here
+#ifndef TIKZPARSERDEFS_H
+#define TIKZPARSERDEFS_H
+#include "graphelementproperty.h"
+#include "graphelementdata.h"
+#include "node.h"
+#include "tikzgraphassembler.h"
+
+#include <QString>
+
+struct noderef {
+ Node *node;
+ QString *anchor;
+};
+
+#endif // TIKZPARSERDEFS_H
diff --git a/tikzit/src/test/testtest.cpp b/tikzit/src/test/testtest.cpp
new file mode 100644
index 0000000..c6de586
--- /dev/null
+++ b/tikzit/src/test/testtest.cpp
@@ -0,0 +1,17 @@
+#include <QObject>
+#include <QTest>
+
+class TestTest: public QObject
+{
+ Q_OBJECT
+private slots:
+ void initTestCase()
+ { qDebug("initialising test"); }
+ void myFirstTest()
+ { QVERIFY(1 == 1); }
+ void mySecondTest()
+ { QVERIFY(1 != 2); }
+ void cleanupTestCase()
+ { qDebug("cleaning up test"); }
+};
+
diff --git a/tikzit/tikzit.pro b/tikzit/tikzit.pro
index 0c8feb5..846fd73 100644
--- a/tikzit/tikzit.pro
+++ b/tikzit/tikzit.pro
@@ -7,11 +7,12 @@
include(flex.pri)
include(bison.pri)
-QT += core gui
+QT += core gui testlib
+CONFIG += testcase
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
-TARGET = tikzit
+TARGET = tikzit
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
@@ -29,7 +30,7 @@ FLEXSOURCES = src/data/tikzlexer.l
BISONSOURCES = src/data/tikzparser.y
SOURCES += src/main.cpp\
- src/gui/mainwindow.cpp \
+ src/gui/mainwindow.cpp \
src/gui/toolpalette.cpp \
src/gui/tikzscene.cpp \
src/data/graph.cpp \
@@ -38,7 +39,8 @@ SOURCES += src/main.cpp\
src/data/tikzgraphassembler.cpp \
src/data/graphelementdata.cpp \
src/data/graphelementproperty.cpp \
- src/gui/propertypalette.cpp
+ src/gui/propertypalette.cpp \
+ src/test/testtest.cpp
HEADERS += src/gui/mainwindow.h \
src/gui/toolpalette.h \
@@ -50,8 +52,6 @@ HEADERS += src/gui/mainwindow.h \
src/data/graphelementdata.h \
src/data/graphelementproperty.h \
src/gui/propertypalette.h \
- src/data/tikzlexer.lpp \
- src/data/tikzparser.ypp \
src/data/tikzparserdefs.h
FORMS += src/gui/mainwindow.ui \