summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleks Kissinger <aleks0@gmail.com>2018-10-06 15:49:50 +0200
committerAleks Kissinger <aleks0@gmail.com>2018-10-06 15:49:50 +0200
commit6359b28b155355e0be67961cc21eccdbd2c61cc2 (patch)
tree94992fb08ffedf2b1481e97e7af34fbdfc076408
parente61fb864ec68a58abdb9cc9df047b4b75801c5e7 (diff)
unified node and edge syles
-rw-r--r--src/data/edgestyle.cpp210
-rw-r--r--src/data/edgestyle.h32
-rw-r--r--src/data/nodestyle.cpp145
-rw-r--r--src/data/nodestyle.h13
-rw-r--r--src/data/nodestylelist.cpp113
-rw-r--r--src/data/nodestylelist.h40
-rw-r--r--src/data/style.cpp182
-rw-r--r--src/data/style.h39
-rw-r--r--src/data/tikzstyles.cpp34
-rw-r--r--src/data/tikzstyles.h6
-rw-r--r--tikzit.pro224
11 files changed, 689 insertions, 349 deletions
diff --git a/src/data/edgestyle.cpp b/src/data/edgestyle.cpp
index 8f3008f..7897c6f 100644
--- a/src/data/edgestyle.cpp
+++ b/src/data/edgestyle.cpp
@@ -21,7 +21,7 @@
#include <QPainter>
#include <QPixmap>
-EdgeStyle *noneEdgeStyle = new EdgeStyle();
+EdgeStyle *noneEdgeStyle = new EdgeStyle("none", new GraphElementData({GraphElementProperty("-")}));
EdgeStyle::EdgeStyle() : Style()
{
@@ -31,107 +31,107 @@ EdgeStyle::EdgeStyle(QString name, GraphElementData *data) : Style(name, data)
{
}
-EdgeStyle::ArrowTipStyle EdgeStyle::arrowHead() const
-{
- if (_data == 0) return NoTip;
-
- if (_data->atom("->") || _data->atom("<->") || _data->atom("|->")) return Pointer;
- if (_data->atom("-|") || _data->atom("<-|") || _data->atom("|-|")) return Flat;
- return NoTip;
-}
-
-EdgeStyle::ArrowTipStyle EdgeStyle::arrowTail() const
-{
- if (_data == 0) return NoTip;
- if (_data->atom("<-") || _data->atom("<->") || _data->atom("<-|")) return Pointer;
- if (_data->atom("|-") || _data->atom("|->") || _data->atom("|-|")) return Flat;
- return NoTip;
-}
-
-EdgeStyle::DrawStyle EdgeStyle::drawStyle() const
-{
- if (_data == 0) return Solid;
- if (_data->atom("dashed")) return Dashed;
- if (_data->atom("dotted")) return Dotted;
- return Solid;
-}
-
-QPen EdgeStyle::pen() const
-{
- QPen p(strokeColor());
- p.setWidthF((float)strokeThickness() * 2.0f);
-
- QVector<qreal> pat;
- switch (drawStyle()) {
- case Dashed:
- pat << 3.0 << 3.0;
- p.setDashPattern(pat);
- break;
- case Dotted:
- pat << 1.0 << 1.0;
- p.setDashPattern(pat);
- break;
- case Solid:
- break;
- }
-
- return p;
-}
-
-QPainterPath EdgeStyle::path() const
-{
- return QPainterPath();
-}
-
-QPainterPath EdgeStyle::palettePath() const
-{
- return QPainterPath();
-}
-
-QIcon EdgeStyle::icon() const
-{
- // draw an icon matching the style
- QPixmap px(100,100);
- px.fill(Qt::transparent);
- QPainter painter(&px);
-
- if (_data == 0) {
- QPen pen(Qt::black);
- pen.setWidth(3);
- } else {
- painter.setPen(pen());
- }
-
- painter.drawLine(10, 50, 90, 50);
-
- QPen pn = pen();
- pn.setStyle(Qt::SolidLine);
- painter.setPen(pn);
-
- switch (arrowHead()) {
- case Pointer:
- painter.drawLine(90,50,80,40);
- painter.drawLine(90,50,80,60);
- break;
- case Flat:
- painter.drawLine(90,40,90,60);
- break;
- case NoTip:
- break;
- }
-
- switch (arrowTail()) {
- case Pointer:
- painter.drawLine(10,50,20,40);
- painter.drawLine(10,50,20,60);
- break;
- case Flat:
- painter.drawLine(10,40,10,60);
- break;
- case NoTip:
- break;
- }
-
-
- return QIcon(px);
-}
+//EdgeStyle::ArrowTipStyle EdgeStyle::arrowHead() const
+//{
+// if (_data == 0) return NoTip;
+
+// if (_data->atom("->") || _data->atom("<->") || _data->atom("|->")) return Pointer;
+// if (_data->atom("-|") || _data->atom("<-|") || _data->atom("|-|")) return Flat;
+// return NoTip;
+//}
+
+//EdgeStyle::ArrowTipStyle EdgeStyle::arrowTail() const
+//{
+// if (_data == 0) return NoTip;
+// if (_data->atom("<-") || _data->atom("<->") || _data->atom("<-|")) return Pointer;
+// if (_data->atom("|-") || _data->atom("|->") || _data->atom("|-|")) return Flat;
+// return NoTip;
+//}
+
+//EdgeStyle::DrawStyle EdgeStyle::drawStyle() const
+//{
+// if (_data == 0) return Solid;
+// if (_data->atom("dashed")) return Dashed;
+// if (_data->atom("dotted")) return Dotted;
+// return Solid;
+//}
+
+//QPen EdgeStyle::pen() const
+//{
+// QPen p(strokeColor());
+// p.setWidthF((float)strokeThickness() * 2.0f);
+
+// QVector<qreal> pat;
+// switch (drawStyle()) {
+// case Dashed:
+// pat << 3.0 << 3.0;
+// p.setDashPattern(pat);
+// break;
+// case Dotted:
+// pat << 1.0 << 1.0;
+// p.setDashPattern(pat);
+// break;
+// case Solid:
+// break;
+// }
+
+// return p;
+//}
+
+//QPainterPath EdgeStyle::path() const
+//{
+// return QPainterPath();
+//}
+
+//QPainterPath EdgeStyle::palettePath() const
+//{
+// return QPainterPath();
+//}
+
+//QIcon EdgeStyle::icon() const
+//{
+// // draw an icon matching the style
+// QPixmap px(100,100);
+// px.fill(Qt::transparent);
+// QPainter painter(&px);
+
+// if (_data == 0) {
+// QPen pen(Qt::black);
+// pen.setWidth(3);
+// } else {
+// painter.setPen(pen());
+// }
+
+// painter.drawLine(10, 50, 90, 50);
+
+// QPen pn = pen();
+// pn.setStyle(Qt::SolidLine);
+// painter.setPen(pn);
+
+// switch (arrowHead()) {
+// case Pointer:
+// painter.drawLine(90,50,80,40);
+// painter.drawLine(90,50,80,60);
+// break;
+// case Flat:
+// painter.drawLine(90,40,90,60);
+// break;
+// case NoTip:
+// break;
+// }
+
+// switch (arrowTail()) {
+// case Pointer:
+// painter.drawLine(10,50,20,40);
+// painter.drawLine(10,50,20,60);
+// break;
+// case Flat:
+// painter.drawLine(10,40,10,60);
+// break;
+// case NoTip:
+// break;
+// }
+
+
+// return QIcon(px);
+//}
diff --git a/src/data/edgestyle.h b/src/data/edgestyle.h
index eac060a..0e7b554 100644
--- a/src/data/edgestyle.h
+++ b/src/data/edgestyle.h
@@ -33,22 +33,22 @@ public:
EdgeStyle();
EdgeStyle(QString name, GraphElementData *data);
- enum ArrowTipStyle {
- Flat, Pointer, NoTip
- };
-
- enum DrawStyle {
- Solid, Dotted, Dashed
- };
-
- ArrowTipStyle arrowHead() const;
- ArrowTipStyle arrowTail() const;
- DrawStyle drawStyle() const;
-
- QPen pen() const override;
- QPainterPath path() const override;
- QPainterPath palettePath() const override;
- QIcon icon() const override;
+// enum ArrowTipStyle {
+// Flat, Pointer, NoTip
+// };
+
+// enum DrawStyle {
+// Solid, Dotted, Dashed
+// };
+
+// ArrowTipStyle arrowHead() const;
+// ArrowTipStyle arrowTail() const;
+// DrawStyle drawStyle() const;
+
+// QPen pen() const override;
+// QPainterPath path() const override;
+// QPainterPath palettePath() const override;
+// QIcon icon() const override;
};
extern EdgeStyle *noneEdgeStyle;
diff --git a/src/data/nodestyle.cpp b/src/data/nodestyle.cpp
index 8bdb763..b379565 100644
--- a/src/data/nodestyle.cpp
+++ b/src/data/nodestyle.cpp
@@ -34,74 +34,79 @@ NodeStyle::NodeStyle(QString name, GraphElementData *data): Style(name, data)
{
}
-QColor NodeStyle::fillColor(bool tikzitOverride) const
-{
- if (_data == 0) return Qt::white;
-
- QString col = propertyWithDefault("fill", "white", tikzitOverride);
- return tikzit->colorByName(col);
-}
-
-QBrush NodeStyle::brush() const
-{
- return QBrush(fillColor());
-}
-
-QString NodeStyle::shape(bool tikzitOverride) const
-{
- return propertyWithDefault("shape", "circle", tikzitOverride);
-}
-
-QPainterPath NodeStyle::path() const
-{
- QPainterPath pth;
- QString sh = shape();
-
- if (sh == "rectangle") {
- pth.addRect(-30.0f, -30.0f, 60.0f, 60.0f);
- } else { // default is 'circle'
- pth.addEllipse(QPointF(0.0f,0.0f), 30.0f, 30.0f);
- }
- return pth;
-}
-
-QPainterPath NodeStyle::palettePath() const
-{
- return path();
-}
-
-QIcon NodeStyle::icon() const
-{
- // draw an icon matching the style
- QImage px(100,100,QImage::Format_ARGB32_Premultiplied);
- px.fill(Qt::transparent);
-
-
- QPainter painter(&px);
- painter.setRenderHint(QPainter::Antialiasing);
- QPainterPath pth = path();
- pth.translate(50.0f, 50.0f);
-
- if (_data == 0) {
- QColor c(180,180,200);
- painter.setPen(QPen(c));
- painter.setBrush(QBrush(c));
- painter.drawEllipse(QPointF(50.0f,50.0f), 3,3);
-
- QPen pen(QColor(180,180,220));
- pen.setWidth(3);
- QVector<qreal> p;
- p << 2.0 << 2.0;
- pen.setDashPattern(p);
- painter.setPen(pen);
- painter.setBrush(Qt::NoBrush);
- painter.drawPath(pth);
- } else {
- painter.setPen(pen());
- painter.setBrush(brush());
- painter.drawPath(pth);
- }
-
- return QIcon(QPixmap::fromImage(px));
-}
+//QColor NodeStyle::fillColor(bool tikzitOverride) const
+//{
+// if (_data == 0) return Qt::white;
+
+// QString col = propertyWithDefault("fill", "white", tikzitOverride);
+// return tikzit->colorByName(col);
+//}
+
+//QBrush NodeStyle::brush() const
+//{
+// return QBrush(fillColor());
+//}
+
+//QString NodeStyle::shape(bool tikzitOverride) const
+//{
+// return propertyWithDefault("shape", "circle", tikzitOverride);
+//}
+
+//QPainterPath NodeStyle::path() const
+//{
+// QPainterPath pth;
+// QString sh = shape();
+
+// if (sh == "rectangle") {
+// pth.addRect(-30.0f, -30.0f, 60.0f, 60.0f);
+// } else { // default is 'circle'
+// pth.addEllipse(QPointF(0.0f,0.0f), 30.0f, 30.0f);
+// }
+// return pth;
+//}
+
+//QPainterPath NodeStyle::palettePath() const
+//{
+// return path();
+//}
+
+//QIcon NodeStyle::icon() const
+//{
+// // draw an icon matching the style
+// QImage px(100,100,QImage::Format_ARGB32_Premultiplied);
+// px.fill(Qt::transparent);
+
+
+// QPainter painter(&px);
+// painter.setRenderHint(QPainter::Antialiasing);
+// QPainterPath pth = path();
+// pth.translate(50.0f, 50.0f);
+
+// if (_data == 0) {
+// QColor c(180,180,200);
+// painter.setPen(QPen(c));
+// painter.setBrush(QBrush(c));
+// painter.drawEllipse(QPointF(50.0f,50.0f), 3,3);
+
+// QPen pen(QColor(180,180,220));
+// pen.setWidth(3);
+// QVector<qreal> p;
+// p << 2.0 << 2.0;
+// pen.setDashPattern(p);
+// painter.setPen(pen);
+// painter.setBrush(Qt::NoBrush);
+// painter.drawPath(pth);
+// } else {
+// painter.setPen(pen());
+// painter.setBrush(brush());
+// painter.drawPath(pth);
+// }
+
+// return QIcon(QPixmap::fromImage(px));
+//}
+
+//QString NodeStyle::category()
+//{
+// return propertyWithDefault("tikzit category", "", false);
+//}
diff --git a/src/data/nodestyle.h b/src/data/nodestyle.h
index a3842ff..36bd5d5 100644
--- a/src/data/nodestyle.h
+++ b/src/data/nodestyle.h
@@ -33,13 +33,14 @@ public:
NodeStyle();
NodeStyle(QString name, GraphElementData *data);
- QColor fillColor(bool tikzitOverride=true) const;
- QBrush brush() const;
- QPainterPath path() const override;
- QString shape(bool tikzitOverride=true) const;
+// QColor fillColor(bool tikzitOverride=true) const;
+// QBrush brush() const;
+// QPainterPath path() const override;
+// QString shape(bool tikzitOverride=true) const;
+
+// QPainterPath palettePath() const override;
+// QIcon icon() const override;
- QPainterPath palettePath() const override;
- QIcon icon() const override;
};
extern NodeStyle *noneStyle;
diff --git a/src/data/nodestylelist.cpp b/src/data/nodestylelist.cpp
new file mode 100644
index 0000000..41749db
--- /dev/null
+++ b/src/data/nodestylelist.cpp
@@ -0,0 +1,113 @@
+#include "nodestylelist.h"
+
+#include <QTextStream>
+
+NodeStyleList::NodeStyleList(QObject *parent) : QAbstractListModel(parent)
+{
+}
+
+NodeStyle *NodeStyleList::style(QString name)
+{
+ foreach (NodeStyle *s, _styles)
+ if (s->name() == name) return s;
+ return nullptr;
+}
+
+NodeStyle *NodeStyleList::style(int i)
+{
+ return _styles[i];
+}
+
+int NodeStyleList::length() const
+{
+ return _styles.length();
+}
+
+void NodeStyleList::addStyle(NodeStyle *s)
+{
+ if (s->category() == _category) {
+ int n = numInCategory();
+ beginInsertRows(QModelIndex(), n, n);
+ _styles << s;
+ endInsertRows();
+ } else {
+ _styles << s;
+ }
+}
+
+void NodeStyleList::clear()
+{
+ int n = numInCategory();
+ if (n > 0) {
+ beginRemoveRows(QModelIndex(), 0, n - 1);
+ _styles.clear();
+ endRemoveRows();
+ } else {
+ _styles.clear();
+ }
+
+ _category = "";
+}
+
+QString NodeStyleList::tikz()
+{
+ QString str;
+ QTextStream code(&str);
+ foreach (NodeStyle *s, _styles) code << s->tikz() << "\n";
+ code.flush();
+ return str;
+}
+
+int NodeStyleList::numInCategory() const
+{
+ int c = 0;
+ foreach (NodeStyle *s, _styles) {
+ if (_category == "" || s->category() == _category) {
+ ++c;
+ }
+ }
+ return c;
+}
+
+int NodeStyleList::nthInCategory(int n) const
+{
+ int c = 0;
+ for (int j = 0; j < _styles.length(); ++j) {
+ if (_category == "" || _styles[j]->category() == _category) {
+ if (c == n) return j;
+ else ++c;
+ }
+ }
+ return -1;
+}
+
+NodeStyle *NodeStyleList::styleInCategory(int n) const
+{
+ return _styles[nthInCategory(n)];
+}
+
+QVariant NodeStyleList::data(const QModelIndex &index, int role) const
+{
+ if (role == Qt::DisplayRole) {
+ return QVariant(styleInCategory(index.row())->name());
+ } else if (role == Qt::DecorationRole) {
+ return QVariant(styleInCategory(index.row())->icon());
+ } else {
+ return QVariant();
+ }
+}
+
+int NodeStyleList::rowCount(const QModelIndex &/*parent*/) const
+{
+ return numInCategory();
+}
+
+QString NodeStyleList::category() const
+{
+ return _category;
+}
+
+void NodeStyleList::setCategory(const QString &category)
+{
+ _category = category;
+}
diff --git a/src/data/nodestylelist.h b/src/data/nodestylelist.h
new file mode 100644
index 0000000..03f7ed5
--- /dev/null
+++ b/src/data/nodestylelist.h
@@ -0,0 +1,40 @@
+#ifndef NODESTYLELIST_H
+#define NODESTYLELIST_H
+
+#include "nodestyle.h"
+
+#include <QAbstractListModel>
+
+class NodeStyleList : public QAbstractListModel
+{
+ Q_OBJECT
+public:
+ explicit NodeStyleList(QObject *parent = nullptr);
+ NodeStyle *style(QString name);
+ NodeStyle *style(int i);
+ int length() const;
+ void addStyle(NodeStyle *s);
+ void clear();
+ QString tikz();
+
+ int numInCategory() const;
+ int nthInCategory(int n) const;
+ NodeStyle *styleInCategory(int n) const;
+
+ QVariant data(const QModelIndex &index, int role) const override;
+ int rowCount(const QModelIndex &/*parent*/) const override;
+
+
+ QString category() const;
+ void setCategory(const QString &category);
+
+signals:
+
+public slots:
+
+private:
+ QVector<NodeStyle*> _styles;
+ QString _category;
+};
+
+#endif // NODESTYLELIST_H
diff --git a/src/data/style.cpp b/src/data/style.cpp
index 63747ec..39314cb 100644
--- a/src/data/style.cpp
+++ b/src/data/style.cpp
@@ -19,17 +19,19 @@
#include "style.h"
#include "tikzit.h"
-Style::Style() : _name("none"), _data(0)
+Style::Style() : _name("none")
{
+ _data = new GraphElementData(this);
}
Style::Style(QString name, GraphElementData *data) : _name(name), _data(data)
{
+ _data->setParent(this);
}
-bool Style::isNone()
+bool Style::isNone() const
{
- return _data == 0;
+ return _name == "none";
}
GraphElementData *Style::data() const
@@ -44,25 +46,43 @@ QString Style::name() const
QColor Style::strokeColor(bool tikzitOverride) const
{
- if (_data == 0) return QColor(Qt::black);
-
QString col = propertyWithDefault("draw", "black", tikzitOverride);
return tikzit->colorByName(col);
}
+QColor Style::fillColor(bool tikzitOverride) const
+{
+ QString col = propertyWithDefault("fill", "white", tikzitOverride);
+ return tikzit->colorByName(col);
+}
+
+QBrush Style::brush() const
+{
+ return QBrush(fillColor());
+}
+
+QString Style::shape(bool tikzitOverride) const
+{
+ return propertyWithDefault("shape", "circle", tikzitOverride);
+}
+
+
// TODO
int Style::strokeThickness() const
{
return 1;
}
-QPen Style::pen() const
+bool Style::isEdgeStyle() const
{
- QPen p(strokeColor());
- p.setWidthF((float)strokeThickness() * 3.0f);
- return p;
+ if (_data->atom("-") || _data->atom("->") || _data->atom("-|") ||
+ _data->atom("<-") || _data->atom("<->") || _data->atom("<-|") ||
+ _data->atom("|-") || _data->atom("|->") || _data->atom("|-|")) return true;
+ else return false;
}
+
+
QString Style::propertyWithDefault(QString prop, QString def, bool tikzitOverride) const
{
if (_data == 0) return def;
@@ -86,3 +106,147 @@ void Style::setName(const QString &name)
{
_name = name;
}
+
+Style::ArrowTipStyle Style::arrowHead() const
+{
+ if (_data->atom("->") || _data->atom("<->") || _data->atom("|->")) return Pointer;
+ if (_data->atom("-|") || _data->atom("<-|") || _data->atom("|-|")) return Flat;
+ return NoTip;
+}
+
+Style::ArrowTipStyle Style::arrowTail() const
+{
+ if (_data->atom("<-") || _data->atom("<->") || _data->atom("<-|")) return Pointer;
+ if (_data->atom("|-") || _data->atom("|->") || _data->atom("|-|")) return Flat;
+ return NoTip;
+}
+
+Style::DrawStyle Style::drawStyle() const
+{
+ if (_data->atom("dashed")) return Dashed;
+ if (_data->atom("dotted")) return Dotted;
+ return Solid;
+}
+
+
+QPen Style::pen() const
+{
+ QPen p(strokeColor());
+ p.setWidthF((float)strokeThickness() * 2.0f);
+
+ QVector<qreal> pat;
+ switch (drawStyle()) {
+ case Dashed:
+ pat << 3.0 << 3.0;
+ p.setDashPattern(pat);
+ break;
+ case Dotted:
+ pat << 1.0 << 1.0;
+ p.setDashPattern(pat);
+ break;
+ case Solid:
+ break;
+ }
+
+ return p;
+}
+
+QPainterPath Style::path() const
+{
+ QPainterPath pth;
+ QString sh = shape();
+
+ if (sh == "rectangle") {
+ pth.addRect(-30.0f, -30.0f, 60.0f, 60.0f);
+ } else { // default is 'circle'
+ pth.addEllipse(QPointF(0.0f,0.0f), 30.0f, 30.0f);
+ }
+ return pth;
+}
+
+QIcon Style::icon() const
+{
+ if (!isEdgeStyle()) {
+ // draw an icon matching the style
+ QImage px(100,100,QImage::Format_ARGB32_Premultiplied);
+ px.fill(Qt::transparent);
+
+
+ QPainter painter(&px);
+ painter.setRenderHint(QPainter::Antialiasing);
+ QPainterPath pth = path();
+ pth.translate(50.0f, 50.0f);
+
+ if (isNone()) {
+ QColor c(180,180,200);
+ painter.setPen(QPen(c));
+ painter.setBrush(QBrush(c));
+ painter.drawEllipse(QPointF(50.0f,50.0f), 3,3);
+
+ QPen pen(QColor(180,180,220));
+ pen.setWidth(3);
+ QVector<qreal> p;
+ p << 2.0 << 2.0;
+ pen.setDashPattern(p);
+ painter.setPen(pen);
+ painter.setBrush(Qt::NoBrush);
+ painter.drawPath(pth);
+ } else {
+ painter.setPen(pen());
+ painter.setBrush(brush());
+ painter.drawPath(pth);
+ }
+
+ return QIcon(QPixmap::fromImage(px));
+ } else {
+ // draw an icon matching the style
+ QPixmap px(100,100);
+ px.fill(Qt::transparent);
+ QPainter painter(&px);
+
+ if (_data == 0) {
+ QPen pen(Qt::black);
+ pen.setWidth(3);
+ } else {
+ painter.setPen(pen());
+ }
+
+ painter.drawLine(10, 50, 90, 50);
+
+ QPen pn = pen();
+ pn.setStyle(Qt::SolidLine);
+ painter.setPen(pn);
+
+ switch (arrowHead()) {
+ case Pointer:
+ painter.drawLine(90,50,80,40);
+ painter.drawLine(90,50,80,60);
+ break;
+ case Flat:
+ painter.drawLine(90,40,90,60);
+ break;
+ case NoTip:
+ break;
+ }
+
+ switch (arrowTail()) {
+ case Pointer:
+ painter.drawLine(10,50,20,40);
+ painter.drawLine(10,50,20,60);
+ break;
+ case Flat:
+ painter.drawLine(10,40,10,60);
+ break;
+ case NoTip:
+ break;
+ }
+
+
+ return QIcon(px);
+ }
+}
+
+QString Style::category() const
+{
+ return propertyWithDefault("tikzit category", "", false);
+}
diff --git a/src/data/style.h b/src/data/style.h
index cef7c7b..ca2e604 100644
--- a/src/data/style.h
+++ b/src/data/style.h
@@ -22,34 +22,53 @@
#include "graphelementdata.h"
+#include <QObject>
#include <QColor>
#include <QPen>
#include <QBrush>
#include <QPainterPath>
#include <QIcon>
-class Style
+class Style : public QObject
{
+ Q_OBJECT
public:
+ enum ArrowTipStyle {
+ Flat, Pointer, NoTip
+ };
+
+ enum DrawStyle {
+ Solid, Dotted, Dashed
+ };
+
Style();
Style(QString name, GraphElementData *data);
- bool isNone();
+ bool isNone() const;
+ bool isEdgeStyle() const;
- // properties that both edges and nodes have
+ // for node and edge styles
GraphElementData *data() const;
QString name() const;
QColor strokeColor(bool tikzitOverride=true) const;
int strokeThickness() const;
-
- // methods that are implemented differently for edges and nodes
- virtual QPen pen() const;
- virtual QPainterPath path() const = 0;
- virtual QPainterPath palettePath() const = 0;
- virtual QIcon icon() const = 0;
+ QPen pen() const;
+ QPainterPath path() const;
+ QIcon icon() const;
void setName(const QString &name);
QString propertyWithDefault(QString prop, QString def, bool tikzitOverride=true) const;
-
QString tikz() const;
+
+ // only relevant for node styles
+ QColor fillColor(bool tikzitOverride=true) const;
+ QBrush brush() const;
+ QString shape(bool tikzitOverride=true) const;
+
+ // only relevant for edge styles
+ Style::ArrowTipStyle arrowHead() const;
+ Style::ArrowTipStyle arrowTail() const;
+ Style::DrawStyle drawStyle() const;
+ QString category() const;
+
protected:
QString _name;
GraphElementData *_data;
diff --git a/src/data/tikzstyles.cpp b/src/data/tikzstyles.cpp
index a827db5..e3a735c 100644
--- a/src/data/tikzstyles.cpp
+++ b/src/data/tikzstyles.cpp
@@ -27,13 +27,14 @@
TikzStyles::TikzStyles(QObject *parent) : QObject(parent)
{
+ _nodeStyles = new NodeStyleList(this);
}
NodeStyle *TikzStyles::nodeStyle(QString name) const
{
- foreach (NodeStyle *s , _nodeStyles)
- if (s->name() == name) return s;
- return unknownStyle;
+ NodeStyle *s = _nodeStyles->style(name);
+
+ return (s == nullptr) ? unknownStyle : s;
}
EdgeStyle *TikzStyles::edgeStyle(QString name) const
@@ -43,14 +44,10 @@ EdgeStyle *TikzStyles::edgeStyle(QString name) const
return noneEdgeStyle;
}
-QVector<NodeStyle *> TikzStyles::nodeStyles() const
-{
- return _nodeStyles;
-}
void TikzStyles::clear()
{
- _nodeStyles.clear();
+ _nodeStyles->clear();
_edgeStyles.clear();
}
@@ -102,7 +99,9 @@ void TikzStyles::refreshModels(QStandardItemModel *nodeModel, QStandardItemModel
it->setSizeHint(QSize(48,48));
}
- foreach(NodeStyle *ns, _nodeStyles) {
+ NodeStyle *ns;
+ for (int i = 0; i < _nodeStyles->length(); ++i) {
+ ns = _nodeStyles->style(i);
if (category == "" || category == ns->propertyWithDefault("tikzit category", "", false))
{
it = new QStandardItem(ns->icon(), ns->name());
@@ -131,16 +130,15 @@ void TikzStyles::refreshModels(QStandardItemModel *nodeModel, QStandardItemModel
}
}
-QVector<EdgeStyle *> TikzStyles::edgeStyles() const
-{
- return _edgeStyles;
-}
-
QStringList TikzStyles::categories() const
{
QMap<QString,bool> cats; // use a QMap to keep keys sorted
cats.insert("", true);
- foreach (NodeStyle *s, _nodeStyles) cats.insert(s->propertyWithDefault("tikzit category", "", false), true);
+ NodeStyle *ns;
+ for (int i = 0; i < _nodeStyles->length(); ++i) {
+ ns = _nodeStyles->style(i);
+ cats.insert(ns->propertyWithDefault("tikzit category", "", false), true);
+ }
//foreach (EdgeStyle *s, _edgeStyles) cats << s->propertyWithDefault("tikzit category", "", false);
return QStringList(cats.keys());
}
@@ -156,10 +154,10 @@ QString TikzStyles::tikz() const
code << "% \\tikzstyle{NAME}=[PROPERTY LIST]\n\n";
code << "% Node styles\n";
- foreach (NodeStyle *s, nodeStyles()) code << s->tikz() << "\n";
+ code << _nodeStyles->tikz();
code << "\n% Edge styles\n";
- foreach (EdgeStyle *s, edgeStyles()) code << s->tikz() << "\n";
+ foreach (EdgeStyle *s, _edgeStyles) code << s->tikz() << "\n";
code.flush();
return str;
@@ -173,7 +171,7 @@ void TikzStyles::addStyle(QString name, GraphElementData *data)
{ // edge style
_edgeStyles << new EdgeStyle(name, data);
} else { // node style
- _nodeStyles << new NodeStyle(name, data);
+ _nodeStyles->addStyle(new NodeStyle(name, data));
}
}
diff --git a/src/data/tikzstyles.h b/src/data/tikzstyles.h
index 558901e..68bd9ce 100644
--- a/src/data/tikzstyles.h
+++ b/src/data/tikzstyles.h
@@ -20,7 +20,7 @@
#define PROJECT_H
#include "graphelementdata.h"
-#include "nodestyle.h"
+#include "nodestylelist.h"
#include "edgestyle.h"
#include <QObject>
@@ -37,8 +37,6 @@ public:
NodeStyle *nodeStyle(QString name) const;
EdgeStyle *edgeStyle(QString name) const;
- QVector<NodeStyle *> nodeStyles() const;
- QVector<EdgeStyle *> edgeStyles() const;
QStringList categories() const;
QString tikz() const;
void clear();
@@ -55,7 +53,7 @@ signals:
public slots:
private:
- QVector<NodeStyle*> _nodeStyles;
+ NodeStyleList *_nodeStyles;
QVector<EdgeStyle*> _edgeStyles;
QStringList _colNames;
QVector<QColor> _cols;
diff --git a/tikzit.pro b/tikzit.pro
index 0cb4c9c..79cb6c6 100644
--- a/tikzit.pro
+++ b/tikzit.pro
@@ -1,111 +1,113 @@
-#-------------------------------------------------
-#
-# Project created by QtCreator 2017-01-11T17:30:16
-#
-#-------------------------------------------------
-
-QT += core gui widgets
-CONFIG += testcase
-
-TARGET = tikzit
-TEMPLATE = app
-
-win32:RC_ICONS += images/tikzit.ico
-win32:RC_ICONS += images/tikzdoc.ico
-
-# The following define makes your compiler emit warnings if you use
-# any feature of Qt which as been marked as deprecated (the exact warnings
-# depend on your compiler). Please consult the documentation of the
-# deprecated API in order to know how to port your code away from it.
-DEFINES += QT_DEPRECATED_WARNINGS
-
-# You can also make your code fail to compile if you use deprecated APIs.
-# In order to do so, uncomment the following line.
-# You can also select to disable deprecated APIs only up to a certain version of Qt.
-#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
-
-FLEXSOURCES = src/data/tikzlexer.l
-BISONSOURCES = src/data/tikzparser.y
-
-include(flex.pri)
-include(bison.pri)
-
-SOURCES += src/gui/mainwindow.cpp \
- src/gui/toolpalette.cpp \
- src/gui/tikzscene.cpp \
- src/data/graph.cpp \
- src/data/node.cpp \
- src/data/edge.cpp \
- src/data/graphelementdata.cpp \
- src/data/graphelementproperty.cpp \
- src/gui/propertypalette.cpp \
- src/gui/tikzview.cpp \
- src/gui/nodeitem.cpp \
- src/gui/edgeitem.cpp \
- src/tikzit.cpp \
- src/data/nodestyle.cpp \
- src/gui/commands.cpp \
- src/data/tikzdocument.cpp \
- src/gui/undocommands.cpp \
- src/gui/mainmenu.cpp \
- src/util.cpp \
- src/gui/stylepalette.cpp \
- src/data/tikzassembler.cpp \
- src/data/tikzstyles.cpp \
- src/data/edgestyle.cpp \
- src/data/style.cpp \
- src/gui/styleeditor.cpp
-
-HEADERS += src/gui/mainwindow.h \
- src/gui/toolpalette.h \
- src/gui/tikzscene.h \
- src/data/graph.h \
- src/data/node.h \
- src/data/edge.h \
- src/data/graphelementdata.h \
- src/data/graphelementproperty.h \
- src/gui/propertypalette.h \
- src/data/tikzparserdefs.h \
- src/gui/tikzview.h \
- src/gui/nodeitem.h \
- src/tikzit.h \
- src/gui/edgeitem.h \
- src/data/nodestyle.h \
- src/gui/commands.h \
- src/data/tikzdocument.h \
- src/gui/undocommands.h \
- src/gui/mainmenu.h \
- src/util.h \
- src/gui/stylepalette.h \
- src/data/tikzassembler.h \
- src/data/tikzstyles.h \
- src/data/edgestyle.h \
- src/data/style.h \
- src/gui/styleeditor.h
-
-FORMS += src/gui/mainwindow.ui \
- src/gui/propertypalette.ui \
- src/gui/mainmenu.ui \
- src/gui/stylepalette.ui \
- src/gui/styleeditor.ui
-
-INCLUDEPATH += src src/gui src/data
-
-DISTFILES +=
-
-RESOURCES += tikzit.qrc
-
-test {
- QT += testlib
- TARGET = UnitTests
- SOURCES -= src/main.cpp
- HEADERS += src/test/testtest.h \
- src/test/testparser.h \
- src/test/testtikzoutput.h
- SOURCES += src/test/testmain.cpp \
- src/test/testtest.cpp \
- src/test/testparser.cpp \
- src/test/testtikzoutput.cpp
-} else {
- SOURCES += src/main.cpp
-}
+#-------------------------------------------------
+#
+# Project created by QtCreator 2017-01-11T17:30:16
+#
+#-------------------------------------------------
+
+QT += core gui widgets
+CONFIG += testcase
+
+TARGET = tikzit
+TEMPLATE = app
+
+win32:RC_ICONS += images/tikzit.ico
+win32:RC_ICONS += images/tikzdoc.ico
+
+# The following define makes your compiler emit warnings if you use
+# any feature of Qt which as been marked as deprecated (the exact warnings
+# depend on your compiler). Please consult the documentation of the
+# deprecated API in order to know how to port your code away from it.
+DEFINES += QT_DEPRECATED_WARNINGS
+
+# You can also make your code fail to compile if you use deprecated APIs.
+# In order to do so, uncomment the following line.
+# You can also select to disable deprecated APIs only up to a certain version of Qt.
+#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
+
+FLEXSOURCES = src/data/tikzlexer.l
+BISONSOURCES = src/data/tikzparser.y
+
+include(flex.pri)
+include(bison.pri)
+
+SOURCES += src/gui/mainwindow.cpp \
+ src/gui/toolpalette.cpp \
+ src/gui/tikzscene.cpp \
+ src/data/graph.cpp \
+ src/data/node.cpp \
+ src/data/edge.cpp \
+ src/data/graphelementdata.cpp \
+ src/data/graphelementproperty.cpp \
+ src/gui/propertypalette.cpp \
+ src/gui/tikzview.cpp \
+ src/gui/nodeitem.cpp \
+ src/gui/edgeitem.cpp \
+ src/tikzit.cpp \
+ src/data/nodestyle.cpp \
+ src/gui/commands.cpp \
+ src/data/tikzdocument.cpp \
+ src/gui/undocommands.cpp \
+ src/gui/mainmenu.cpp \
+ src/util.cpp \
+ src/gui/stylepalette.cpp \
+ src/data/tikzassembler.cpp \
+ src/data/tikzstyles.cpp \
+ src/data/edgestyle.cpp \
+ src/data/style.cpp \
+ src/gui/styleeditor.cpp \
+ src/data/nodestylelist.cpp
+
+HEADERS += src/gui/mainwindow.h \
+ src/gui/toolpalette.h \
+ src/gui/tikzscene.h \
+ src/data/graph.h \
+ src/data/node.h \
+ src/data/edge.h \
+ src/data/graphelementdata.h \
+ src/data/graphelementproperty.h \
+ src/gui/propertypalette.h \
+ src/data/tikzparserdefs.h \
+ src/gui/tikzview.h \
+ src/gui/nodeitem.h \
+ src/tikzit.h \
+ src/gui/edgeitem.h \
+ src/data/nodestyle.h \
+ src/gui/commands.h \
+ src/data/tikzdocument.h \
+ src/gui/undocommands.h \
+ src/gui/mainmenu.h \
+ src/util.h \
+ src/gui/stylepalette.h \
+ src/data/tikzassembler.h \
+ src/data/tikzstyles.h \
+ src/data/edgestyle.h \
+ src/data/style.h \
+ src/gui/styleeditor.h \
+ src/data/nodestylelist.h
+
+FORMS += src/gui/mainwindow.ui \
+ src/gui/propertypalette.ui \
+ src/gui/mainmenu.ui \
+ src/gui/stylepalette.ui \
+ src/gui/styleeditor.ui
+
+INCLUDEPATH += src src/gui src/data
+
+DISTFILES +=
+
+RESOURCES += tikzit.qrc
+
+test {
+ QT += testlib
+ TARGET = UnitTests
+ SOURCES -= src/main.cpp
+ HEADERS += src/test/testtest.h \
+ src/test/testparser.h \
+ src/test/testtikzoutput.h
+ SOURCES += src/test/testmain.cpp \
+ src/test/testtest.cpp \
+ src/test/testparser.cpp \
+ src/test/testtikzoutput.cpp
+} else {
+ SOURCES += src/main.cpp
+}