From 55a6c39c2a676f0885bbc88003491f92252ea36a Mon Sep 17 00:00:00 2001 From: Yumin Yuan Date: Mon, 20 Apr 2015 12:42:45 -0400 Subject: [PATCH] Added logic to make sure newly created indices are visible --- smtk/extension/qt/qtEntityItemModel.cxx | 12 +++++++++--- smtk/extension/qt/qtEntityItemModel.h | 1 + smtk/extension/qt/qtModelView.cxx | 11 +++++++++++ smtk/extension/qt/qtModelView.h | 1 + 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/smtk/extension/qt/qtEntityItemModel.cxx b/smtk/extension/qt/qtEntityItemModel.cxx index 1ebd569ff9..7828f6cc0a 100644 --- a/smtk/extension/qt/qtEntityItemModel.cxx +++ b/smtk/extension/qt/qtEntityItemModel.cxx @@ -146,7 +146,7 @@ QModelIndex QEntityItemModel::index(int row, int column, const QModelIndex& owne DescriptivePhrasePtr ownerPhrase = this->getItem(owner); std::string entName = ownerPhrase->relatedEntity().name(); - std::cout << "Owner index for: " << entName << std::endl; +// std::cout << "Owner index for: " << entName << std::endl; DescriptivePhrases& subphrases(ownerPhrase->subphrases()); if (row >= 0 && row < static_cast(subphrases.size())) { @@ -696,7 +696,7 @@ inline void _internal_findAllExistingPhrases( if (modEnts->has((*it)->relatedEntity())) { modifiedPhrases.push_back(*it); - return; // stop searching siblings + continue; // skip Descending } // Descend @@ -779,7 +779,13 @@ void QEntityItemModel::addChildPhrases( } else */ - emit dataChanged(qidx, qidx); + emit dataChanged(qidx, qidx); + if(newDphrs.size() > 0) + { + QModelIndex lastnewChild = qidx.child(row, 0); + // give view an opportunity to scroll to the new child + emit newIndexAdded(lastnewChild); + } } void QEntityItemModel::removeChildPhrases( diff --git a/smtk/extension/qt/qtEntityItemModel.h b/smtk/extension/qt/qtEntityItemModel.h index 31230daa25..f5cc47cd45 100644 --- a/smtk/extension/qt/qtEntityItemModel.h +++ b/smtk/extension/qt/qtEntityItemModel.h @@ -114,6 +114,7 @@ class QTSMTK_EXPORT QEntityItemModel : public QAbstractItemModel signals: void phraseTitleChanged(const QModelIndex&); + void newIndexAdded(const QModelIndex & newidx); protected: smtk::model::DescriptivePhrasePtr m_root; diff --git a/smtk/extension/qt/qtModelView.cxx b/smtk/extension/qt/qtModelView.cxx index 9de2daa256..6376d575b9 100644 --- a/smtk/extension/qt/qtModelView.cxx +++ b/smtk/extension/qt/qtModelView.cxx @@ -106,6 +106,9 @@ qtModelView::qtModelView(QWidget* p) QObject::connect(qmodel, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), this, SLOT(dataChanged(const QModelIndex&, const QModelIndex&)), Qt::QueuedConnection); + QObject::connect(qmodel, + SIGNAL(newIndexAdded(const QModelIndex&)), + this, SLOT(newIndexAdded(const QModelIndex&)), Qt::QueuedConnection); } @@ -361,6 +364,14 @@ void qtModelView::selectionChanged ( emit this->entitiesSelected(selentityrefs); } +//----------------------------------------------------------------------------- +// when the dataChanged is emitted from the model, we want to scroll to +// that index so that the changes are visible in the tree view. +void qtModelView::newIndexAdded(const QModelIndex & newidx) +{ + this->scrollTo(newidx); +} + //---------------------------------------------------------------------------- void qtModelView::recursiveSelect (smtk::model::DescriptivePhrasePtr dPhrase, smtk::model::EntityRefs& selentityrefs, BitFlags entityFlags, diff --git a/smtk/extension/qt/qtModelView.h b/smtk/extension/qt/qtModelView.h index 6ef8f697cb..604bdfe588 100644 --- a/smtk/extension/qt/qtModelView.h +++ b/smtk/extension/qt/qtModelView.h @@ -101,6 +101,7 @@ protected slots: const smtk::model::SessionRef& session, const smtk::model::Group& grp, const smtk::model::EntityRefs& entities); + virtual void newIndexAdded(const QModelIndex & newidx); protected: // If 'Delete' button is pressed, invoke proper operation if possible.