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 <QFormLayout>
29 ModuleBase_WidgetLineEdit::ModuleBase_WidgetLineEdit(QWidget* theParent,
30 const Config_WidgetAPI* theData,
31 const std::string& theParentId)
32 : ModuleBase_ModelWidget(theParent, theData, theParentId)
34 QFormLayout* aMainLay = new QFormLayout(this);
35 ModuleBase_Tools::adjustMargins(aMainLay);
36 QString aLabelText = QString::fromStdString(theData->widgetLabel());
37 QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
38 QLabel* aLabel = new QLabel(aLabelText, this);
39 if (!aLabelIcon.isEmpty())
40 aLabel->setPixmap(QPixmap(aLabelIcon));
42 myLineEdit = new QLineEdit(this);
43 myLineEdit->setMinimumHeight(20);
44 aMainLay->addRow(aLabel, myLineEdit);
45 this->setLayout(aMainLay);
47 connect(myLineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(onTextChanged()));
50 ModuleBase_WidgetLineEdit::~ModuleBase_WidgetLineEdit()
54 bool ModuleBase_WidgetLineEdit::storeValueCustom() const
56 // A rare case when plugin was not loaded.
59 DataPtr aData = myFeature->data();
60 AttributeStringPtr aStringAttr = aData->string(attributeID());
61 QString aWidgetValue = myLineEdit->text();
62 aStringAttr->setValue(aWidgetValue.toStdString());
63 updateObject(myFeature);
67 bool ModuleBase_WidgetLineEdit::restoreValue()
69 // A rare case when plugin was not loaded.
72 DataPtr aData = myFeature->data();
73 AttributeStringPtr aStringAttr = aData->string(attributeID());
75 bool isBlocked = myLineEdit->blockSignals(true);
76 myLineEdit->setText(QString::fromStdString(aStringAttr->value()));
77 myLineEdit->blockSignals(isBlocked);
82 QList<QWidget*> ModuleBase_WidgetLineEdit::getControls() const
84 QList<QWidget*> result;
89 void ModuleBase_WidgetLineEdit::onTextChanged()