]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Imrove multi-selector control to provide items multi-selection. Delete key in line...
authornds <nds@opencascade.com>
Mon, 18 Jan 2016 07:35:38 +0000 (10:35 +0300)
committernds <nds@opencascade.com>
Mon, 18 Jan 2016 07:35:38 +0000 (10:35 +0300)
src/PartSet/PartSet_Module.cpp
src/XGUI/XGUI_OperationMgr.cpp
src/XGUI/XGUI_OperationMgr.h

index 35613280488db8da7792cba3637c4eb3dbc95e6e..35c38bc464fbdc9ab2714a7325dfd0704140ed62 100755 (executable)
@@ -492,7 +492,7 @@ void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* the
 {
   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
   XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
-  anOpMgr->onKeyReleased(theEvent);
+  anOpMgr->onKeyReleased(theWnd->viewPort(), theEvent);
 }
 
 void PartSet_Module::onOperationActivatedByPreselection()
index e46877afa762f5a37717520d80b0f871cd5d812b..f8879aa62eddfcff893e0f493d11218a527c1751 100644 (file)
@@ -8,6 +8,7 @@
 #include "XGUI_ModuleConnector.h"
 #include "XGUI_Workshop.h"
 #include "XGUI_ErrorMgr.h"
+#include <XGUI_ObjectsBrowser.h>
 
 #include <ModuleBase_IPropertyPanel.h>
 #include <ModuleBase_ModelWidget.h>
@@ -56,7 +57,7 @@ public:
       if(aKeyEvent) {
         switch (aKeyEvent->key()) {
           case Qt::Key_Delete: {
-            isAccepted = myOperationMgr->onProcessDelete();
+            isAccepted = myOperationMgr->onProcessDelete(theObject);
           }
         }
       }
@@ -154,9 +155,8 @@ bool XGUI_OperationMgr::eventFilter(QObject *theObject, QEvent *theEvent)
   bool isAccepted = false;
   if (theEvent->type() == QEvent::KeyRelease) {
     QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
-    if(aKeyEvent) {
-      isAccepted = onKeyReleased(aKeyEvent);
-    }
+    if(aKeyEvent)
+      isAccepted = onKeyReleased(theObject, aKeyEvent);
   }
   if (!isAccepted)
     isAccepted = QObject::eventFilter(theObject, theEvent);
@@ -544,7 +544,7 @@ void XGUI_OperationMgr::onOperationStopped()
   }
 }
 
-bool XGUI_OperationMgr::onKeyReleased(QKeyEvent* theEvent)
+bool XGUI_OperationMgr::onKeyReleased(QObject *theObject, QKeyEvent* theEvent)
 {
   // Let the manager decide what to do with the given key combination.
   ModuleBase_Operation* anOperation = currentOperation();
@@ -552,7 +552,7 @@ bool XGUI_OperationMgr::onKeyReleased(QKeyEvent* theEvent)
   switch (theEvent->key()) {
     case Qt::Key_Return:
     case Qt::Key_Enter: {
-      isAccepted = onProcessEnter();
+      isAccepted = onProcessEnter(theObject);
     }
     break;
     case Qt::Key_N:
@@ -582,11 +582,16 @@ bool XGUI_OperationMgr::onKeyReleased(QKeyEvent* theEvent)
   return isAccepted;
 }
 
-bool XGUI_OperationMgr::onProcessEnter()
+bool XGUI_OperationMgr::onProcessEnter(QObject* theObject)
 {
   bool isAccepted = false;
   ModuleBase_Operation* aOperation = currentOperation();
   ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
+  // only property panel enter is processed in order to do not process enter in application dialogs
+  bool isPPChild = isChildObject(theObject, aPanel);
+  if (!isPPChild)
+    return isAccepted;
+
   ModuleBase_ModelWidget* anActiveWgt = aPanel->activeWidget();
   bool isAborted = false;
   if (!anActiveWgt) {
@@ -619,20 +624,30 @@ bool XGUI_OperationMgr::onProcessEnter()
   return isAccepted;
 }
 
-bool XGUI_OperationMgr::onProcessDelete()
+bool XGUI_OperationMgr::onProcessDelete(QObject* theObject)
 {
   bool isAccepted = false;
   ModuleBase_Operation* aOperation = currentOperation();
   ModuleBase_ModelWidget* anActiveWgt = 0;
+  // firstly the widget should process Delete action
+  ModuleBase_IPropertyPanel* aPanel;
   if (aOperation) {
-    ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
+    aPanel = aOperation->propertyPanel();
     if (aPanel)
       anActiveWgt = aPanel->activeWidget();
+    if (anActiveWgt) {
+      isAccepted = anActiveWgt->processDelete();
+    }
   }
-  if (anActiveWgt)
-    isAccepted = anActiveWgt->processDelete();
   if (!isAccepted) {
-    workshop()->deleteObjects();
+    // after widget, object browser and viewer should process delete
+    /// other widgets such as line edit controls should not lead to
+    /// processing delete by workshop
+    XGUI_ObjectsBrowser* aBrowser = workshop()->objectBrowser();
+    QWidget* aViewPort = myWorkshop->viewer()->activeViewPort();
+    if (isChildObject(theObject, aBrowser) ||
+        isChildObject(theObject, aViewPort))
+      workshop()->deleteObjects();
     isAccepted = true;
   }
 
@@ -645,3 +660,17 @@ XGUI_Workshop* XGUI_OperationMgr::workshop() const
   return aConnector->workshop();
 }
 
+bool XGUI_OperationMgr::isChildObject(const QObject* theObject, const QObject* theParent)
+{
+  bool isPPChild = false;
+  if (theParent && theObject) {
+    QObject* aParent = (QObject*)theObject;
+    while (aParent ) {
+      isPPChild = aParent == theParent;
+      if (isPPChild)
+        break;
+      aParent = aParent->parent();
+    }
+  }
+  return isPPChild;
+}
index fba23b0d4d890673000871f72e4d83371c10017f..1453bf762e76443f3a36400d6c1c5e7e829861a7 100755 (executable)
@@ -160,18 +160,21 @@ protected: // TEMPORARY
  public slots:
   /// SLOT, that is called by the key in the property panel is clicked.
   /// \param theEvent the mouse event
-  bool onKeyReleased(QKeyEvent* theEvent);
+  /// \param theObject a sender of the event
+  bool onKeyReleased(QObject *theObject, QKeyEvent* theEvent);
 
   /// The functionaly, that should be done by delete click
   /// Fistly the active widget processes it, then workshop. If no one does not
   /// process it, do nothing
-  bool onProcessDelete();
+  /// \param theObject a sender of the event
+  bool onProcessDelete(QObject* theObject);
 
   protected slots:
   /// The functionaly, that should be done by enter click
   /// Fistly the active widget processes it, then module. If no one does not
   /// process it, the current operation is committed
-  bool onProcessEnter();
+  /// \param theObject a sender of the event
+  bool onProcessEnter(QObject *theObject);
 
   /// Slot that is called by an operation stop. Removes the stopped operation form the stack.
   /// If there is a suspended operation, restart it.
@@ -203,6 +206,11 @@ protected: // TEMPORARY
 private:
   XGUI_Workshop* workshop() const;
 
+  /// Checks if the object is a parent or a child under
+  /// \param theObject an investivated object
+  /// \param theParent a candidate to be a parent
+  static bool isChildObject(const QObject* theObject, const QObject* theParent);
+
  private:
   typedef QList<ModuleBase_Operation*> Operations;  ///< definition for a list of operations
   Operations myOperations;  ///< a stack of started operations. The active operation is on top,