1 // File: ModuleBase_WidgetEditor.cpp
2 // Created: 25 Apr 2014
3 // Author: Natalia ERMOLAEVA
5 #include <ModuleBase_WidgetEditor.h>
6 #include <ModuleBase_DoubleSpinBox.h>
7 #include <ModuleBase_Tools.h>
9 #include <Config_Keywords.h>
10 #include <Config_WidgetAPI.h>
12 #include <Events_Loop.h>
13 #include <ModelAPI_Events.h>
15 #include <ModelAPI_Feature.h>
16 #include <ModelAPI_Data.h>
17 #include <ModelAPI_Object.h>
18 #include <ModelAPI_AttributeDouble.h>
20 #include <GeomDataAPI_Point2D.h>
28 ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent,
29 const Config_WidgetAPI* theData,
30 const std::string& theParentId)
31 : ModuleBase_WidgetDoubleValue(theParent, theData, theParentId)
35 ModuleBase_WidgetEditor::~ModuleBase_WidgetEditor()
39 double editedValue(double theValue, bool& isDone)
42 aDlg.setWindowFlags(Qt::FramelessWindowHint);
43 QHBoxLayout* aLay = new QHBoxLayout(&aDlg);
44 ModuleBase_Tools::zeroMargins(aLay);
46 QLineEdit* aEditor = new QLineEdit(QString::number(theValue), &aDlg);
47 aEditor->setValidator(new QDoubleValidator(aEditor));
48 QObject::connect(aEditor, SIGNAL(returnPressed()), &aDlg, SLOT(accept()));
49 aLay->addWidget(aEditor);
51 QPoint aPoint = QCursor::pos();
54 isDone = aDlg.exec() == QDialog::Accepted;
55 double aValue = theValue;
57 aValue = aEditor->text().toDouble();
61 bool ModuleBase_WidgetEditor::focusTo()
63 double aValue = mySpinBox->value();
65 aValue = editedValue(aValue, isDone);
68 bool isBlocked = mySpinBox->blockSignals(true);
69 mySpinBox->setValue(aValue);
70 mySpinBox->blockSignals(isBlocked);
73 emit focusOutWidget(this);
78 void ModuleBase_WidgetEditor::editFeatureValue(FeaturePtr theFeature,
79 const std::string theAttribute)
81 DataPtr aData = theFeature->data();
82 AttributeDoublePtr aRef = aData->real(theAttribute);
83 double aValue = aRef->value();
86 aValue = editedValue(aValue, isDone);
88 aRef->setValue(aValue);