Salome HOME
Action button to call customAction of a feature.
authornds <nds@opencascade.com>
Fri, 15 Apr 2016 10:05:21 +0000 (13:05 +0300)
committernds <nds@opencascade.com>
Fri, 15 Apr 2016 10:05:21 +0000 (13:05 +0300)
src/Config/Config_Keywords.h
src/FeaturesPlugin/wire_widget.xml
src/ModelAPI/ModelAPI_Feature.cpp
src/ModelAPI/ModelAPI_Feature.h
src/ModuleBase/CMakeLists.txt
src/ModuleBase/ModuleBase_WidgetAction.cpp [new file with mode: 0755]
src/ModuleBase/ModuleBase_WidgetAction.h [new file with mode: 0755]
src/ModuleBase/ModuleBase_WidgetFactory.cpp

index ae6dc346d5744c9df83e3ed9668a21ec111c6b89..7824c685d7311add72765f685b52b899ee5efaaf 100644 (file)
@@ -38,6 +38,7 @@ const static char* WDG_DOUBLEVALUE_EDITOR = "doublevalue_editor";
 const static char* WDG_FILE_SELECTOR= "file_selector";
 const static char* WDG_EXPR_EDITOR = "expr_editor";
 const static char* WDG_PLACE_HOLDER = "placeholder";
+const static char* WDG_ACTION = "action";
 
 // Containers
 const static char* WDG_GROUP = "groupbox";
index 6db25b19f81eebfe44da2909447168477586e9d4..a2b8c35a33995cfc335571e994674ad79a176113 100644 (file)
@@ -7,4 +7,5 @@
                   type_choice="edges objects">
     <validator id="FeaturesPlugin_ValidatorBaseForWire"/>
   </multi_selector>
+  <action id="Action_1" label="Action_1" tooltip="Tool tip information"/>
 </source>
index 5b9d7e3d4e0f3da971bd37d24dd6347179928f9f..ad496462bd8c70e183b6e5574b320543313a0442 100644 (file)
@@ -218,6 +218,11 @@ bool ModelAPI_Feature::isStable()
   return myIsStable;
 }
 
