From 1a71fd8efa0350d1e121f6792e8fad67e82b25c1 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Thu, 5 Apr 2018 13:20:20 +0200 Subject: fixed name conflict, now builds in MSVC --- src/data/edge.cpp | 32 +++++++++++++++-------------- src/data/graph.cpp | 7 +++++-- src/data/tikzdocument.cpp | 2 +- src/data/tikzparser.y | 52 +++++++++++++++++++++++++---------------------- src/data/tikzparserdefs.h | 4 ++++ 5 files changed, 55 insertions(+), 42 deletions(-) (limited to 'src/data') diff --git a/src/data/edge.cpp b/src/data/edge.cpp index d3396e8..bcf127f 100644 --- a/src/data/edge.cpp +++ b/src/data/edge.cpp @@ -222,21 +222,23 @@ void Edge::updateData() // TODO: style handling? - if (_basicBendMode && _bend != 0) { - QString bendKey; - int b; - if (_bend < 0) { - bendKey = "bend left"; - b = -_bend; - } else { - bendKey = "bend right"; - b = _bend; - } - - if (b == 30) { - _data->setAtom(bendKey); - } else { - _data->setProperty(bendKey, QString::number(b)); + if (_basicBendMode) { + if (_bend != 0) { + QString bendKey; + int b; + if (_bend < 0) { + bendKey = "bend left"; + b = -_bend; + } else { + bendKey = "bend right"; + b = _bend; + } + + if (b == 30) { + _data->setAtom(bendKey); + } else { + _data->setProperty(bendKey, QString::number(b)); + } } } else { _data->setProperty("in", QString::number(_inAngle)); diff --git a/src/data/graph.cpp b/src/data/graph.cpp index 208cd00..33af93d 100644 --- a/src/data/graph.cpp +++ b/src/data/graph.cpp @@ -1,4 +1,5 @@ #include "graph.h" +#include "util.h" #include #include @@ -158,7 +159,9 @@ QString Graph::tikz() code << n->data()->tikz() << " "; code << "(" << n->name() << ") at (" - << n->point().x() << ", " << n->point().y() + << floatToString(n->point().x()) + << ", " + << floatToString(n->point().y()) << ") {" << n->label() << "};\n"; line++; } @@ -230,7 +233,7 @@ Graph *Graph::copyOfSubgraphWithNodes(QSet nds) g->addNode(n1); } foreach (Edge *e, edges()) { - if (nds.contains(e->source()) || nds.contains(e->target())) { + if (nds.contains(e->source()) && nds.contains(e->target())) { g->addEdge(e->copy(&nodeTable)); } } diff --git a/src/data/tikzdocument.cpp b/src/data/tikzdocument.cpp index eeb4e14..4a813ad 100644 --- a/src/data/tikzdocument.cpp +++ b/src/data/tikzdocument.cpp @@ -85,7 +85,7 @@ void TikzDocument::save() { QSettings settings("tikzit", "tikzit"); settings.setValue("previous-file-path", fi.absolutePath()); - if (file.open(QIODevice::ReadWrite)) { + if (file.open(QIODevice::WriteOnly)) { QTextStream stream(&file); stream << _tikz; file.close(); diff --git a/src/data/tikzparser.y b/src/data/tikzparser.y index 76674f1..6e708a3 100644 --- a/src/data/tikzparser.y +++ b/src/data/tikzparser.y @@ -25,6 +25,7 @@ * along with this program. If not, see . */ + #include "tikzparserdefs.h" %} @@ -62,7 +63,7 @@ #include "graphelementproperty.h" #include "tikzlexer.h" -#import "tikzassembler.h" +#include "tikzassembler.h" /* the assembler (used by this parser) is stored in the lexer state as "extra" data */ #define assembler yyget_extra(scanner) @@ -71,7 +72,7 @@ void yyerror(YYLTYPE *yylloc, void *scanner, const char *str) { // TODO: implement reportError() //assembler->reportError(str, yylloc); - qDebug() << "parse error: " << str; + qDebug() << "\nparse error: " << str << " line:" << yylloc->first_line; } %} @@ -104,7 +105,7 @@ void yyerror(YYLTYPE *yylloc, void *scanner, const char *str) { %token RIGHTBRACKET "]" %token FULLSTOP "." %token EQUALS "=" -%token COORD "co-ordinate" +%token TCOORD "coordinate" %token PROPSTRING "key/value string" %token REFSTRING "string" %token DELIMITEDSTRING "{-delimited string" @@ -187,7 +188,7 @@ property: val: PROPSTRING { $$ = $1; } | DELIMITEDSTRING { $$ = $1; }; nodename: "(" REFSTRING ")" { $$ = $2; }; -node: "\\node" optproperties nodename "at" COORD DELIMITEDSTRING ";" +node: "\\node" optproperties nodename "at" TCOORD DELIMITEDSTRING ";" { Node *node = new Node(); @@ -240,36 +241,39 @@ edge: "\\draw" optproperties noderef "to" optedgenode optnoderef ";" t = s; } - Edge *edge = new Edge(s, t); - if ($2) { - edge->setData($2); - edge->setAttributesFromData(); - } + // if the source or the target of the edge doesn't exist, quietly ignore it. + if (s != 0 && t != 0) { + Edge *edge = new Edge(s, t); + if ($2) { + edge->setData($2); + edge->setAttributesFromData(); + } - if ($5) - edge->setEdgeNode($5); - if ($3.anchor) { - edge->setSourceAnchor(QString($3.anchor)); - free($3.anchor); - } + if ($5) + edge->setEdgeNode($5); + if ($3.anchor) { + edge->setSourceAnchor(QString($3.anchor)); + free($3.anchor); + } - if ($6.node) { - if ($6.anchor) { - edge->setTargetAnchor(QString($6.anchor)); - free($6.anchor); + if ($6.node) { + if ($6.anchor) { + edge->setTargetAnchor(QString($6.anchor)); + free($6.anchor); + } + } else { + edge->setTargetAnchor(edge->sourceAnchor()); } - } else { - edge->setTargetAnchor(edge->sourceAnchor()); - } - assembler->graph()->addEdge(edge); + assembler->graph()->addEdge(edge); + } }; ignoreprop: val | val "=" val; ignoreprops: ignoreprop ignoreprops | ; optignoreprops: "[" ignoreprops "]"; boundingbox: - "\\path" optignoreprops COORD "rectangle" COORD ";" + "\\path" optignoreprops TCOORD "rectangle" TCOORD ";" { assembler->graph()->setBbox(QRectF(*$3, *$5)); delete $3; diff --git a/src/data/tikzparserdefs.h b/src/data/tikzparserdefs.h index b51a8c9..1625136 100644 --- a/src/data/tikzparserdefs.h +++ b/src/data/tikzparserdefs.h @@ -1,6 +1,8 @@ #ifndef TIKZPARSERDEFS_H #define TIKZPARSERDEFS_H +#define YY_NO_UNISTD_H 1 + #include "graphelementproperty.h" #include "graphelementdata.h" #include "node.h" @@ -15,4 +17,6 @@ struct noderef { char *anchor; }; +inline int isatty(void*) { return 0; } + #endif // TIKZPARSERDEFS_H -- cgit v1.2.3