1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: ModuleBase_WidgetAction.cpp
4 // Created: 15 Apr 2016
5 // Author: Natalia Ermolaeva
7 #include <ModuleBase_WidgetAction.h>
8 #include <ModuleBase_Tools.h>
10 #include <Config_WidgetAPI.h>
13 #include <QHBoxLayout>
14 #include <QToolButton>
16 #define DEFAULT_TOOL_TIP_WIDTH 300
18 ModuleBase_WidgetAction::ModuleBase_WidgetAction(QWidget* theParent,
19 const Config_WidgetAPI* theData)
20 : ModuleBase_ModelWidget(theParent, theData)
22 QHBoxLayout* aControlLay = new QHBoxLayout(this);
23 ModuleBase_Tools::adjustMargins(aControlLay);
25 myActionID = attributeID();
28 QString aText = QString::fromStdString(theData->widgetLabel());
29 QString aToolTip = ModuleBase_Tools::wrapTextByWords(
30 QString::fromStdString(theData->widgetTooltip()), myButton, DEFAULT_TOOL_TIP_WIDTH);
32 myButton = new QToolButton(this);
33 myButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
34 aControlLay->addWidget(myButton);
36 QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
37 if (!aLabelIcon.isEmpty())
38 myButton->setIcon(QPixmap(aLabelIcon));
40 myButton->setText(aText);
41 myButton->setToolTip(aToolTip);
43 connect(myButton, SIGNAL(clicked(bool)), this, SLOT(onActionClicked()));
46 ModuleBase_WidgetAction::~ModuleBase_WidgetAction()
50 QList<QWidget*> ModuleBase_WidgetAction::getControls() const
52 QList<QWidget*> aList;
53 aList.append(myButton);
57 bool ModuleBase_WidgetAction::storeValueCustom()
62 bool ModuleBase_WidgetAction::restoreValueCustom()
67 void ModuleBase_WidgetAction::onActionClicked()
69 if (myFeature->customAction(myActionID))
70 updateObject(myFeature);