From: vsv Date: Thu, 29 Nov 2018 15:23:52 +0000 (+0300) Subject: Issue #2806: Provide correct selection with Shift button when Multi selector widget... X-Git-Tag: End2018~131 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=bdf459165e3036046ce0ae3805b2391d569f9340;p=modules%2Fshaper.git Issue #2806: Provide correct selection with Shift button when Multi selector widget is active --- diff --git a/src/ModuleBase/ModuleBase_ISelection.cpp b/src/ModuleBase/ModuleBase_ISelection.cpp index b54f6e4ee..cde321d1e 100644 --- a/src/ModuleBase/ModuleBase_ISelection.cpp +++ b/src/ModuleBase/ModuleBase_ISelection.cpp @@ -34,24 +34,19 @@ void ModuleBase_ISelection::appendSelected(const QList { // collect the objects from the viewer QObjectPtrList anExistedObjects; - QList::const_iterator aPrsIt = theValuesTo.begin(), - aPrsLast = theValuesTo.end(); - for (; aPrsIt != aPrsLast; aPrsIt++) { - if ((*aPrsIt)->owner() && (*aPrsIt)->object()) - anExistedObjects.push_back((*aPrsIt)->object()); + foreach(ModuleBase_ViewerPrsPtr aPrs, theValuesTo) { + if (aPrs->owner() && aPrs->object()) + anExistedObjects.append(aPrs->object()); } - - QList::const_iterator anIt = theValues.begin(), - aLast = theValues.end(); - for (; anIt != aLast; anIt++) { - ObjectPtr anObject = (*anIt)->object(); + ObjectPtr anObject; + foreach(ModuleBase_ViewerPrsPtr aPrs, theValues) { + anObject = aPrs->object(); if (anObject.get() != NULL && !anExistedObjects.contains(anObject)) { theValuesTo.append(std::shared_ptr( new ModuleBase_ViewerPrs(anObject, GeomShapePtr(), NULL))); } } - } //******************************************************************** diff --git a/src/XGUI/XGUI_ModuleConnector.cpp b/src/XGUI/XGUI_ModuleConnector.cpp index 5c67a3d50..0c7dcd6be 100644 --- a/src/XGUI/XGUI_ModuleConnector.cpp +++ b/src/XGUI/XGUI_ModuleConnector.cpp @@ -137,9 +137,7 @@ void XGUI_ModuleConnector::setSelected(const QList& the foreach(ModuleBase_ViewerPrsPtr aVal, theValues) { anObjects.append(aVal->object()); } - bool aBlocked = myWorkshop->objectBrowser()->blockSignals(true); aBrowser->setObjectsSelected(anObjects); - myWorkshop->objectBrowser()->blockSignals(aBlocked); } } diff --git a/src/XGUI/XGUI_ObjectsBrowser.cpp b/src/XGUI/XGUI_ObjectsBrowser.cpp index b08ccc36e..7f28e6f41 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.cpp +++ b/src/XGUI/XGUI_ObjectsBrowser.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #ifdef DEBUG_INDXES #include @@ -533,17 +534,61 @@ void XGUI_ObjectsBrowser::rebuildDataTree() //*************************************************** void XGUI_ObjectsBrowser::setObjectsSelected(const QObjectPtrList& theObjects) { - QList theIndexes; QItemSelectionModel* aSelectModel = myTreeView->selectionModel(); - aSelectModel->clear(); + QModelIndexList aIndexes = aSelectModel->selectedIndexes(); + if (theObjects.size() == 0) { + bool aIsBlock = aSelectModel->blockSignals(true); + aSelectModel->clear(); + aSelectModel->blockSignals(aIsBlock); + foreach(QModelIndex aIdx, aIndexes) { + myTreeView->update(aIdx); + } + return; + } - foreach(ObjectPtr aFeature, theObjects) - { - QModelIndex aIndex = myDocModel->objectIndex(aFeature); - if (aIndex.isValid()) { - aSelectModel->select(aIndex, QItemSelectionModel::Select); + ObjectPtr aObject; + QModelIndexList aUnselect; + QObjectPtrList aToSelect = theObjects; + QHash aNotChanged; + foreach(QModelIndex aIdx, aIndexes) { + aObject = myDocModel->object(aIdx); + if (aObject.get()) { + if (aToSelect.contains(aObject)) { + aNotChanged.insert((qint64)aObject.get(), aObject); + } else { + aUnselect.append(aIdx); + } + } + else { + aUnselect.append(aIdx); } } + + foreach(ObjectPtr aObj, aNotChanged) + aToSelect.removeAll(aObj); + + bool aIsBlock = aSelectModel->blockSignals(true); + foreach(QModelIndex aIdx, aUnselect) { + aSelectModel->select(aIdx, QItemSelectionModel::Deselect); + myTreeView->update(aIdx); + } + + QModelIndex aIndex0, aIndex1, aIndex2, aCurrent; + foreach(ObjectPtr aFeature, aToSelect) { + aIndex1 = myDocModel->objectIndex(aFeature, 1); + if (aIndex1.isValid()) { + if (!aCurrent.isValid()) + aCurrent = aIndex1; + aIndex0 = myDocModel->objectIndex(aFeature, 0); + aIndex2 = myDocModel->objectIndex(aFeature, 2); + aSelectModel->select(aIndex1, QItemSelectionModel::Select | QItemSelectionModel::Rows); + myTreeView->update(aIndex0); + myTreeView->update(aIndex1); + myTreeView->update(aIndex2); + } + } + aSelectModel->setCurrentIndex(aCurrent, QItemSelectionModel::NoUpdate); + aSelectModel->blockSignals(aIsBlock); } //*************************************************** @@ -585,14 +630,14 @@ QObjectPtrList XGUI_ObjectsBrowser::selectedObjects(QModelIndexList* theIndexes) QObjectPtrList aList; QModelIndexList aIndexes = selectedIndexes(); XGUI_DataModel* aModel = dataModel(); - QModelIndexList::const_iterator aIt; - for (aIt = aIndexes.constBegin(); aIt != aIndexes.constEnd(); ++aIt) { - if ((*aIt).column() == 1) { - ObjectPtr aObject = aModel->object(*aIt); + + foreach(QModelIndex aIdx, aIndexes) { + if (aIdx.column() == 1) { + ObjectPtr aObject = aModel->object(aIdx); if (aObject) { aList.append(aObject); if (theIndexes) - theIndexes->append(*aIt); + theIndexes->append(aIdx); } } } diff --git a/src/XGUI/XGUI_SelectionMgr.cpp b/src/XGUI/XGUI_SelectionMgr.cpp index 6ea539481..a4cf3bbcb 100755 --- a/src/XGUI/XGUI_SelectionMgr.cpp +++ b/src/XGUI/XGUI_SelectionMgr.cpp @@ -146,10 +146,7 @@ void XGUI_SelectionMgr::onViewerSelection() QObjectPtrList anObjects; convertToObjectBrowserSelection(aValues, anObjects); - - bool aBlocked = myWorkshop->objectBrowser()->blockSignals(true); myWorkshop->objectBrowser()->setObjectsSelected(anObjects); - myWorkshop->objectBrowser()->blockSignals(aBlocked); emit selectionChanged(); } @@ -191,9 +188,7 @@ void XGUI_SelectionMgr::updateSelectionBy(const ModuleBase_ISelection::Selection void XGUI_SelectionMgr::clearSelection() { QObjectPtrList aFeatures; - bool aBlocked = myWorkshop->objectBrowser()->blockSignals(true); myWorkshop->objectBrowser()->setObjectsSelected(aFeatures); - myWorkshop->objectBrowser()->blockSignals(aBlocked); QList aSelectedPrs = myWorkshop->selector()->selection()->getSelected(ModuleBase_ISelection::Browser); @@ -211,12 +206,9 @@ void XGUI_SelectionMgr::setSelected(const QList& theVal aDisplayer->setSelected(theValues); // update selection in Object Browser - bool aBlocked = myWorkshop->objectBrowser()->blockSignals(true); QObjectPtrList anObjects; convertToObjectBrowserSelection(theValues, anObjects); - myWorkshop->objectBrowser()->setObjectsSelected(anObjects); - myWorkshop->objectBrowser()->blockSignals(aBlocked); } //************************************************************** diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 823d8fe88..e3db137e0 100755 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -171,8 +171,8 @@ QString XGUI_Workshop::MOVE_TO_END_COMMAND = QObject::tr("Move to the end"); //#define DEBUG_CLEAN_HISTORY #ifdef HAVE_SALOME -static QString MyFilter(QObject::tr("OpenParts files (*.shaper *.opp)")); -static QString MyFilter2(QObject::tr("OpenParts files (*.shaper)")); +static QString MyFilter(QObject::tr("SHAPER files (*.shaper *.opp)")); +static QString MyFilter2(QObject::tr("SHAPER files (*.shaper)")); static QString MyExtension(".shaper"); #else static QString MyFilter(QObject::tr("OpenParts files (*.opp);;All files (*.*)")); @@ -2723,9 +2723,7 @@ void XGUI_Workshop::highlightResults(const QObjectPtrList& theObjects) } if (aSelList.count() > theObjects.count()) { // if something was found - bool aBlocked = objectBrowser()->blockSignals(true); objectBrowser()->setObjectsSelected(aSelList); - objectBrowser()->blockSignals(aBlocked); objectBrowser()->ensureVisible(aNewSel.first()); } if (aHasHidden) @@ -2752,9 +2750,7 @@ void XGUI_Workshop::highlightFeature(const QObjectPtrList& theObjects) } if (aSelList.count() > theObjects.count()) { // if something was found - bool aBlocked = objectBrowser()->blockSignals(true); objectBrowser()->setObjectsSelected(aSelList); - objectBrowser()->blockSignals(aBlocked); objectBrowser()->ensureVisible(aNewSel.first()); } }