From fed43d1e0bbd617580196c6038bb02206529f359 Mon Sep 17 00:00:00 2001 From: vsv Date: Thu, 31 Jul 2014 16:44:20 +0400 Subject: [PATCH] Process multi-selection in pop-up menu --- src/XGUI/XGUI_ContextMenuMgr.cpp | 62 ++++++++++++++++++-------------- src/XGUI/XGUI_ObjectsBrowser.cpp | 2 ++ 2 files changed, 38 insertions(+), 26 deletions(-) diff --git a/src/XGUI/XGUI_ContextMenuMgr.cpp b/src/XGUI/XGUI_ContextMenuMgr.cpp index 6891d57da..e699b4a2a 100644 --- a/src/XGUI/XGUI_ContextMenuMgr.cpp +++ b/src/XGUI/XGUI_ContextMenuMgr.cpp @@ -101,40 +101,50 @@ QMenu* XGUI_ContextMenuMgr::objectBrowserMenu() const QMenu* aMenu = new QMenu(); XGUI_SelectionMgr* aSelMgr = myWorkshop->selector(); QList aObjects = aSelMgr->selection()->selectedObjects(); - if (aObjects.size() == 1) { + int aSelected = aObjects.size(); + if (aSelected > 0) { PluginManagerPtr aMgr = ModelAPI_PluginManager::get(); - ObjectPtr aObject = aObjects.first(); + XGUI_Displayer* aDisplayer = myWorkshop->displayer(); //Process Feature - if (aObject) { - ResultPartPtr aPart = boost::dynamic_pointer_cast(aObject); - if (aPart) { - if (aMgr->currentDocument() == aPart->partDoc()) - aMenu->addAction(action("DEACTIVATE_PART_CMD")); - else - aMenu->addAction(action("ACTIVATE_PART_CMD")); - } else { - ResultPtr aResult = boost::dynamic_pointer_cast(aObject); - if (aResult) { - XGUI_Displayer* aDisplayer = myWorkshop->displayer(); - if (aDisplayer->isVisible(aResult)) + if (aSelected == 1) { + ObjectPtr aObject = aObjects.first(); + if (aObject) { + ResultPartPtr aPart = boost::dynamic_pointer_cast(aObject); + FeaturePtr aFeature = boost::dynamic_pointer_cast(aObject); + if (aPart) { + if (aMgr->currentDocument() == aPart->partDoc()) + aMenu->addAction(action("DEACTIVATE_PART_CMD")); + else + aMenu->addAction(action("ACTIVATE_PART_CMD")); + } else if (aFeature) { + aMenu->addAction(action("EDIT_CMD")); + } else { + if (aDisplayer->isVisible(aObject)) aMenu->addAction(action("HIDE_CMD")); else aMenu->addAction(action("SHOW_CMD")); - } else { - FeaturePtr aFeature = boost::dynamic_pointer_cast(aObject); - if (aFeature) { - aMenu->addAction(action("EDIT_CMD")); - aMenu->addAction(action("DELETE_CMD")); - } } + } else { // If feature is 0 the it means that selected root object (document) + if (aMgr->currentDocument() != aMgr->rootDocument()) + aMenu->addAction(action("ACTIVATE_PART_CMD")); } - aMenu->addSeparator(); - - // Process Root object (document) - } else { // If feature is 0 the it means that selected root object (document) - if (aMgr->currentDocument() != aMgr->rootDocument()) { - aMenu->addAction(action("ACTIVATE_PART_CMD")); + } else if (aSelected >= 1) { + bool hasResult = false; + bool hasFeature = false; + foreach(ObjectPtr aObj, aObjects) { + FeaturePtr aFeature = boost::dynamic_pointer_cast(aObj); + ResultPtr aResult = boost::dynamic_pointer_cast(aObj); + if (aResult) hasResult = true; + if (aFeature) hasFeature = true; + if (hasFeature && hasResult) + break; + } + if (hasResult) { + aMenu->addAction(action("SHOW_CMD")); + aMenu->addAction(action("HIDE_CMD")); } + if (hasFeature) + aMenu->addAction(action("DELETE_CMD")); } } aMenu->addActions(myWorkshop->objectBrowser()->actions()); diff --git a/src/XGUI/XGUI_ObjectsBrowser.cpp b/src/XGUI/XGUI_ObjectsBrowser.cpp index 6e61fef19..45d287465 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.cpp +++ b/src/XGUI/XGUI_ObjectsBrowser.cpp @@ -23,6 +23,8 @@ XGUI_DataTree::XGUI_DataTree(QWidget* theParent) setHeaderHidden(true); setModel(new XGUI_DocumentDataModel(this)); setEditTriggers(QAbstractItemView::NoEditTriggers); + setSelectionBehavior(QAbstractItemView::SelectRows); + setSelectionMode(QAbstractItemView::ExtendedSelection); connect(selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), this, SLOT(onSelectionChanged(const QItemSelection&, const QItemSelection&))); -- 2.39.2