summaryrefslogtreecommitdiff
path: root/src/data
diff options
context:
space:
mode:
authorAleks Kissinger <aleks0@gmail.com>2018-04-05 13:20:20 +0200
committerAleks Kissinger <aleks0@gmail.com>2018-04-05 13:20:20 +0200
commit1a71fd8efa0350d1e121f6792e8fad67e82b25c1 (patch)
tree0e706cf35256c5195974105218ad2b6ea49e1193 /src/data
parent8b8ea9395bdda4bb1404497ff654b82098084822 (diff)
fixed name conflict, now builds in MSVC
Diffstat (limited to 'src/data')
-rw-r--r--src/data/edge.cpp32
-rw-r--r--src/data/graph.cpp7
-rw-r--r--src/data/tikzdocument.cpp2
-rw-r--r--src/data/tikzparser.y52
-rw-r--r--src/data/tikzparserdefs.h4
5 files changed, 55 insertions, 42 deletions
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 <QTextStream>
#include <QSet>
@@ -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<Node *> 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 <http://www.gnu.org/licenses/>.
*/
+
#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 <pt> COORD "co-ordinate"
+%token <pt> TCOORD "coordinate"
%token <str> PROPSTRING "key/value string"
%token <str> REFSTRING "string"
%token <str> 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