2 * ModuleBase_WidgetLineEdit.cpp
4 * Created on: Aug 28, 2014
8 #include <ModuleBase_WidgetLineEdit.h>
9 #include <ModuleBase_Tools.h>
11 #include <ModelAPI_AttributeString.h>
12 #include <ModelAPI_Data.h>
13 #include <ModelAPI_Object.h>
14 #include <ModelAPI_Validator.h>
16 #include <Config_WidgetAPI.h>
18 #include <QHBoxLayout>
27 ModuleBase_WidgetLineEdit::ModuleBase_WidgetLineEdit(QWidget* theParent,
28 const Config_WidgetAPI* theData,
29 const std::string& theParentId)
30 : ModuleBase_ModelWidget(theParent, theData, theParentId)
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);
43 connect(myLineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(onTextChanged()));
46 ModuleBase_WidgetLineEdit::~ModuleBase_WidgetLineEdit()
50 bool ModuleBase_WidgetLineEdit::storeValue() const
52 // A rare case when plugin was not loaded.
55 DataPtr aData = myFeature->data();
56 AttributeStringPtr aStringAttr = aData->string(attributeID());
57 QString aWidgetValue = myLineEdit->text();
58 aStringAttr->setValue(aWidgetValue.toStdString());
59 updateObject(myFeature);
63 bool ModuleBase_WidgetLineEdit::restoreValue()
65 // A rare case when plugin was not loaded.
68 DataPtr aData = myFeature->data();
69 AttributeStringPtr aStringAttr = aData->string(attributeID());
71 bool isBlocked = myLineEdit->blockSignals(true);
72 myLineEdit->setText(QString::fromStdString(aStringAttr->value()));
73 myLineEdit->blockSignals(isBlocked);
78 QWidget* ModuleBase_WidgetLineEdit::getControl() const
83 QList<QWidget*> ModuleBase_WidgetLineEdit::getControls() const
85 QList<QWidget*> result;
90 void ModuleBase_WidgetLineEdit::onTextChanged()