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(QWidget* theParent, const std::string& theAttribute)
33 : ModuleBase_ModelWidget(theParent, 0), myValue(0)
35 this->setAttributeID(theAttribute);
38 ModuleBase_WidgetEditor::~ModuleBase_WidgetEditor()
42 bool ModuleBase_WidgetEditor::storeValue(FeaturePtr theFeature) const
44 DataPtr aData = theFeature->data();
45 AttributeDoublePtr aReal = aData->real(attributeID());
46 if (aReal->value() != myValue) {
47 aReal->setValue(myValue);
48 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
53 bool ModuleBase_WidgetEditor::restoreValue(FeaturePtr theFeature)
55 boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
56 AttributeDoublePtr aRef = aData->real(attributeID());
58 myValue = aRef->value();
62 void ModuleBase_WidgetEditor::focusTo()
64 QPoint aPoint = QCursor::pos();
67 aDlg.setWindowFlags(Qt::FramelessWindowHint);
68 QHBoxLayout* aLay = new QHBoxLayout(&aDlg);
69 aLay->setContentsMargins(0,0,0,0);
71 QLineEdit* aEditor = new QLineEdit(QString::number(myValue), &aDlg);
72 connect(aEditor, SIGNAL(returnPressed()), &aDlg, SLOT(accept()));
73 aLay->addWidget(aEditor);
76 int aRes = aDlg.exec();
78 if (aRes == QDialog::Accepted)
79 myValue = aEditor->text().toDouble();
82 emit focusOutWidget(this);
85 QWidget* ModuleBase_WidgetEditor::getControl() const
90 QList<QWidget*> ModuleBase_WidgetEditor::getControls() const
92 QList<QWidget*> aControls;
96 void ModuleBase_WidgetEditor::editFeatureValue(FeaturePtr theFeature, const std::string theAttribute)
98 ModuleBase_WidgetEditor anEditor(0, theAttribute);
100 anEditor.restoreValue(theFeature);
102 anEditor.storeValue(theFeature);