From 38582ebd4b974150cbe446ac92c9a4a7024f5f09 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Tue, 9 Oct 2018 10:33:08 +0200 Subject: style editor is finished --- src/data/stylelist.cpp | 35 +++++++++++++++++++++++++++++++++++ src/data/stylelist.h | 6 ++++++ 2 files changed, 41 insertions(+) (limited to 'src/data') diff --git a/src/data/stylelist.cpp b/src/data/stylelist.cpp index c8baf3f..14302c7 100644 --- a/src/data/stylelist.cpp +++ b/src/data/stylelist.cpp @@ -41,6 +41,13 @@ void StyleList::addStyle(Style *s) } } +void StyleList::removeNthStyle(int n) +{ + beginRemoveRows(QModelIndex(), n, n); + _styles.remove(nthInCategory(n)); + endRemoveRows(); +} + void StyleList::clear() { int n = numInCategory(); @@ -113,6 +120,34 @@ int StyleList::rowCount(const QModelIndex &/*parent*/) const return numInCategory(); } +bool StyleList::moveRows(const QModelIndex &sourceParent, + int sourceRow, + int /*count*/, + const QModelIndex &destinationParent, + int destinationRow) +{ + if (sourceRow >= 1 && sourceRow < numInCategory() && + destinationRow >= 1 && destinationRow <= numInCategory()) + { + beginMoveRows(sourceParent, sourceRow, sourceRow, destinationParent, destinationRow); + int sourceIndex = nthInCategory(sourceRow); + int destinationIndex = nthInCategory(destinationRow); + if (destinationIndex == -1) + destinationIndex = _styles.length(); + Style *s = _styles[sourceIndex]; + _styles.remove(sourceIndex); + if (sourceIndex < destinationIndex) { + _styles.insert(destinationIndex - 1, s); + } else { + _styles.insert(destinationIndex, s); + } + endMoveRows(); + return true; + } else { + return false; + } +} + QString StyleList::category() const { return _category; diff --git a/src/data/stylelist.h b/src/data/stylelist.h index f698761..eb1c43a 100644 --- a/src/data/stylelist.h +++ b/src/data/stylelist.h @@ -14,6 +14,7 @@ public: Style *style(int i); int length() const; void addStyle(Style *s); + void removeNthStyle(int n); void clear(); QString tikz(); @@ -23,6 +24,11 @@ public: QVariant data(const QModelIndex &index, int role) const override; int rowCount(const QModelIndex &/*parent*/) const override; + bool moveRows(const QModelIndex &sourceParent, + int sourceRow, + int /*count*/, + const QModelIndex &destinationParent, + int destinationChild); QString category() const; -- cgit v1.2.3