diff options
author | Aleks Kissinger <aleks0@gmail.com> | 2018-10-09 10:33:08 +0200 |
---|---|---|
committer | Aleks Kissinger <aleks0@gmail.com> | 2018-10-09 10:33:08 +0200 |
commit | 38582ebd4b974150cbe446ac92c9a4a7024f5f09 (patch) | |
tree | 8da4e23b02274e31ae62e2d26e40746ee988c368 /src/data/stylelist.cpp | |
parent | 59f92c45fd751aeb7811ca68d76d3af4ee72a9c4 (diff) |
style editor is finished
Diffstat (limited to 'src/data/stylelist.cpp')
-rw-r--r-- | src/data/stylelist.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
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; |