1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
4 * ModuleBase_WidgetLineEdit.cpp
6 * Created on: Aug 28, 2014
10 #include <ModuleBase_WidgetLineEdit.h>
11 #include <ModuleBase_Tools.h>
13 #include <ModelAPI_AttributeString.h>
14 #include <ModelAPI_Data.h>
15 #include <ModelAPI_Object.h>
16 #include <ModelAPI_Validator.h>
18 #include <Config_WidgetAPI.h>
20 #include <QHBoxLayout>
29 ModuleBase_WidgetLineEdit::ModuleBase_WidgetLineEdit(QWidget* theParent,
30 const Config_WidgetAPI* theData,
31 const std::string& theParentId)
32 : ModuleBase_ModelWidget(theParent, theData, theParentId)
34 myMainWidget = new QWidget(theParent);
35 QHBoxLayout* aMainLay = new QHBoxLayout(myMainWidget);
36 ModuleBase_Tools::adjustMargins(aMainLay);
37 QString aTitle = QString::fromStdString(theData->widgetLabel());
38 QLabel* aTitleLabel = new QLabel(aTitle, myMainWidget);
39 aMainLay->addWidget(aTitleLabel);
40 myLineEdit = new QLineEdit(myMainWidget);
41 aMainLay->addWidget(myLineEdit);
42 myLineEdit->setMinimumHeight(20);
43 myMainWidget->setLayout(aMainLay);
45 connect(myLineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(onTextChanged()));
48 ModuleBase_WidgetLineEdit::~ModuleBase_WidgetLineEdit()
52 bool ModuleBase_WidgetLineEdit::storeValue() const
54 // A rare case when plugin was not loaded.
57 DataPtr aData = myFeature->data();
58 AttributeStringPtr aStringAttr = aData->string(attributeID());
59 QString aWidgetValue = myLineEdit->text();
60 aStringAttr->setValue(aWidgetValue.toStdString());
61 updateObject(myFeature);
65 bool ModuleBase_WidgetLineEdit::restoreValue()
67 // A rare case when plugin was not loaded.
70 DataPtr aData = myFeature->data();
71 AttributeStringPtr aStringAttr = aData->string(attributeID());
73 bool isBlocked = myLineEdit->blockSignals(true);
74 myLineEdit->setText(QString::fromStdString(aStringAttr->value()));
75 myLineEdit->blockSignals(isBlocked);
80 QWidget* ModuleBase_WidgetLineEdit::getControl() const
85 QList<QWidget*> ModuleBase_WidgetLineEdit::getControls() const
87 QList<QWidget*> result;
92 void ModuleBase_WidgetLineEdit::onTextChanged()