From e0f973435c6cf24f4eefc9f767b8b6a957daf8ac Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Mon, 8 Oct 2018 08:51:13 +0200 Subject: fixed tikzstyles output --- src/data/stylelist.cpp | 3 ++- src/gui/styleeditor.cpp | 68 +++++++++++++++++++++++++++++++++++-------------- src/gui/styleeditor.h | 1 + 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 -- cgit v1.2.3