Salome HOME
Correction of Boolean crash
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetAction.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModuleBase_WidgetAction.cpp
4 // Created:     15 Apr 2016
5 // Author:      Natalia Ermolaeva
6
7 #include <ModuleBase_WidgetAction.h>
8 #include <ModuleBase_Tools.h>
9 #include <ModuleBase_IconFactory.h>
10
11 #include <Config_WidgetAPI.h>
12
13 #include <QWidget>
14 #include <QHBoxLayout>
15 #include <QToolButton>
16
17 #define DEFAULT_TOOL_TIP_WIDTH 300
18
19 ModuleBase_WidgetAction::ModuleBase_WidgetAction(QWidget* theParent,
20                                                  const Config_WidgetAPI* theData)
21 : ModuleBase_ModelWidget(theParent, theData)
22 {
23   QHBoxLayout* aControlLay = new QHBoxLayout(this);
24   ModuleBase_Tools::adjustMargins(aControlLay);
25
26   myActionID = attributeID();
27   setAttributeID("");
28
29   QString aText = QString::fromStdString(theData->widgetLabel());
30   QString aToolTip = ModuleBase_Tools::wrapTextByWords(
31               QString::fromStdString(theData->widgetTooltip()), myButton, DEFAULT_TOOL_TIP_WIDTH);
32
33   myButton = new QToolButton(this);
34   myButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
35   aControlLay->addWidget(myButton);
36
37   QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
38   if (!aLabelIcon.isEmpty())
39     myButton->setIcon(ModuleBase_IconFactory::loadPixmap(aLabelIcon));
40   else
41     myButton->setText(aText);
42   myButton->setToolTip(aToolTip);
43
44   connect(myButton, SIGNAL(clicked(bool)), this, SLOT(onActionClicked()));
45 }
46
47 ModuleBase_WidgetAction::~ModuleBase_WidgetAction()
48 {
49 }
50
51 QList<QWidget*> ModuleBase_WidgetAction::getControls() const
52 {
53   QList<QWidget*> aList;
54   aList.append(myButton);
55   return aList;
56 }
57
58 bool ModuleBase_WidgetAction::storeValueCustom()
59 {
60   return true;
61 }
62
63 bool ModuleBase_WidgetAction::restoreValueCustom()
64 {
65   return true;
66 }
67
68 void ModuleBase_WidgetAction::onActionClicked()
69 {
70   if (myFeature->customAction(myActionID))
71     updateObject(myFeature);
72 }