Salome HOME
Improvement for key "Delete" processing: should be done only on possible objects...
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetExprEditor.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 /*
4  * ModuleBase_WidgetExprEditor.h
5  *
6  *  Created on: Oct 8, 2014
7  *      Author: sbh
8  */
9
10 #ifndef MODULEBASE_WIDGETEXPREDITOR_H_
11 #define MODULEBASE_WIDGETEXPREDITOR_H_
12
13 #include <ModuleBase.h>
14 #include <ModuleBase_ModelWidget.h>
15
16 #include <QList>
17 #include <QLabel>
18 #include <QString>
19 #include <QStringList>
20 #include <QPlainTextEdit>
21
22 class QWidget;
23 class QStringListModel;
24 class QCompleter;
25
26 /**
27 * \ingroup GUI
28 * A multi-line text editor which lets to input formula and provides a list of completion strings
29 */
30 class ExpressionEditor: public QPlainTextEdit
31 {
32   Q_OBJECT
33  public:
34    /// Constructor
35    /// \param theParent a parent widget
36   explicit ExpressionEditor(QWidget* theParent = 0);
37   virtual ~ExpressionEditor();
38
39   /// Set list of completion strings
40   void setCompletionList(QStringList&);
41
42   /// Set a text which will be shown when the listr is empty
43   void setPlaceHolderText( const QString& );
44
45   /// Returns placeholder list
46   QString placeHolderText() const;
47
48  public slots:
49   /// Insert additional string for completion
50   /// \param theCompletion a string to insert
51   /// \param isSingleWord a flag shows that inserted string is single word or not
52   void insertCompletion(const QString& theCompletion, bool isSingleWord = false);
53
54   /// Perform completion
55   void performCompletion();
56
57   /// A slot for processing text changed event
58   void onTextChanged();
59
60 signals:
61   /// The signal about text change in the text editor
62   void valueModified();
63
64   /// The signal about key release on the control, that corresponds to the attribute
65   /// \param theObject a sender of the event
66   /// \param theEvent key release event
67   void keyReleased(QObject* theObject, QKeyEvent* theEvent);
68
69  protected:
70   /// Perform completion by prefix
71   /// \param theCompletionPrefix a prefix for looking for completion
72   void performCompletion(const QString& theCompletionPrefix);
73
74   /// Redefinition of virtual method
75   /// \param theEvent a key press event
76   virtual void keyPressEvent(QKeyEvent* theEvent);
77
78   /// Key events processing
79   /// theEvent a key event
80   bool handledCompletedAndSelected(QKeyEvent* theEvent);
81
82   /// Redefinition of virtual method
83   virtual void paintEvent( QPaintEvent* );
84
85 private:
86   QStringListModel* myCompleterModel;
87   QCompleter* myCompleter;
88   bool myCompletedAndSelected;
89   QString myPlaceHolderText;
90 };
91
92 /**
93 * \ingroup GUI
94 * A Widget which provides an input of an expression
95 */
96 class MODULEBASE_EXPORT ModuleBase_WidgetExprEditor : public ModuleBase_ModelWidget
97 {
98   Q_OBJECT
99  public:
100   /// Constructor
101   /// \param theParent the parent object
102   /// \param theData the widget configuration.
103   /// \param thePlaceHolder a placeholder string
104   ModuleBase_WidgetExprEditor( QWidget* theParent,
105                                const Config_WidgetAPI* theData,
106                                const std::string& thePlaceHolder );
107   virtual ~ModuleBase_WidgetExprEditor();
108
109   /// The methiod called when widget is activated
110   virtual void activateCustom();
111
112   /// Redefinition of virtual method
113   virtual QList<QWidget*> getControls() const;
114
115   /// Returns true if the event is processed.
116   virtual bool processEnter();
117
118 protected slots:
119   /// A slot for processing text changed event
120   void onTextChanged();
121
122 protected:
123   /// Do not initialize value on the widget activation
124   virtual void initializeValueByActivate();
125
126   /// Saves the internal parameters to the given feature
127   /// \return True in success
128   virtual bool storeValueCustom();
129
130   /// Redefinition of virtual method
131   virtual bool restoreValueCustom();
132
133 private:
134    /// A line edit control
135   QLabel* myResultLabel;
136   ExpressionEditor* myEditor;
137 };
138
139 #endif /* MODULEBASE_WIDGETEXPREDITOR_H_ */