Salome HOME
Merge branch 'master' into cgt/devCEA
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetEditor.h
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #ifndef ModuleBase_WidgetEditor_H
22 #define ModuleBase_WidgetEditor_H
23
24 #include <ModuleBase.h>
25 #include "ModuleBase_WidgetDoubleValue.h"
26
27 #include <QObject>
28 #include <QStringList>
29
30 class ModelAPI_Feature;
31 class QDialog;
32 class QLineEdit;
33
34 /**\class ModuleBase_WidgetEditor
35  * \ingroup GUI
36  * \brief Custom widget. An abstract class to be redefined to fill with some GUI controls
37  */
38 class MODULEBASE_EXPORT ModuleBase_WidgetEditor : public ModuleBase_WidgetDoubleValue
39 {
40 Q_OBJECT
41  public:
42   /// Constructor
43   /// \param theParent the parent object
44   /// \param theData the widget configuation. The attribute of the model widget is obtained from
45   ModuleBase_WidgetEditor(QWidget* theParent, const Config_WidgetAPI* theData);
46   /// Constructor
47   /// \param theParent the parent object
48   /// \param theAttribute The attribute of the model widget
49   ModuleBase_WidgetEditor(QWidget* theParent, const std::string& theAttribute);
50
51   /// Destructor
52   virtual ~ModuleBase_WidgetEditor();
53
54   /// Set focus to the first control of the current widget.
55   /// The focus policy of the control is checked.
56   /// If the widget has the NonFocus focus policy, it is skipped.
57   /// \return the state whether the widget can accept the focus
58   virtual bool focusTo();
59
60   /// Shous popup window under cursor for data editing
61   /// \param theSendSignals a flag whether the signals should be sent or the value
62   /// is to be applyed directly
63   /// \return true if the editor value is accepted
64   bool showPopupEditor(const bool theSendSignals = true);
65
66   /// Set current cursor position
67   /// \param theX the X coordinate
68   /// \param theY the Y coordinate
69   void setCursorPosition(const int theX, const int theY);
70
71   /// Returns true if the event is processed.
72   virtual bool processEnter();
73
74 private:
75   /// Show editor
76   /// \param theOutValue a result value
77   /// \param theOutText a result text
78   /// \return true if the editor value is accepted
79   bool editedValue(double& theOutValue, QString& theOutText);
80
81  private:
82    ///< the current widget feature
83    FeaturePtr myFeature;
84
85    ///< the kinds of possible features
86    QStringList myFeatureKinds;
87
88    int myXPosition, myYPosition;
89
90    QDialog* myEditorDialog;
91 };
92
93 #endif