diff options
author | Arno <am@disconnect.de> | 2012-10-10 19:56:12 +0200 |
---|---|---|
committer | Arno <am@disconnect.de> | 2012-10-10 19:56:12 +0200 |
commit | b185254de61a7b6497d480339a9a38ff94a2cd87 (patch) | |
tree | 3ca715f66b4abe5d08fa6a7ed0c55eed0ea7fb71 | |
parent | dab3f05dcb2975c07247e3bebd8e9a7e8b9e83ce (diff) | |
download | SheMov-b185254de61a7b6497d480339a9a38ff94a2cd87.tar.gz SheMov-b185254de61a7b6497d480339a9a38ff94a2cd87.tar.bz2 SheMov-b185254de61a7b6497d480339a9a38ff94a2cd87.zip |
Usability: MappingTreeWidget
Try to select newly added mapping. Only try, because it will fail if we
have two children with the same name. The first will win.
-rw-r--r-- | mappingtreewidget.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/mappingtreewidget.cpp b/mappingtreewidget.cpp index 0951312..305bb41 100644 --- a/mappingtreewidget.cpp +++ b/mappingtreewidget.cpp @@ -42,6 +42,7 @@ MappingTreeWidget::MappingTreeWidget(QWidget *parent) : QWidget(parent){ mTree->setColumnHidden(1, true); mTree->setColumnHidden(2, true); mTree->setColumnHidden(3, true); + mTree->setColumnHidden(4, true); mTree->setAlternatingRowColors(true); mTree->expandAll(); connect(mModel, SIGNAL(needExpansion()), mTree, SLOT(expandAll())); @@ -119,15 +120,23 @@ void MappingTreeWidget::addChild(){ QMessageBox::critical(this, tr("Error"), msg); return; } - QModelIndex sel = selected(); QModelIndex parent = mModel->rootIndex(); if(!dlg.createRoot()){ QModelIndex sel = selected(); parent = mProxy->mapToSource(sel); } if(!mModel->addChild(value, parent)){ - QString err = QString(tr("Error: Database said: %1")).arg(mModel->lastError().text()); + 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); + } } } |