Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetLabelValue.cpp
1 // Copyright (C) 2014-2017  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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include "ModuleBase_WidgetLabelValue.h"
22
23 #include <Config_WidgetAPI.h>
24 #include <Config_Keywords.h>
25 #include <ModuleBase_LabelValue.h>
26
27 #include <ModelAPI_AttributeDouble.h>
28
29 #include <QLabel>
30 #include <QVBoxLayout>
31
32 ModuleBase_WidgetLabelValue::ModuleBase_WidgetLabelValue(QWidget* theParent,
33                                                const Config_WidgetAPI* theData)
34 : ModuleBase_ModelWidget(theParent, theData)
35 {
36   QVBoxLayout* aLayout = new QVBoxLayout(this);
37   aLayout->setContentsMargins(0, 0, 0, 0);
38   aLayout->setSpacing(0);
39
40   QString aText = QString::fromStdString(theData->widgetLabel());
41   QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
42   QString aToolTip = QString::fromStdString(theData->widgetTooltip());
43
44   myLabel = new ModuleBase_LabelValue(theParent, aText, aToolTip, aLabelIcon);
45   bool isOk;
46   double aDefVal = QString::fromStdString(getDefaultValue()).toDouble(&isOk);
47   if (isOk) {
48     myLabel->setValue(aDefVal);
49   }
50
51   aLayout->addWidget(myLabel);
52 }
53
54 ModuleBase_WidgetLabelValue::~ModuleBase_WidgetLabelValue()
55 {
56 }
57
58 QList<QWidget*> ModuleBase_WidgetLabelValue::getControls() const
59 {
60   QList<QWidget*> aControls;
61   aControls.append(myLabel);
62   return aControls;
63 }
64
65 bool ModuleBase_WidgetLabelValue::restoreValueCustom()
66 {
67   DataPtr aData = myFeature->data();
68   AttributeDoublePtr anAttribute = aData->real(attributeID());
69   double aValue = 0;
70   if (anAttribute.get() && anAttribute->isInitialized())
71     aValue = anAttribute->value();
72   myLabel->setValue(aValue);
73   return true;
74 }
75
76 bool ModuleBase_WidgetLabelValue::storeValueCustom()
77 {
78   return true;
79 }