summaryrefslogtreecommitdiffstats
path: root/mappingtreewidget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'mappingtreewidget.cpp')
-rw-r--r--mappingtreewidget.cpp15
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);
+ }
}
}
}