Salome HOME
Show tool tip of shape multi selector. Remove an article.
[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 theEvent key release event
66   void keyReleased(QKeyEvent* theEvent);
67
68  protected:
69   /// Perform completion by prefix
70   /// \param theCompletionPrefix a prefix for looking for completion
71   void performCompletion(const QString& theCompletionPrefix);
72
73   /// Redefinition of virtual method
74   /// \param theEvent a key press event
75   virtual void keyPressEvent(QKeyEvent* theEvent);
76
77   /// Key events processing
78   /// theEvent a key event
79   bool handledCompletedAndSelected(QKeyEvent* theEvent);
80
81   /// Redefinition of virtual method
82   virtual void paintEvent( QPaintEvent* );
83
84 private:
85   QStringListModel* myCompleterModel;
86   QCompleter* myCompleter;
87   bool myCompletedAndSelected;
88   QString myPlaceHolderText;
89 };
90
91 /**
92 * \ingroup GUI
93 * A Widget which provides an input of an expression
94 */
95 class MODULEBASE_EXPORT ModuleBase_WidgetExprEditor : public ModuleBase_ModelWidget
96 {
97   Q_OBJECT
98  public:
99   /// Constructor
100   /// \param theParent the parent object
101   /// \param theData the widget configuration.
102   /// \param theParentId is Id of a parent of the current attribute
103   /// \param thePlaceHolder a placeholder string
104   ModuleBase_WidgetExprEditor( QWidget* theParent,
105                                const Config_WidgetAPI* theData,
106                                const std::string& theParentId,
107                                const std::string& thePlaceHolder );
108   virtual ~ModuleBase_WidgetExprEditor();
109
110   /// Redefinition of virtual method
111   virtual QList<QWidget*> getControls() const;
112
113   /// Returns true if the event is processed.
114   virtual bool processEnter();
115
116 protected slots:
117   /// A slot for processing text changed event
118   void onTextChanged();
119
120 protected:
121   /// Do not initialize value on the widget activation
122   virtual void initializeValueByActivate();
123
124   /// Saves the internal parameters to the given feature
125   /// \return True in success
126   virtual bool storeValueCustom() const;
127
128   /// Redefinition of virtual method
129   virtual bool restoreValueCustom();
130
131 private:
132    /// A line edit control
133   QLabel* myResultLabel;
134   ExpressionEditor* myEditor;
135 };
136
137 #endif /* MODULEBASE_WIDGETEXPREDITOR_H_ */