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>
27 #include <QApplication>
29 ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent,
30 const Config_WidgetAPI* theData,
31 const std::string& theParentId)
32 : ModuleBase_WidgetDoubleValue(theParent, theData, theParentId)
36 ModuleBase_WidgetEditor::~ModuleBase_WidgetEditor()
40 double editedValue(double theValue, bool& isDone)
43 aDlg.setWindowFlags(Qt::FramelessWindowHint);
44 QHBoxLayout* aLay = new QHBoxLayout(&aDlg);
45 ModuleBase_Tools::zeroMargins(aLay);
47 QLineEdit* aEditor = new QLineEdit(QString::number(theValue), &aDlg);
48 aEditor->setValidator(new QDoubleValidator(aEditor));
49 QObject::connect(aEditor, SIGNAL(returnPressed()), &aDlg, SLOT(accept()));
50 aLay->addWidget(aEditor);
52 QPoint aPoint = QCursor::pos();
55 isDone = aDlg.exec() == QDialog::Accepted;
56 double aValue = theValue;
58 aValue = aEditor->text().toDouble();
62 bool ModuleBase_WidgetEditor::focusTo()
64 // We can not launch here modal process for value editing because
65 // it can be called on other focusOutWidget event and will block it
66 QTimer::singleShot(1, this, SLOT(showPopupEditor()));
70 void ModuleBase_WidgetEditor::showPopupEditor()
72 // White while all events will be processed
73 QApplication::processEvents();
74 double aValue = mySpinBox->value();
76 aValue = editedValue(aValue, isDone);
79 bool isBlocked = mySpinBox->blockSignals(true);
80 mySpinBox->setValue(aValue);
81 mySpinBox->blockSignals(isBlocked);
84 emit focusOutWidget(this);
87 void ModuleBase_WidgetEditor::editFeatureValue(FeaturePtr theFeature,
88 const std::string theAttribute)
90 DataPtr aData = theFeature->data();
91 AttributeDoublePtr aRef = aData->real(theAttribute);
92 double aValue = aRef->value();
95 aValue = editedValue(aValue, isDone);
97 aRef->setValue(aValue);