summaryrefslogtreecommitdiff
path: root/tikzit/src/data
diff options
context:
space:
mode:
Diffstat (limited to 'tikzit/src/data')
-rw-r--r--tikzit/src/data/edge.cpp4
-rw-r--r--tikzit/src/data/graph.cpp43
-rw-r--r--tikzit/src/data/graph.h10
-rw-r--r--tikzit/src/data/node.cpp7
-rw-r--r--tikzit/src/data/node.h4
-rw-r--r--tikzit/src/data/nodestyle.cpp2
-rw-r--r--tikzit/src/data/nodestyle.h2
7 files changed, 42 insertions, 30 deletions
diff --git a/tikzit/src/data/edge.cpp b/tikzit/src/data/edge.cpp
index 3ff6c6e..6802b2d 100644
--- a/tikzit/src/data/edge.cpp
+++ b/tikzit/src/data/edge.cpp
@@ -117,14 +117,14 @@ void Edge::updateControls() {
}
// TODO: calculate head and tail properly, not just for circles
- if (_source->style().isNone()) {
+ if (_source->style()->isNone()) {
_tail = src;
} else {
_tail = QPointF(src.x() + std::cos(outAngleR) * 0.1,
src.y() + std::sin(outAngleR) * 0.1);
}
- if (_target->style().isNone()) {
+ if (_target->style()->isNone()) {
_head = targ;
} else {
_head = QPointF(targ.x() + std::cos(inAngleR) * 0.1,
diff --git a/tikzit/src/data/graph.cpp b/tikzit/src/data/graph.cpp
index 4329928..ba9a4c6 100644
--- a/tikzit/src/data/graph.cpp
+++ b/tikzit/src/data/graph.cpp
@@ -1,6 +1,10 @@
#include "graph.h"
#include <QTextStream>
+#include <QSet>
+#include <QtAlgorithms>
+#include <QDebug>
+#include <algorithm>
Graph::Graph(QObject *parent) : QObject(parent)
{
@@ -12,30 +16,42 @@ Graph::~Graph()
{
}
+// add a node. The graph claims ownership.
+void Graph::addNode(Node *n) {
+ n->setParent(this);
+ _nodes << n;
+}
+
+void Graph::addNode(Node *n, int index)
+{
+ n->setParent(this);
+ _nodes.insert(index, n);
+}
+
void Graph::removeNode(Node *n) {
// the node itself is not deleted, as it may still be referenced in an undo command. It will
// be deleted when graph is, via QObject memory management.
- _nodes.removeAll(n);
- inEdges.remove(n);
- outEdges.remove(n);
+ _nodes.removeOne(n);
}
-Edge *Graph::addEdge(Edge *e)
+
+void Graph::addEdge(Edge *e)
{
e->setParent(this);
_edges << e;
- outEdges.insert(e->source(), e);
- inEdges.insert(e->target(), e);
- return e;
+}
+
+void Graph::addEdge(Edge *e, int index)
+{
+ e->setParent(this);
+ _edges.insert(index, e);
}
void Graph::removeEdge(Edge *e)
{
// the edge itself is not deleted, as it may still be referenced in an undo command. It will
// be deleted when graph is, via QObject memory management.
- _edges.removeAll(e);
- outEdges.remove(e->source(), e);
- inEdges.remove(e->target(), e);
+ _edges.removeOne(e);
}
GraphElementData *Graph::data() const
@@ -153,11 +169,4 @@ void Graph::setBbox(const QRectF &bbox)
_bbox = bbox;
}
-// add a node. The graph claims ownership.
-Node *Graph::addNode(Node *n) {
- n->setParent(this);
- _nodes << n;
- return n;
-}
-
diff --git a/tikzit/src/data/graph.h b/tikzit/src/data/graph.h
index 963def8..8856e5c 100644
--- a/tikzit/src/data/graph.h
+++ b/tikzit/src/data/graph.h
@@ -21,9 +21,11 @@ class Graph : public QObject
public:
explicit Graph(QObject *parent = 0);
~Graph();
- Node *addNode(Node *n);
+ void addNode(Node *n);
+ void addNode(Node *n, int index);
void removeNode(Node *n);
- Edge *addEdge(Edge *e);
+ void addEdge(Edge *e);
+ void addEdge(Edge *e, int index);
void removeEdge(Edge *e);
GraphElementData *data() const;
@@ -45,8 +47,8 @@ public slots:
private:
QVector<Node*> _nodes;
QVector<Edge*> _edges;
- QMultiHash<Node*,Edge*> inEdges;
- QMultiHash<Node*,Edge*> outEdges;
+ //QMultiHash<Node*,Edge*> inEdges;
+ //QMultiHash<Node*,Edge*> outEdges;
GraphElementData *_data;
QRectF _bbox;
};
diff --git a/tikzit/src/data/node.cpp b/tikzit/src/data/node.cpp
index 1b8ccf8..f94a3df 100644
--- a/tikzit/src/data/node.cpp
+++ b/tikzit/src/data/node.cpp
@@ -6,7 +6,7 @@
Node::Node(QObject *parent) : QObject(parent)
{
_data = new GraphElementData();
- _style = NodeStyle();
+ _style = noneStyle;
_styleName = "none";
}
@@ -69,12 +69,11 @@ void Node::setStyleName(const QString &styleName)
void Node::attachStyle()
{
- if (_styleName == "none") _style = NodeStyle();
+ if (_styleName == "none") _style = noneStyle;
else _style = tikzit->nodeStyle(_styleName);
}
-NodeStyle Node::style() const
+NodeStyle *Node::style() const
{
return _style;
}
-
diff --git a/tikzit/src/data/node.h b/tikzit/src/data/node.h
index 91b1725..ee70835 100644
--- a/tikzit/src/data/node.h
+++ b/tikzit/src/data/node.h
@@ -31,7 +31,7 @@ public:
void setStyleName(const QString &styleName);
void attachStyle();
- NodeStyle style() const;
+ NodeStyle *style() const;
signals:
@@ -42,7 +42,7 @@ private:
QString _name;
QString _label;
QString _styleName;
- NodeStyle _style;
+ NodeStyle *_style;
GraphElementData *_data;
};
diff --git a/tikzit/src/data/nodestyle.cpp b/tikzit/src/data/nodestyle.cpp
index 109e2af..7eca791 100644
--- a/tikzit/src/data/nodestyle.cpp
+++ b/tikzit/src/data/nodestyle.cpp
@@ -1,5 +1,7 @@
#include "nodestyle.h"
+NodeStyle *noneStyle = new NodeStyle();
+
NodeStyle::NodeStyle()
{
name = "none";
diff --git a/tikzit/src/data/nodestyle.h b/tikzit/src/data/nodestyle.h
index baf967c..00d1b20 100644
--- a/tikzit/src/data/nodestyle.h
+++ b/tikzit/src/data/nodestyle.h
@@ -21,6 +21,6 @@ public:
int strokeThickness;
};
-extern NodeStyle noneStyle;
+extern NodeStyle *noneStyle;
#endif // NODESTYLE_H