From 6359b28b155355e0be67961cc21eccdbd2c61cc2 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Sat, 6 Oct 2018 15:49:50 +0200 Subject: unified node and edge syles --- src/data/edgestyle.cpp | 210 ++++++++++++++++++++++----------------------- src/data/edgestyle.h | 32 +++---- src/data/nodestyle.cpp | 145 ++++++++++++++++--------------- src/data/nodestyle.h | 13 +-- src/data/nodestylelist.cpp | 113 ++++++++++++++++++++++++ src/data/nodestylelist.h | 40 +++++++++ src/data/style.cpp | 182 +++++++++++++++++++++++++++++++++++++-- src/data/style.h | 39 ++++++--- src/data/tikzstyles.cpp | 34 ++++---- src/data/tikzstyles.h | 6 +- 10 files changed, 576 insertions(+), 238 deletions(-) create mode 100644 src/data/nodestylelist.cpp create mode 100644 src/data/nodestylelist.h (limited to 'src/data') 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 #include -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 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 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 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 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 + +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 + +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 _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 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 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 #include #include #include #include #include -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 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 TikzStyles::edgeStyles() const -{ - return _edgeStyles; -} - QStringList TikzStyles::categories() const { QMap 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 @@ -37,8 +37,6 @@ public: NodeStyle *nodeStyle(QString name) const; EdgeStyle *edgeStyle(QString name) const; - QVector nodeStyles() const; - QVector edgeStyles() const; QStringList categories() const; QString tikz() const; void clear(); @@ -55,7 +53,7 @@ signals: public slots: private: - QVector _nodeStyles; + NodeStyleList *_nodeStyles; QVector _edgeStyles; QStringList _colNames; QVector _cols; -- cgit v1.2.3