]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_WidgetEditor.cpp
Salome HOME
Merge remote-tracking branch 'remotes/origin/master' into SketchSolver
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetEditor.cpp
1 // File:        ModuleBase_WidgetEditor.cpp
2 // Created:     25 Apr 2014
3 // Author:      Natalia ERMOLAEVA
4
5 #include <ModuleBase_WidgetEditor.h>
6
7 #include <Config_Keywords.h>
8 #include <Config_WidgetAPI.h>
9
10 #include <Events_Loop.h>
11 #include <Model_Events.h>
12
13 #include <ModelAPI_Feature.h>
14 #include <ModelAPI_Data.h>
15 #include <ModelAPI_Object.h>
16 #include <ModelAPI_AttributeDouble.h>
17
18 #include <GeomDataAPI_Point2D.h>
19
20 #include <QWidget>
21 #include <QLineEdit>
22
23 ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent,
24                                                  const Config_WidgetAPI* theData)
25 : ModuleBase_ModelWidget(theParent, theData)
26 {
27   myEditor = new QLineEdit(0);
28   myEditor->setWindowFlags(Qt::ToolTip);
29   myEditor->setFocusPolicy(Qt::StrongFocus);
30
31   connect(myEditor, SIGNAL(returnPressed()), this, SLOT(onStopEditing()));
32   connect(myEditor, SIGNAL(textChanged(const QString&)), this, SIGNAL(valuesChanged()));
33 }
34
35 ModuleBase_WidgetEditor::~ModuleBase_WidgetEditor()
36 {
37   delete myEditor;
38 }
39
40 bool ModuleBase_WidgetEditor::storeValue(FeaturePtr theFeature) const
41 {
42   DataPtr aData = theFeature->data();
43   AttributeDoublePtr aReal = aData->real(attributeID());
44   bool isOk;
45   double aValue = myEditor->text().toDouble(&isOk);
46   if (isOk && aReal->value() != aValue) {
47     //ModuleBase_WidgetPoint2D* that = (ModuleBase_WidgetPoint2D*) this;
48     //bool isBlocked = that->blockSignals(true);
49     aReal->setValue(aValue);
50     Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
51     //that->blockSignals(isBlocked);
52   }
53   return true;
54 }
55
56 bool ModuleBase_WidgetEditor::restoreValue(FeaturePtr theFeature)
57 {
58   boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
59   AttributeDoublePtr aRef = aData->real(attributeID());
60
61   //bool isBlocked = this->blockSignals(true);
62   myEditor->setText(QString::number(aRef->value()));
63   //this->blockSignals(isBlocked);
64   return true;
65 }
66
67 void ModuleBase_WidgetEditor::focusTo()
68 {
69   QPoint aPoint = QCursor::pos();
70
71   myEditor->move(aPoint);
72   myEditor->show();
73
74   myEditor->selectAll();
75   myEditor->setFocus();
76 }
77
78 QWidget* ModuleBase_WidgetEditor::getControl() const
79 {
80   return 0;
81 }
82
83 QList<QWidget*> ModuleBase_WidgetEditor::getControls() const
84 {
85   QList<QWidget*> aControls;
86   return aControls;
87 }
88
89 void ModuleBase_WidgetEditor::onStopEditing()
90 {
91   myEditor->hide();
92   emit focusOutWidget(this);
93 }