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);
51 aEditor->setValidator(new QDoubleValidator(aEditor));
52 QObject::connect(aEditor, SIGNAL(returnPressed()), &aDlg, SLOT(accept()));
53 aLay->addWidget(aEditor);
55 QPoint aPoint = QCursor::pos();
58 isDone = aDlg.exec() == QDialog::Accepted;
59 double aValue = theValue;
61 aValue = aEditor->text().toDouble();
65 bool ModuleBase_WidgetEditor::focusTo()
67 // We can not launch here modal process for value editing because
68 // it can be called on other focusOutWidget event and will block it
69 QTimer::singleShot(1, this, SLOT(showPopupEditor()));
73 void ModuleBase_WidgetEditor::showPopupEditor()
75 // White while all events will be processed
76 QApplication::processEvents();
77 double aValue = mySpinBox->value();
79 aValue = editedValue(aValue, isDone);
82 ModuleBase_Tools::setSpinValue(mySpinBox, aValue);
85 emit focusOutWidget(this);
88 void ModuleBase_WidgetEditor::editFeatureValue(FeaturePtr theFeature,
89 const std::string theAttribute)
91 DataPtr aData = theFeature->data();
92 AttributeDoublePtr aRef = aData->real(theAttribute);
93 double aValue = aRef->value();
96 aValue = editedValue(aValue, isDone);
98 aRef->setValue(aValue);