diff options
author | Arno <am@disconnect.de> | 2014-07-07 06:30:04 +0200 |
---|---|---|
committer | Arno <am@disconnect.de> | 2014-07-07 06:30:04 +0200 |
commit | ca9cdb39a8b3eafa8106fed84cce013f18b0a114 (patch) | |
tree | ac96da1937a7f565ab6915c8c82334a530a883c9 | |
parent | f295cfb8672d97bb5c804499bdb311a9a0d8039b (diff) | |
download | SheMov-ca9cdb39a8b3eafa8106fed84cce013f18b0a114.tar.gz SheMov-ca9cdb39a8b3eafa8106fed84cce013f18b0a114.tar.bz2 SheMov-ca9cdb39a8b3eafa8106fed84cce013f18b0a114.zip |
Fix MappinTreeWidget::addChild
Fix the lookup of a new child, so it will select the right child if we
have more than one child with the same name. Do it by looking up the id
instead of the name.
-rw-r--r-- | mappingtreewidget.cpp | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/mappingtreewidget.cpp b/mappingtreewidget.cpp index c2da053..be0c5a5 100644 --- a/mappingtreewidget.cpp +++ b/mappingtreewidget.cpp @@ -135,17 +135,20 @@ void MappingTreeWidget::addChild(){ QModelIndex sel = selected(); parent = mProxy->mapToSource(sel); } + int parentId = parent.data(MappingTreeModel::MappingIdRole).toInt(); if(!mModel->addChild(value, parent)){ QString err = QString(tr("<p>Failed to create child! Database said:</p><p>%1</p>")).arg(mModel->lastError().text()); QMessageBox::critical(this, tr("Error"), err); }else{ // we repopulated the model, so all indexes are invalid! - // this will fail if we have 2 children with the same name... :( - QModelIndex newSIdx = mModel->findRecursive(value, 0, mModel->rootIndex()); - if(newSIdx.isValid()){ - QModelIndex newPIdx = mProxy->mapFromSource(newSIdx); - mTree->scrollTo(newPIdx, QAbstractItemView::EnsureVisible); - mTree->selectionModel()->setCurrentIndex(newPIdx, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Current | QItemSelectionModel::Rows); + QModelIndex newPIdx = mModel->findRecursive(parentId, MappingTreeModel::MappingId, mModel->rootIndex()); + if(newPIdx.isValid()){ + QModelIndex newSIdx = mModel->find(value, MappingTreeModel::Name, newPIdx); + if(newSIdx.isValid()){ + QModelIndex newSIdxP = mProxy->mapFromSource(newSIdx); + mTree->scrollTo(newSIdxP, QAbstractItemView::EnsureVisible); + mTree->selectionModel()->setCurrentIndex(newSIdxP, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Current | QItemSelectionModel::Rows); + } } } } |