1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: ModuleBase_WidgetEditor.cpp
4 // Created: 25 Apr 2014
5 // Author: Natalia ERMOLAEVA
7 #include <ModuleBase_WidgetEditor.h>
8 #include <ModuleBase_DoubleSpinBox.h>
9 #include <ModuleBase_Tools.h>
11 #include <Config_Keywords.h>
12 #include <Config_WidgetAPI.h>
14 #include <Events_Loop.h>
15 #include <ModelAPI_Events.h>
17 #include <ModelAPI_Feature.h>
18 #include <ModelAPI_Data.h>
19 #include <ModelAPI_Object.h>
20 #include <ModelAPI_AttributeDouble.h>
22 #include <GeomDataAPI_Point2D.h>
29 #include <QApplication>
31 ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent,
32 const Config_WidgetAPI* theData,
33 const std::string& theParentId)
34 : ModuleBase_WidgetDoubleValue(theParent, theData, theParentId)
38 ModuleBase_WidgetEditor::~ModuleBase_WidgetEditor()
42 double editedValue(double theValue, bool& isDone)
45 aDlg.setWindowFlags(Qt::FramelessWindowHint);
46 QHBoxLayout* aLay = new QHBoxLayout(&aDlg);
47 ModuleBase_Tools::zeroMargins(aLay);
49 QLineEdit* aEditor = new QLineEdit(QString::number(theValue), &aDlg);
50 aEditor->setValidator(new QDoubleValidator(aEditor));
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 // We can not launch here modal process for value editing because
67 // it can be called on other focusOutWidget event and will block it
68 QTimer::singleShot(1, this, SLOT(showPopupEditor()));
72 void ModuleBase_WidgetEditor::showPopupEditor()
74 // White while all events will be processed
75 QApplication::processEvents();
76 double aValue = mySpinBox->value();
78 aValue = editedValue(aValue, isDone);
81 bool isBlocked = mySpinBox->blockSignals(true);
82 mySpinBox->setValue(aValue);
83 mySpinBox->blockSignals(isBlocked);
86 emit focusOutWidget(this);
89 void ModuleBase_WidgetEditor::editFeatureValue(FeaturePtr theFeature,
90 const std::string theAttribute)
92 DataPtr aData = theFeature->data();
93 AttributeDoublePtr aRef = aData->real(theAttribute);
94 double aValue = aRef->value();
97 aValue = editedValue(aValue, isDone);
99 aRef->setValue(aValue);