From ee29bb41dc9c4d4dd6fc9bfd3fb9ad5cc3bd1569 Mon Sep 17 00:00:00 2001 From: Arno Date: Fri, 2 Mar 2012 20:08:40 +0100 Subject: 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. --- mappingtreewidget.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'mappingtreewidget.cpp') diff --git a/mappingtreewidget.cpp b/mappingtreewidget.cpp index 6108ebe..41aa6e2 100644 --- a/mappingtreewidget.cpp +++ b/mappingtreewidget.cpp @@ -84,6 +84,9 @@ MappingTreeWidget::MappingTreeWidget(QWidget *parent) : QWidget(parent){ mEditChildA = new QAction(tr("Edit..."), this); connect(mEditChildA, SIGNAL(triggered()), this, SLOT(editChild())); mTree->addAction(mEditChildA); + mMoveChildA = new QAction(tr("Move..."), this); + connect(mMoveChildA, SIGNAL(triggered()), this, SLOT(moveChild())); + mTree->addAction(mMoveChildA); //widget layout and tab order QVBoxLayout *mainLayout = new QVBoxLayout; @@ -216,6 +219,22 @@ void MappingTreeWidget::selectionChanged(){ emit mappingChanged(real.data(MappingTreeModel::IdRole).toInt()); } +void MappingTreeWidget::moveChild(){ + QString path = QInputDialog::getItem(this, tr("Move item"), tr("Move to:"), mModel->paths(), -1, false); + if(!path.isEmpty()){ + QModelIndex sel = selected(); + QModelIndex realSource = mProxy->mapToSource(sel); + QModelIndex dest = mModel->indexFromPath(path); + if(dest == realSource){ + QMessageBox::critical(this, tr("Error"), tr("Destination cannot be the source!")); + return; + } + if(realSource.isValid() && dest.isValid()){ + mModel->move(realSource, dest); + } + } +} + const QModelIndex MappingTreeWidget::selected() const{ QModelIndexList sel = mTree->selectionModel()->selectedRows(); if(sel.isEmpty()){ -- cgit v1.2.3-70-g09d2