summaryrefslogtreecommitdiff
path: root/lsscenemodel.cpp
diff options
context:
space:
mode:
authorTreeki <treeki@gmail.com>2012-08-12 19:27:08 +0200
committerTreeki <treeki@gmail.com>2012-08-12 19:27:08 +0200
commit86b4b22662426cc0127620de1e6451f1a2e1da79 (patch)
tree8d5b88f095db7b7b5fd4815d52cc4f74e755b40b /lsscenemodel.cpp
parent14664da8230d9e76aa5cdafc80c4f5be273a1ea1 (diff)
downloadLayoutStudio-86b4b22662426cc0127620de1e6451f1a2e1da79.tar.gz
LayoutStudio-86b4b22662426cc0127620de1e6451f1a2e1da79.zip
moving multiple panes at the same time..hope this works
Diffstat (limited to '')
-rw-r--r--lsscenemodel.cpp50
1 files changed, 29 insertions, 21 deletions
diff --git a/lsscenemodel.cpp b/lsscenemodel.cpp
index 48b32bd..f5c4ba3 100644
--- a/lsscenemodel.cpp
+++ b/lsscenemodel.cpp
@@ -105,11 +105,6 @@ Qt::DropActions LSSceneModel::supportedDropActions() const {
bool LSSceneModel::insertRows(int row, int count, const QModelIndex &parent) {
qDebug("LSSceneModel::insertRows(%d, %d, something)", row, count);
- if (count != 1) {
- qWarning("huh, what? count != 1");
- return false;
- }
-
if (m_movingPaneParent) {
qWarning("huh, already moving something? dunno");
return false;
@@ -117,6 +112,7 @@ bool LSSceneModel::insertRows(int row, int count, const QModelIndex &parent) {
m_movingPaneParent = new QPersistentModelIndex(parent);
m_movingPaneRow = row;
+ m_movingPaneCount = count;
return true;
}
@@ -124,24 +120,25 @@ bool LSSceneModel::insertRows(int row, int count, const QModelIndex &parent) {
bool LSSceneModel::removeRows(int row, int count, const QModelIndex &parent) {
qDebug("LSSceneModel::removeRows(%d, %d, something)", row, count);
- if (count != 1) {
- qWarning("huh, what? count != 1");
- return false;
- }
-
if (!m_movingPaneParent) {
- qWarning("huh, not moving anything? dunno");
+ qWarning("huh, not moving anything / nothing left to move? dunno");
return false;
}
+ // detach all the existing panes
LYTPane *parentPane = (LYTPane*)parent.internalPointer();
- LYTPane *pane = parentPane->children.at(row);
- beginRemoveRows(parent, row, row);
- parentPane->children.removeAt(row);
+ QVector<LYTPane *> removingPanes;
+ removingPanes.reserve(count);
+
+ beginRemoveRows(parent, row, row + count - 1);
+ for (int i = 0; i < count; i++) {
+ removingPanes.append(parentPane->children.at(row));
+ parentPane->children.removeAt(row);
+ }
endRemoveRows();
- // now add it!
+ // now add them in their new homes!
LYTPane *newParentPane = (LYTPane*)m_movingPaneParent->internalPointer();
// note: compensate for the offset: if we're moving the thing within the
@@ -149,17 +146,28 @@ bool LSSceneModel::removeRows(int row, int count, const QModelIndex &parent) {
// removing the source row will have changed the index of the row the user
// actually wanted to move the moved row to... what a terrible sentence :|
if (*m_movingPaneParent == parent && m_movingPaneRow > row)
- m_movingPaneRow--;
+ m_movingPaneRow -= count;
+
+ beginInsertRows(*m_movingPaneParent, m_movingPaneRow, m_movingPaneRow + count - 1);
- beginInsertRows(*m_movingPaneParent, m_movingPaneRow, m_movingPaneRow);
+ for (int i = 0; i < count; i++) {
+ LYTPane *pane = removingPanes.at(i);
- pane->parent = newParentPane;
- newParentPane->children.insert(m_movingPaneRow, pane);
+ pane->parent = newParentPane;
+ newParentPane->children.insert(m_movingPaneRow, pane);
+
+ m_movingPaneRow++;
+ }
endInsertRows();
- delete m_movingPaneParent;
- m_movingPaneParent = 0;
+ // clean up if needed
+ m_movingPaneCount -= count;
+
+ if (m_movingPaneCount <= 0) {
+ delete m_movingPaneParent;
+ m_movingPaneParent = 0;
+ }
return true;
}