Salome HOME
db7f895e90f7b6077891f9365f559978404f895c
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetLabelValue.cpp
1 // Copyright (C) 2014-2022  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "ModuleBase_WidgetLabelValue.h"
21
22 #include <Config_WidgetAPI.h>
23 #include <Config_Keywords.h>
24 #include <ModuleBase_LabelValue.h>
25
26 #include <ModelAPI_AttributeDouble.h>
27
28 #include <QLabel>
29 #include <QVBoxLayout>
30
31 ModuleBase_WidgetLabelValue::ModuleBase_WidgetLabelValue(QWidget* theParent,
32                                                const Config_WidgetAPI* theData)
33 : ModuleBase_ModelWidget(theParent, theData)
34 {
35   QVBoxLayout* aLayout = new QVBoxLayout(this);
36   aLayout->setContentsMargins(0, 0, 0, 0);
37   aLayout->setSpacing(0);
38
39   QString aText = translate(theData->widgetLabel());
40   QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
41   QString aToolTip = translate(theData->widgetTooltip());
42
43   myLabel = new ModuleBase_LabelValue(theParent, aText, aToolTip, aLabelIcon);
44   bool isOk;
45   double aDefVal = QString::fromStdString(getDefaultValue()).toDouble(&isOk);
46   if (isOk) {
47     myLabel->setValue(aDefVal);
48   }
49
50   aLayout->addWidget(myLabel);
51 }
52
53 ModuleBase_WidgetLabelValue::~ModuleBase_WidgetLabelValue()
54 {
55 }
56
57 QList<QWidget*> ModuleBase_WidgetLabelValue::getControls() const
58 {
59   QList<QWidget*> aControls;
60   aControls.append(myLabel);
61   return aControls;
62 }
63
64 bool ModuleBase_WidgetLabelValue::restoreValueCustom()
65 {
66   DataPtr aData = myFeature->data();
67   AttributeDoublePtr anAttribute = aData->real(attributeID());
68   double aValue = 0;
69   if (anAttribute.get() && anAttribute->isInitialized())
70     aValue = anAttribute->value();
71   myLabel->setValue(aValue);
72   return true;
73 }
74
75 bool ModuleBase_WidgetLabelValue::storeValueCustom()
76 {
77   return true;
78 }