From f085393232f29237e7d6bfb1469d77a78e4a511a Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Mon, 1 Oct 2018 17:46:11 +0200 Subject: moving properties up and down --- src/data/graphelementdata.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/data/graphelementdata.cpp') diff --git a/src/data/graphelementdata.cpp b/src/data/graphelementdata.cpp index 25ba08e..b478842 100644 --- a/src/data/graphelementdata.cpp +++ b/src/data/graphelementdata.cpp @@ -110,6 +110,42 @@ int GraphElementData::indexOfKey(QString key) return -1; } +bool GraphElementData::removeRows(int row, int /*count*/, const QModelIndex &parent) +{ + if (row >= 0 && row < _properties.length()) { + beginRemoveRows(parent, row, row+1); + _properties.remove(row); + endRemoveRows(); + return true; + } else { + return false; + } +} + +bool GraphElementData::moveRows(const QModelIndex &sourceParent, + int sourceRow, + int /*count*/, + const QModelIndex &destinationParent, + int destinationRow) +{ + if (sourceRow >= 0 && sourceRow < _properties.length() && + destinationRow >= 0 && destinationRow <= _properties.length()) + { + beginMoveRows(sourceParent, sourceRow, sourceRow, destinationParent, destinationRow); + GraphElementProperty p = _properties[sourceRow]; + _properties.remove(sourceRow); + if (sourceRow < destinationRow) { + _properties.insert(destinationRow - 1, p); + } else { + _properties.insert(destinationRow, p); + } + endMoveRows(); + return true; + } else { + return false; + } +} + QVariant GraphElementData::data(const QModelIndex &index, int role) const { if (role == Qt::DisplayRole || role == Qt::EditRole) { -- cgit v1.2.3