From: nds Date: Fri, 15 Apr 2016 10:05:21 +0000 (+0300) Subject: Action button to call customAction of a feature. X-Git-Tag: V_2.3.0~216 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=50aeec65965daa04bb5ef38125363c22067817f5;p=modules%2Fshaper.git Action button to call customAction of a feature. --- diff --git a/src/Config/Config_Keywords.h b/src/Config/Config_Keywords.h index ae6dc346d..7824c685d 100644 --- a/src/Config/Config_Keywords.h +++ b/src/Config/Config_Keywords.h @@ -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"; diff --git a/src/FeaturesPlugin/wire_widget.xml b/src/FeaturesPlugin/wire_widget.xml index 6db25b19f..a2b8c35a3 100644 --- a/src/FeaturesPlugin/wire_widget.xml +++ b/src/FeaturesPlugin/wire_widget.xml @@ -7,4 +7,5 @@ type_choice="edges objects"> + diff --git a/src/ModelAPI/ModelAPI_Feature.cpp b/src/ModelAPI/ModelAPI_Feature.cpp index 5b9d7e3d4..ad496462b 100644 --- a/src/ModelAPI/ModelAPI_Feature.cpp +++ b/src/ModelAPI/ModelAPI_Feature.cpp @@ -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; diff --git a/src/ModelAPI/ModelAPI_Feature.h b/src/ModelAPI/ModelAPI_Feature.h index 8a648e7c5..a9fc2f077 100644 --- a/src/ModelAPI/ModelAPI_Feature.h +++ b/src/ModelAPI/ModelAPI_Feature.h @@ -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() // ----------------------------------------------------------------------------------------------- diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index d2d93c9b5..40de9e2b9 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -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 index 000000000..2b0dd3915 --- /dev/null +++ b/src/ModuleBase/ModuleBase_WidgetAction.cpp @@ -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 +#include + +#include + +#include +#include +#include + +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 ModuleBase_WidgetAction::getControls() const +{ + QList 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 index 000000000..1e801b7e2 --- /dev/null +++ b/src/ModuleBase/ModuleBase_WidgetAction.h @@ -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 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 diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.cpp b/src/ModuleBase/ModuleBase_WidgetFactory.cpp index f9627d525..3052dae9f 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFactory.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -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)