Salome HOME
Issue #943: Process double click in Object Browser
authorvsv <vitaly.smetannikov@opencascade.com>
Thu, 10 Sep 2015 14:22:30 +0000 (17:22 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Thu, 10 Sep 2015 14:22:30 +0000 (17:22 +0300)
src/ModuleBase/ModuleBase_IModule.h
src/PartSet/PartSet_MenuMgr.cpp
src/PartSet/PartSet_MenuMgr.h
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h

index a482586078a557b85c3f94bdac403013e1377155..ea6124eb45cc8b5ba9f8918069a7e225552cc978 100644 (file)
@@ -147,8 +147,10 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject
   /// \returns true if the action is processed\r
   virtual bool deleteObjects() { return false; };\r
 \r
+#ifdef ModuleDataModel\r
   /// Returns data model object for representation of data tree in Object browser\r
   virtual ModuleBase_IDocumentDataModel* dataModel() const = 0;\r
+#endif\r
 \r
   /// Performs functionality on closing document\r
   virtual void closeDocument() = 0;\r
index a027eb77afb9d7fae36b08872b6b27355056eeee..9b82b66c3460a2bba5e43223dd5def81c76164ae 100644 (file)
@@ -477,16 +477,17 @@ void PartSet_MenuMgr::onActivatePartSet(bool)
 {
   if (myModule->workshop()->currentOperation())
     return;
+  activatePartSet();
+}
+
+void PartSet_MenuMgr::activatePartSet() const
+{
   SessionPtr aMgr = ModelAPI_Session::get();
   bool isNewTransaction = !aMgr->isOperation();
   // activation may cause changes in current features in document, so it must be in transaction
-  if (isNewTransaction) {
-    aMgr->startOperation("Activation");
-  }
+  if (isNewTransaction) aMgr->startOperation("Activation");
   aMgr->setActiveDocument(aMgr->moduleDocument());
-  if (isNewTransaction) {
-    aMgr->finishOperation();
-  }
+  if (isNewTransaction) aMgr->finishOperation();
 }
 
 void PartSet_MenuMgr::onEdit(bool)
index 865bbccdc58ff83d5aba681721177006211ec6ad..7a94a0d9c633e1d65d06433d2bd947f353c89adc 100644 (file)
@@ -46,6 +46,9 @@ public:
   /// \param theStdActions - a map of standard actions
   void updateViewerMenu(const QMap<QString, QAction*>& theStdActions); 
 
+  /// Activates a PartSet document
+  void activatePartSet() const;
+
 public slots:
   /// Processes the context menu action click
   /// \param isChecked a state of toggle if the action is checkable
index 1bc9bfbefd90b85bf768976e93f25da3637dc57f..adb46118fc10a3c752e3479c85f321c1fa2ff22f 100755 (executable)
@@ -125,7 +125,9 @@ PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
   new PartSet_IconFactory();
 
   mySketchMgr = new PartSet_SketcherMgr(this);
+#ifdef ModuleDataModel
   myDataModel = new PartSet_DocumentDataModel(this);
+#endif
 
   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
   XGUI_Workshop* aWorkshop = aConnector->workshop();
@@ -841,9 +843,9 @@ void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
     //aPalet.setColor(QPalette::Text, QColor(0, 72, 140));
     //aLabel->setPalette(aPalet);
     aOB->treeView()->setExpandsOnDoubleClick(false);
-#ifdef ModuleDataModel
     connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)), 
       SLOT(onTreeViewDoubleClick(const QModelIndex&)));
+#ifdef ModuleDataModel
     connect(aOB, SIGNAL(headerMouseDblClicked(const QModelIndex&)), 
       SLOT(onTreeViewDoubleClick(const QModelIndex&)));
     connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)), 
@@ -1005,7 +1007,18 @@ void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
   }
   if (theIndex.column() != 0) // Use only first column
     return;
+#ifdef ModuleDataModel
   ObjectPtr aObj = myDataModel->object(theIndex);
+#else
+  XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
+  XGUI_Workshop* aWorkshop = aConnector->workshop();
+  XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
+  // De not use non editable Indexes
+  if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
+    return;
+  ObjectPtr aObj = aDataModel->object(theIndex);
+#endif
+
   ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
   if (!aPart.get()) { // Probably this is Feature
     FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
@@ -1015,7 +1028,7 @@ void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
   }
   if (aPart.get()) { // if this is a part
     if (aPart->partDoc() == aMgr->activeDocument()) {
-      aMgr->setActiveDocument(aMgr->moduleDocument());
+      myMenuMgr->activatePartSet();
     } else {
       aPart->activate();
     }
index 87572db15c83362772ba75d2bd289cec4f9bf932..bdcbdd0ecdbf090b0a9303083385a9c431e06f65 100644 (file)
@@ -157,8 +157,10 @@ public:
 
   PartSet_SketcherMgr* sketchMgr() const { return mySketchMgr; }
 
+#ifdef ModuleDataModel
   /// Returns data model object for representation of data tree in Object browser
   virtual ModuleBase_IDocumentDataModel* dataModel() const { return myDataModel; }
+#endif
 
   /// Performs functionality on closing document
   virtual void closeDocument();
@@ -279,7 +281,9 @@ protected slots:
   PartSet_CustomPrs* myCustomPrs;
   int myVisualLayerId;
 
+#ifdef ModuleDataModel
   PartSet_DocumentDataModel* myDataModel;
+#endif
 
   QModelIndex aActivePartIndex;
 };