Salome HOME
46cf12aee5ca6a29a93d66cb18ac526f4b142e1f
[modules/shaper.git] / src / ModuleBase / ModuleBase_LabelValue.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModuleBase_IWorkshop.cpp
4 // Created:     30 Nov 2016
5 // Author:      Natalia ERMOLAEVA
6
7 #include <ModuleBase_LabelValue.h>
8 #include <ModuleBase_IconFactory.h>
9
10 #include <QHBoxLayout>
11 #include <QLabel>
12 #include <QLocale>
13
14 ModuleBase_LabelValue::ModuleBase_LabelValue(QWidget* theParent, const QString& theText,
15                                              const QString& theToolTip, const QString& theIcon,
16                                              int thePrecision)
17 : QWidget(theParent), myPrecision(thePrecision), myValue(0)
18 {
19   QHBoxLayout* aLayout = new QHBoxLayout(this);
20   aLayout->setContentsMargins(2, 0, 0, 0);
21   aLayout->setSpacing(0);
22
23   myLabel = new QLabel(QString("%1 : ").arg(theText), this);
24   if (!theIcon.isEmpty()) {
25     myLabel->setPixmap(ModuleBase_IconFactory::loadPixmap(theIcon));
26     aLayout->setSpacing(4);
27   }
28   myLabel->setToolTip(!theToolTip.isEmpty() ? theToolTip : theText);
29   aLayout->addWidget(myLabel);
30
31   myLabelValue = new QLabel("", this);
32   aLayout->addWidget(myLabelValue, 1);
33
34   // VSR 01/07/2010: Disable thousands separator for spin box
35   // (to avoid inconsistency of double-2-string and string-2-double conversion)
36   QLocale loc;
37   loc.setNumberOptions(loc.numberOptions() |
38                        QLocale::OmitGroupSeparator |
39                        QLocale::RejectGroupSeparator);
40   setLocale(loc);
41
42   aLayout->addStretch(1);
43 }
44
45 ModuleBase_LabelValue::~ModuleBase_LabelValue()
46 {
47 }
48
49 void ModuleBase_LabelValue::setValue(const double theValue)
50 {
51   myValue = theValue;
52
53   QString aStrValue = locale().toString(theValue, myPrecision >= 0 ? 'f' : 'g', qAbs(myPrecision));
54   myLabelValue->setText(aStrValue);
55   myLabelValue->setToolTip(QString::number(theValue));
56 }