]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_WidgetLineEdit.cpp
Salome HOME
Speed up the redraw of sketch with constraints moved by the point of the line
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetLineEdit.cpp
1 /*
2  * ModuleBase_WidgetLineEdit.cpp
3  *
4  *  Created on: Aug 28, 2014
5  *      Author: sbh
6  */
7
8 #include <ModuleBase_WidgetLineEdit.h>
9 #include <ModuleBase_Tools.h>
10
11 #include <ModelAPI_AttributeString.h>
12 #include <ModelAPI_Data.h>
13 #include <ModelAPI_Object.h>
14 #include <ModelAPI_Validator.h>
15
16 #include <Config_WidgetAPI.h>
17
18 #include <QHBoxLayout>
19 #include <QLabel>
20 #include <QLineEdit>
21 #include <QObject>
22 #include <QString>
23
24 #include <memory>
25 #include <string>
26
27 ModuleBase_WidgetLineEdit::ModuleBase_WidgetLineEdit(QWidget* theParent,
28                                                      const Config_WidgetAPI* theData,
29                                                      const std::string& theParentId)
30     : ModuleBase_ModelWidget(theParent, theData, theParentId)
31 {
32   myMainWidget = new QWidget(theParent);
33   QHBoxLayout* aMainLay = new QHBoxLayout(myMainWidget);
34   ModuleBase_Tools::adjustMargins(aMainLay);
35   QString aTitle = QString::fromStdString(theData->widgetLabel());
36   QLabel* aTitleLabel = new QLabel(aTitle, myMainWidget);
37   aMainLay->addWidget(aTitleLabel);
38   myLineEdit = new QLineEdit(myMainWidget);
39   aMainLay->addWidget(myLineEdit);
40   myLineEdit->setMinimumHeight(20);
41   myMainWidget->setLayout(aMainLay);
42
43   connect(myLineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(onTextChanged()));
44 }
45
46 ModuleBase_WidgetLineEdit::~ModuleBase_WidgetLineEdit()
47 {
48 }
49
50 bool ModuleBase_WidgetLineEdit::storeValue() const
51 {
52   // A rare case when plugin was not loaded. 
53   if(!myFeature)
54     return false;
55   DataPtr aData = myFeature->data();
56   AttributeStringPtr aStringAttr = aData->string(attributeID());
57   QString aWidgetValue = myLineEdit->text();
58   aStringAttr->setValue(aWidgetValue.toStdString());
59   updateObject(myFeature);
60   return true;
61 }
62
63 bool ModuleBase_WidgetLineEdit::restoreValue()
64 {
65   // A rare case when plugin was not loaded. 
66   if(!myFeature)
67     return false;
68   DataPtr aData = myFeature->data();
69   AttributeStringPtr aStringAttr = aData->string(attributeID());
70
71   bool isBlocked = myLineEdit->blockSignals(true);
72   myLineEdit->setText(QString::fromStdString(aStringAttr->value()));
73   myLineEdit->blockSignals(isBlocked);
74
75   return true;
76 }
77
78 QWidget* ModuleBase_WidgetLineEdit::getControl() const
79 {
80   return myMainWidget;
81 }
82
83 QList<QWidget*> ModuleBase_WidgetLineEdit::getControls() const
84 {
85   QList<QWidget*> result;
86   result << myLineEdit;
87   return result;
88 }
89
90 void ModuleBase_WidgetLineEdit::onTextChanged()
91 {
92   storeValue();
93 }