]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_WidgetExprEditor.h
Salome HOME
39ae9823546f07afd09c1960fe7ba6dd70f21c37
[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  protected:
58   /// Perform completion by prefix
59   /// \param theCompletionPrefix a prefix for looking for completion
60   void performCompletion(const QString& theCompletionPrefix);
61
62   /// Redefinition of virtual method
63   /// \param theEvent a key press event
64   virtual void keyPressEvent(QKeyEvent* theEvent);
65
66   /// Key events processing
67   /// theEvent a key event
68   bool handledCompletedAndSelected(QKeyEvent* theEvent);
69
70   /// Redefinition of virtual method
71   virtual void paintEvent( QPaintEvent* );
72
73  private:
74   QStringListModel* myCompleterModel;
75   QCompleter* myCompleter;
76   bool myCompletedAndSelected;
77   QString myPlaceHolderText;
78 };
79
80 /**
81 * \ingroup GUI
82 * A Widget which provides an input of an expression
83 */
84 class MODULEBASE_EXPORT ModuleBase_WidgetExprEditor : public ModuleBase_ModelWidget
85 {
86   Q_OBJECT
87  public:
88   /// Constructor
89   /// \param theParent the parent object
90   /// \param theData the widget configuration.
91   /// \param theParentId is Id of a parent of the current attribute
92   /// \param thePlaceHolder a placeholder string
93   ModuleBase_WidgetExprEditor( QWidget* theParent,
94                                const Config_WidgetAPI* theData,
95                                const std::string& theParentId,
96                                const std::string& thePlaceHolder );
97   virtual ~ModuleBase_WidgetExprEditor();
98
99   /// Redefinition of virtual method
100   virtual QList<QWidget*> getControls() const;
101
102  public slots:
103    /// A slot for processing text changed event
104   void onTextChanged();
105
106 protected:
107   /// Saves the internal parameters to the given feature
108   /// \return True in success
109   virtual bool storeValueCustom() const;
110
111   /// Redefinition of virtual method
112   virtual bool restoreValueCustom();
113
114 private:
115    /// A line edit control
116   QLabel* myResultLabel;
117   ExpressionEditor* myEditor;
118 };
119
120 #endif /* MODULEBASE_WIDGETEXPREDITOR_H_ */