+bool ModelAPI_Feature::customAction(const std::string& theActionId)
+{
+  return false;
+}
+
 bool ModelAPI_Feature::isPreviewNeeded() const
 {
   return true;
index 8a648e7c53c21616a7260ed5ad29ec0d11f2628c..a9fc2f07717f1f7141f539adbd316f7656d0c424 100644 (file)
@@ -142,6 +142,11 @@ class ModelAPI_Feature : public ModelAPI_Object
   /// Returns the feature is stable or not.
   MODELAPI_EXPORT virtual bool isStable();
 
+  /// Performs some functionality for the indes
+  /// \param theAttributeId an action key
+  /// \return a boolean value about it is performed
+  MODELAPI_EXPORT virtual bool customAction(const std::string& theActionId);
+
  //
  // Helper methods, aliases for data()->method()
  // -----------------------------------------------------------------------------------------------
index d2d93c9b5e92819151d85c8ea18d3db6c71a6bf3..40de9e2b9dac77f22d69bfcf668e6c0c86f50b94 100644 (file)
@@ -39,6 +39,7 @@ SET(PROJECT_HEADERS
   ModuleBase_Tools.h
   ModuleBase_ViewerFilters.h
   ModuleBase_ViewerPrs.h
+  ModuleBase_WidgetAction.h
   ModuleBase_WidgetBoolValue.h
   ModuleBase_WidgetCheckGroupBox.h
   ModuleBase_WidgetChoice.h
@@ -96,6 +97,7 @@ SET(PROJECT_SOURCES
   ModuleBase_Tools.cpp
   ModuleBase_ViewerFilters.cpp
   ModuleBase_ViewerPrs.cpp
+  ModuleBase_WidgetAction.cpp
   ModuleBase_WidgetBoolValue.cpp
   ModuleBase_WidgetCheckGroupBox.cpp
   ModuleBase_WidgetChoice.cpp
diff --git a/src/ModuleBase/ModuleBase_WidgetAction.cpp b/src/ModuleBase/ModuleBase_WidgetAction.cpp
new file mode 100755 (executable)
index 0000000..2b0dd39
--- /dev/null
@@ -0,0 +1,68 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        ModuleBase_WidgetAction.cpp
+// Created:     15 Apr 2016
+// Author:      Natalia Ermolaeva
+
+#include <ModuleBase_WidgetAction.h>
+#include <ModuleBase_Tools.h>
+
+#include <Config_WidgetAPI.h>
+
+#include <QWidget>
+#include <QHBoxLayout>
+#include <QToolButton>
+
+ModuleBase_WidgetAction::ModuleBase_WidgetAction(QWidget* theParent,
+                                                 const Config_WidgetAPI* theData)
+: ModuleBase_ModelWidget(theParent, theData)
+{
+  QHBoxLayout* aControlLay = new QHBoxLayout(this);
+  ModuleBase_Tools::adjustMargins(aControlLay);
+
+  myActionID = attributeID();
+  setAttributeID("");
+
+  QString aText = QString::fromStdString(theData->widgetLabel());
+  QString aToolTip = QString::fromStdString(theData->widgetTooltip());
+
+  myButton = new QToolButton(this);
+  myButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
+  aControlLay->addWidget(myButton);
+
+  QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
+  if (!aLabelIcon.isEmpty())
+    myButton->setIcon(QPixmap(aLabelIcon));
+  else
+    myButton->setText(aText);
+  myButton->setToolTip(aToolTip);
+
+  connect(myButton, SIGNAL(clicked(bool)), this, SLOT(onActionClicked()));
+}
+
+ModuleBase_WidgetAction::~ModuleBase_WidgetAction()
+{
+}
+
+QList<QWidget*> ModuleBase_WidgetAction::getControls() const
+{
+  QList<QWidget*> aList;
+  aList.append(myButton);
+  return aList;
+}
+
+bool ModuleBase_WidgetAction::storeValueCustom()
+{
+  return true;
+}
+
+bool ModuleBase_WidgetAction::restoreValueCustom()
+{
+  return true;
+}
+
+void ModuleBase_WidgetAction::onActionClicked()
+{
+  if (myFeature->customAction(myActionID))
+    updateObject(myFeature);
+}
diff --git a/src/ModuleBase/ModuleBase_WidgetAction.h b/src/ModuleBase/ModuleBase_WidgetAction.h
new file mode 100755 (executable)
index 0000000..1e801b7
--- /dev/null
@@ -0,0 +1,53 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        ModuleBase_WidgetAction.h
+// Created:     15 Apr 2016
+// Author:      Natalia Ermolaeva
+
+#ifndef ModuleBase_WidgetAction_H
+#define ModuleBase_WidgetAction_H
+
+#include "ModuleBase.h"
+#include "ModuleBase_ModelWidget.h"
+
+class Config_WidgetAPI;
+class QWidget;
+class QToolButton;
+
+/**
+* \ingroup GUI
+* Implementation of widget for feature action (tool button)
+*/ 
+class MODULEBASE_EXPORT ModuleBase_WidgetAction : public ModuleBase_ModelWidget
+{
+Q_OBJECT
+ public:
+  /// Constructor
+  /// \param theParent the parent object
+  /// \param theData the widget configuation. The attribute of the model widget is obtained from
+  ModuleBase_WidgetAction(QWidget* theParent, const Config_WidgetAPI* theData);
+
+  virtual ~ModuleBase_WidgetAction();
+
+  /// Returns list of widget controls
+  /// \return a control list
+  virtual QList<QWidget*> getControls() const;
+
+protected:
+  /// Do nothing
+  /// \return True in success
+  virtual bool storeValueCustom();
+
+  /// Do nothing
+  virtual bool restoreValueCustom();
+
+protected slots:
+  /// Listens the button click and call the customAction function of the current feature
+  void onActionClicked();
+
+private:
+  QToolButton* myButton; ///< action button
+  std::string myActionID; ///< action index
+};
+
+#endif
index f9627d5259ac72bead2166c8b06f986a624f76f5..3052dae9f594129a2551930805e4e6925edad684 100644 (file)
@@ -33,6 +33,7 @@
 #include <ModuleBase_PageWidget.h>
 #include <ModuleBase_WidgetExprEditor.h>
 #include <ModuleBase_WidgetCreatorFactory.h>
+#include <ModuleBase_WidgetAction.h>
 
 #include <ModelAPI_Validator.h>
 #include <ModelAPI_Session.h>
@@ -312,6 +313,8 @@ ModuleBase_ModelWidget* ModuleBase_WidgetFactory::createWidgetByType(const std::
              theType == NODE_VALIDATOR) {
     // Do nothing for "box" and "case"
     result = NULL;
+  } else if (theType == WDG_ACTION) {
+    result = new ModuleBase_WidgetAction(theParent, myWidgetApi);
   } else {
     result = myWorkshop->module()->createWidgetByType(theType, theParent, myWidgetApi);
     if (!result)