Salome HOME
Merge branch 'master' into cgt/devCEA
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetLabelValue.cpp
1 // Copyright (C) 2014-2016 CEA/DEN, EDF R&D
2
3 // File:        ModuleBase_WidgetLabelValue.cpp
4 // Created:     30 Nov 2016
5 // Author:      Natalia ERMOLAEVA
6
7 #include "ModuleBase_WidgetLabelValue.h"
8
9 #include <Config_WidgetAPI.h>
10 #include <Config_Keywords.h>
11 #include <ModuleBase_LabelValue.h>
12
13 #include <ModelAPI_AttributeDouble.h>
14
15 #include <QLabel>
16 #include <QVBoxLayout>
17
18 ModuleBase_WidgetLabelValue::ModuleBase_WidgetLabelValue(QWidget* theParent,
19                                                const Config_WidgetAPI* theData)
20 : ModuleBase_ModelWidget(theParent, theData)
21 {
22   QVBoxLayout* aLayout = new QVBoxLayout(this);
23   aLayout->setContentsMargins(0, 0, 0, 0);
24   aLayout->setSpacing(0);
25
26   QString aText = QString::fromStdString(theData->widgetLabel());
27   QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
28   QString aToolTip = QString::fromStdString(theData->widgetTooltip());
29
30   myLabel = new ModuleBase_LabelValue(theParent, aText, aToolTip, aLabelIcon);
31   bool isOk;
32   double aDefVal = QString::fromStdString(getDefaultValue()).toDouble(&isOk);
33   if (isOk) {
34     myLabel->setValue(aDefVal);
35   }
36
37   aLayout->addWidget(myLabel);
38 }
39
40 ModuleBase_WidgetLabelValue::~ModuleBase_WidgetLabelValue()
41 {
42 }
43
44 QList<QWidget*> ModuleBase_WidgetLabelValue::getControls() const
45 {
46   QList<QWidget*> aControls;
47   aControls.append(myLabel);
48   return aControls;
49 }
50
51 bool ModuleBase_WidgetLabelValue::restoreValueCustom()
52 {
53   DataPtr aData = myFeature->data();
54   AttributeDoublePtr anAttribute = aData->real(attributeID());
55   double aValue = 0;
56   if (anAttribute.get() && anAttribute->isInitialized())
57     aValue = anAttribute->value();
58   myLabel->setValue(aValue);
59   return true;
60 }
61
62 bool ModuleBase_WidgetLabelValue::storeValueCustom()
63 {
64   return true;
65 }