summaryrefslogtreecommitdiff
path: root/src/data
diff options
context:
space:
mode:
authorAleks Kissinger <aleks0@gmail.com>2018-10-09 10:33:08 +0200
committerAleks Kissinger <aleks0@gmail.com>2018-10-09 10:33:08 +0200
commit38582ebd4b974150cbe446ac92c9a4a7024f5f09 (patch)
tree8da4e23b02274e31ae62e2d26e40746ee988c368 /src/data
parent59f92c45fd751aeb7811ca68d76d3af4ee72a9c4 (diff)
style editor is finished
Diffstat (limited to 'src/data')
-rw-r--r--src/data/stylelist.cpp35
-rw-r--r--src/data/stylelist.h6
2 files changed, 41 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;
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;