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>
25 #include <QDoubleSpinBox>
27 ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent,
28 const Config_WidgetAPI* theData)
29 : ModuleBase_WidgetDoubleValue(theParent, theData)
33 ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent, const std::string& theAttribute)
34 : ModuleBase_WidgetDoubleValue(theParent, 0)
36 setAttributeID(theAttribute);
39 ModuleBase_WidgetEditor::~ModuleBase_WidgetEditor()
43 double editedValue(double theValue, bool& isDone)
46 aDlg.setWindowFlags(Qt::FramelessWindowHint);
47 QHBoxLayout* aLay = new QHBoxLayout(&aDlg);
48 aLay->setContentsMargins(0,0,0,0);
50 QLineEdit* aEditor = new QLineEdit(QString::number(theValue), &aDlg);
51 QObject::connect(aEditor, SIGNAL(returnPressed()), &aDlg, SLOT(accept()));
52 aLay->addWidget(aEditor);
54 QPoint aPoint = QCursor::pos();
57 isDone = aDlg.exec() == QDialog::Accepted;
58 double aValue = theValue;
60 aValue = aEditor->text().toDouble();
64 bool ModuleBase_WidgetEditor::focusTo()
66 double aValue = mySpinBox->value();
68 aValue = editedValue(aValue, isDone);
71 bool isBlocked = mySpinBox->blockSignals(true);
72 mySpinBox->setValue(aValue);
73 mySpinBox->blockSignals(isBlocked);
76 emit focusOutWidget(this);
81 void ModuleBase_WidgetEditor::editFeatureValue(FeaturePtr theFeature, const std::string theAttribute)
83 DataPtr aData = theFeature->data();
84 AttributeDoublePtr aRef = aData->real(theAttribute);
85 double aValue = aRef->value();
88 aValue = editedValue(aValue, isDone);
90 aRef->setValue(aValue);