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";
type_choice="edges objects">
<validator id="FeaturesPlugin_ValidatorBaseForWire"/>
</multi_selector>
+ <action id="Action_1" label="Action_1" tooltip="Tool tip information"/>
</source>
return myIsStable;
}
+bool ModelAPI_Feature::customAction(const std::string& theActionId)
+{
+ return false;
+}
+
bool ModelAPI_Feature::isPreviewNeeded() const
{
return true;
/// 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()
// -----------------------------------------------------------------------------------------------
ModuleBase_Tools.h
ModuleBase_ViewerFilters.h
ModuleBase_ViewerPrs.h
+ ModuleBase_WidgetAction.h
ModuleBase_WidgetBoolValue.h
ModuleBase_WidgetCheckGroupBox.h
ModuleBase_WidgetChoice.h
ModuleBase_Tools.cpp
ModuleBase_ViewerFilters.cpp
ModuleBase_ViewerPrs.cpp
+ ModuleBase_WidgetAction.cpp
ModuleBase_WidgetBoolValue.cpp
ModuleBase_WidgetCheckGroupBox.cpp
ModuleBase_WidgetChoice.cpp
--- /dev/null
+// 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);
+}
--- /dev/null
+// 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
#include <ModuleBase_PageWidget.h>
#include <ModuleBase_WidgetExprEditor.h>
#include <ModuleBase_WidgetCreatorFactory.h>
+#include <ModuleBase_WidgetAction.h>
#include <ModelAPI_Validator.h>
#include <ModelAPI_Session.h>
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)