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>
23 ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent,
24 const Config_WidgetAPI* theData)
25 : ModuleBase_ModelWidget(theParent, theData)
27 myEditor = new QLineEdit(0);
28 myEditor->setWindowFlags(Qt::ToolTip);
29 myEditor->setFocusPolicy(Qt::StrongFocus);
31 connect(myEditor, SIGNAL(returnPressed()), this, SLOT(onStopEditing()));
32 connect(myEditor, SIGNAL(textChanged(const QString&)), this, SIGNAL(valuesChanged()));
35 ModuleBase_WidgetEditor::~ModuleBase_WidgetEditor()
40 bool ModuleBase_WidgetEditor::storeValue(FeaturePtr theFeature) const
42 DataPtr aData = theFeature->data();
43 AttributeDoublePtr aReal = aData->real(attributeID());
45 double aValue = myEditor->text().toDouble(&isOk);
46 if (isOk && aReal->value() != aValue) {
47 //ModuleBase_WidgetPoint2D* that = (ModuleBase_WidgetPoint2D*) this;
48 //bool isBlocked = that->blockSignals(true);
49 aReal->setValue(aValue);
50 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
51 //that->blockSignals(isBlocked);
56 bool ModuleBase_WidgetEditor::restoreValue(FeaturePtr theFeature)
58 boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
59 AttributeDoublePtr aRef = aData->real(attributeID());
61 //bool isBlocked = this->blockSignals(true);
62 myEditor->setText(QString::number(aRef->value()));
63 //this->blockSignals(isBlocked);
67 void ModuleBase_WidgetEditor::focusTo()
69 QPoint aPoint = QCursor::pos();
71 myEditor->move(aPoint);
74 myEditor->selectAll();
78 QWidget* ModuleBase_WidgetEditor::getControl() const
83 QList<QWidget*> ModuleBase_WidgetEditor::getControls() const
85 QList<QWidget*> aControls;
89 void ModuleBase_WidgetEditor::onStopEditing()
92 emit focusOutWidget(this);