summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleks Kissinger <aleks0@gmail.com>2018-10-08 08:51:13 +0200
committerAleks Kissinger <aleks0@gmail.com>2018-10-08 08:51:13 +0200
commite0f973435c6cf24f4eefc9f767b8b6a957daf8ac (patch)
tree6629fcaf78c8319f695b6dc6aff3a1c564bd0cac
parent07c9d67859248840bba0a178aab0dff4306c01c4 (diff)
fixed tikzstyles output
-rw-r--r--src/data/stylelist.cpp3
-rw-r--r--src/gui/styleeditor.cpp68
-rw-r--r--src/gui/styleeditor.h1
3 files changed, 52 insertions, 20 deletions
diff --git a/src/data/stylelist.cpp b/src/data/stylelist.cpp
index 2c79d10..c8baf3f 100644
--- a/src/data/stylelist.cpp
+++ b/src/data/stylelist.cpp
@@ -63,7 +63,8 @@ QString StyleList::tikz()
{
QString str;
QTextStream code(&str);
- foreach (Style *s, _styles) code << s->tikz() << "\n";
+ for (int i = 1; i < _styles.length(); ++i)
+ code << _styles[i]->tikz() << "\n";
code.flush();
return str;
}
diff --git a/src/gui/styleeditor.cpp b/src/gui/styleeditor.cpp
index e3f8ace..06bb718 100644
--- a/src/gui/styleeditor.cpp
+++ b/src/gui/styleeditor.cpp
@@ -19,6 +19,7 @@ StyleEditor::StyleEditor(QWidget *parent) :
ui->properties;
_styles = nullptr;
+ _activeStyle = nullptr;
ui->styleListView->setViewMode(QListView::IconMode);
ui->styleListView->setMovement(QListView::Static);
@@ -80,6 +81,7 @@ StyleEditor::~StyleEditor()
void StyleEditor::open() {
if (_styles != nullptr) delete _styles;
_styles = new TikzStyles;
+ _activeStyle = nullptr;
ui->styleListView->setModel(_styles->nodeStyles());
ui->edgeStyleListView->setModel(_styles->edgeStyles());
connect(ui->styleListView->selectionModel(),
@@ -127,8 +129,7 @@ void StyleEditor::nodeItemChanged(QModelIndex sel)
{
if (sel.isValid()) {
ui->edgeStyleListView->selectionModel()->clear();
- qDebug() << "active style:" << ((activeStyle() == nullptr) ? "null" : activeStyle()->tikz());
- qDebug() << "style from index:" << _styles->nodeStyles()->styleInCategory(sel.row())->tikz();
+ _activeStyle = _styles->nodeStyles()->styleInCategory(sel.row());
}
_nodeStyleIndex = sel;
refreshDisplay();
@@ -138,7 +139,7 @@ void StyleEditor::edgeItemChanged(QModelIndex sel)
{
if (sel.isValid()) {
ui->styleListView->selectionModel()->clear();
- //_nodeStyleIndex = QModelIndex();
+ _activeStyle = _styles->edgeStyles()->styleInCategory(sel.row());
}
_edgeStyleIndex = sel;
refreshDisplay();
@@ -150,17 +151,43 @@ void StyleEditor::categoryChanged()
QString cat = ui->category->currentText();
//qDebug() << "got category: " << cat;
- if (s != 0 && s->data()->property("tikzit category") != cat) {
+ if (s != nullptr && s->data()->property("tikzit category") != cat) {
if (cat.isEmpty()) s->data()->unsetProperty("tikzit category");
else s->data()->setProperty("tikzit category", cat);
_dirty = true;
refreshCategories();
- refreshDisplay();
+
+ if (_styles->nodeStyles()->category() != "") {
+ ui->currentCategory->setCurrentText(cat);
+ //qDebug() << "after cat change, cat reports:" << _styles->nodeStyles()->category();
+ }
+ //refreshDisplay();
}
}
void StyleEditor::currentCategoryChanged()
{
+ if (_styles != nullptr) {
+ QString cat = ui->currentCategory->currentText();
+ qDebug() << "got category:" << cat;
+ qDebug() << "node style category:" << _styles->nodeStyles()->category();
+ if (cat != _styles->nodeStyles()->category()) {
+ ui->styleListView->selectionModel()->clear();
+ _styles->nodeStyles()->setCategory(cat);
+
+ if (_activeStyle != nullptr && !_activeStyle->isEdgeStyle()) {
+ for (int i = 0; i < _styles->nodeStyles()->numInCategory(); ++i) {
+ if (_styles->nodeStyles()->styleInCategory(i) == _activeStyle) {
+ ui->styleListView->selectionModel()->setCurrentIndex(
+ _styles->nodeStyles()->index(i),
+ QItemSelectionModel::ClearAndSelect);
+ break;
+ }
+ }
+ if (!_nodeStyleIndex.isValid()) _activeStyle = nullptr;
+ }
+ }
+ }
}
void StyleEditor::refreshCategories()
@@ -187,13 +214,16 @@ void StyleEditor::refreshCategories()
void StyleEditor::propertyChanged()
{
- QModelIndexList nSel = ui->styleListView->selectionModel()->selectedRows();
- QModelIndexList eSel = ui->edgeStyleListView->selectionModel()->selectedRows();
- if (!nSel.isEmpty()) {
- emit _styles->nodeStyles()->dataChanged(nSel[0], nSel[0]);
- refreshCategories();
- } else if (!eSel.isEmpty()) {
- emit _styles->edgeStyles()->dataChanged(eSel[0], eSel[0]);
+ if (_nodeStyleIndex.isValid()) {
+ emit _styles->nodeStyles()->dataChanged(_nodeStyleIndex, _nodeStyleIndex);
+
+ if (_activeStyle->category() != _styles->nodeStyles()->category()) {
+ refreshCategories();
+ if (_styles->nodeStyles()->category() != "")
+ ui->currentCategory->setCurrentText(_activeStyle->category());
+ }
+ } else if (_edgeStyleIndex.isValid()) {
+ emit _styles->edgeStyles()->dataChanged(_edgeStyleIndex, _edgeStyleIndex);
}
_dirty = true;
refreshDisplay();
@@ -496,15 +526,15 @@ QColor StyleEditor::color(QPushButton *btn)
Style *StyleEditor::activeStyle()
{
- if (_styles != nullptr) {
- if (_nodeStyleIndex.isValid())
- return _styles->nodeStyles()->styleInCategory(_nodeStyleIndex.row());
+// if (_styles != nullptr) {
+// if (_nodeStyleIndex.isValid())
+// return _styles->nodeStyles()->styleInCategory(_nodeStyleIndex.row());
- if (_edgeStyleIndex.isValid())
- return _styles->edgeStyles()->styleInCategory(_edgeStyleIndex.row());
- }
+// if (_edgeStyleIndex.isValid())
+// return _styles->edgeStyles()->styleInCategory(_edgeStyleIndex.row());
+// }
- return nullptr;
+ return _activeStyle;
}
void StyleEditor::refreshActiveStyle()
diff --git a/src/gui/styleeditor.h b/src/gui/styleeditor.h
index fed2908..f9caf9c 100644
--- a/src/gui/styleeditor.h
+++ b/src/gui/styleeditor.h
@@ -68,6 +68,7 @@ private:
QModelIndex _nodeStyleIndex;
QModelIndex _edgeStyleIndex;
+ Style *_activeStyle;
};
#endif // STYLEEDITOR_H