1 // File: ModuleBase_WidgetEditor.cpp
2 // Created: 25 Apr 2014
3 // Author: Natalia ERMOLAEVA
5 #include <ModuleBase_WidgetEditor.h>
7 #include <Config_Keywords.h>
8 #include <Config_WidgetAPI.h>
10 #include <Events_Loop.h>
11 #include <Model_Events.h>
13 #include <ModelAPI_Feature.h>
14 #include <ModelAPI_Data.h>
15 #include <ModelAPI_Object.h>
16 #include <ModelAPI_AttributeDouble.h>
18 #include <GeomDataAPI_Point2D.h>
26 ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent,
27 const Config_WidgetAPI* theData)
28 : ModuleBase_ModelWidget(theParent, theData), myValue(0)
32 ModuleBase_WidgetEditor::~ModuleBase_WidgetEditor()
37 bool ModuleBase_WidgetEditor::storeValue(FeaturePtr theFeature) const
39 DataPtr aData = theFeature->data();
40 AttributeDoublePtr aReal = aData->real(attributeID());
42 if (isOk && aReal->value() != myValue) {
43 aReal->setValue(myValue);
44 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
49 bool ModuleBase_WidgetEditor::restoreValue(FeaturePtr theFeature)
51 boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
52 AttributeDoublePtr aRef = aData->real(attributeID());
54 myValue = aRef->value();
58 void ModuleBase_WidgetEditor::focusTo()
60 QPoint aPoint = QCursor::pos();
63 aDlg.setWindowFlags(Qt::FramelessWindowHint);
64 QHBoxLayout* aLay = new QHBoxLayout(&aDlg);
65 aLay->setContentsMargins(0,0,0,0);
67 QLineEdit* aEditor = new QLineEdit(QString::number(myValue), &aDlg);
68 connect(aEditor, SIGNAL(returnPressed()), &aDlg, SLOT(accept()));
69 aLay->addWidget(aEditor);
72 int aRes = aDlg.exec();
74 if (aRes == QDialog::Accepted)
75 myValue = aEditor->text().toDouble();
77 emit focusOutWidget(this);
80 QWidget* ModuleBase_WidgetEditor::getControl() const
85 QList<QWidget*> ModuleBase_WidgetEditor::getControls() const
87 QList<QWidget*> aControls;