diff options
author | Arno <am@disconnect.de> | 2012-03-02 20:08:40 +0100 |
---|---|---|
committer | Arno <am@disconnect.de> | 2012-03-02 20:08:40 +0100 |
commit | ee29bb41dc9c4d4dd6fc9bfd3fb9ad5cc3bd1569 (patch) | |
tree | 4801c4b23215259cec9620a32593c656fdfd8ede /smtreemodel.cpp | |
parent | 11bf52b6cf1c27a75715a8379e7893b8d1e16bf0 (diff) | |
download | SheMov-ee29bb41dc9c4d4dd6fc9bfd3fb9ad5cc3bd1569.tar.gz SheMov-ee29bb41dc9c4d4dd6fc9bfd3fb9ad5cc3bd1569.tar.bz2 SheMov-ee29bb41dc9c4d4dd6fc9bfd3fb9ad5cc3bd1569.zip |
Make it possible to move mappings
Move mappings by context menu. Select new parent by QComboBox with
available paths, items separated by "/". Note that hell will break loose
if a mapping name contains "/". Will be fixed later.
Since mapping views don't have setSortingEnabled(), make
SmTreeModel::addRow() sort items.
This fixes a long standing bug in SmTreeModel::reparent(): Since it
alters the model, newParent has to be a QPersistentModelIndex to stay
consistent.
Diffstat (limited to 'smtreemodel.cpp')
-rw-r--r-- | smtreemodel.cpp | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/smtreemodel.cpp b/smtreemodel.cpp index 98e7e45..802eebc 100644 --- a/smtreemodel.cpp +++ b/smtreemodel.cpp @@ -185,7 +185,7 @@ SmTreeItem *SmTreeModel::parentItem(const QModelIndex &child) const{ return static_cast<SmTreeItem*>(child.parent().internalPointer()); } -void SmTreeModel::reparent(const QModelIndex &idx, const QModelIndex &newParent){ +void SmTreeModel::reparent(const QModelIndex &idx, const QModelIndex &newParent, bool sorted){ if(!idx.isValid()){ return; } @@ -194,8 +194,9 @@ void SmTreeModel::reparent(const QModelIndex &idx, const QModelIndex &newParent) for(int i = 0; i < item->columnCount(); ++i){ data << item->data(i); } + QPersistentModelIndex pNewParent = newParent; removeRows(idx.row(), 1, idx.parent()); - addRow(data, newParent); + addRow(data, pNewParent, sorted); } bool SmTreeModel::insertRows(int row, int count, const QModelIndex &parent){ @@ -231,15 +232,24 @@ bool SmTreeModel::removeRows(int row, int count, const QModelIndex &parent){ return retval; } -bool SmTreeModel::addRow(const QList<QVariant> &data, const QModelIndex &parent){ +bool SmTreeModel::addRow(const QList<QVariant> &data, const QModelIndex &parent, bool sorted){ if(data.count() != mRootItem->columnCount()){ return false; } SmTreeItem *parentItem = itemAt(parent); + int where = 0; + if(sorted){ + for(int i = 0; i < parentItem->childCount(); ++i){ + if(parentItem->child(i)->data(0).toString() > data.at(0).toString()){ + where = i; + break; + } + } + } - if(insertRows(parentItem->childCount(), 1, parent)){ - SmTreeItem *child = parentItem->child(parentItem->childCount() - 1); + if(insertRows(where, 1, parent)){ + SmTreeItem *child = parentItem->child(where); for(int i = 0; i < data.count(); ++i){ child->setData(i, data.at(i)); } |