1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
4 * ModuleBase_WidgetExprEditor.h
6 * Created on: Oct 8, 2014
10 #ifndef MODULEBASE_WIDGETEXPREDITOR_H_
11 #define MODULEBASE_WIDGETEXPREDITOR_H_
13 #include <ModuleBase.h>
14 #include <ModuleBase_ModelWidget.h>
19 #include <QStringList>
20 #include <QPlainTextEdit>
23 class QStringListModel;
28 * A multi-line text editor which lets to input formula and provides a list of completion strings
30 class ExpressionEditor: public QPlainTextEdit
35 /// \param theParent a parent widget
36 explicit ExpressionEditor(QWidget* theParent = 0);
37 virtual ~ExpressionEditor();
39 /// Set list of completion strings
40 void setCompletionList(QStringList&);
42 /// Set a text which will be shown when the listr is empty
43 void setPlaceHolderText( const QString& );
45 /// Returns placeholder list
46 QString placeHolderText() const;
48 // Returns true if the current value is modified by has not been applyed yet
49 bool isModified() const;
51 // Clears modified state
55 /// Insert additional string for completion
56 /// \param theCompletion a string to insert
57 /// \param isSingleWord a flag shows that inserted string is single word or not
58 void insertCompletion(const QString& theCompletion, bool isSingleWord = false);
60 /// Perform completion
61 void performCompletion();
63 /// A slot for processing text changed event
68 /// A signal that is emitted by the "Tab" key event. It is emitted before the key is processed.
72 /// The signal about key release on the control, that corresponds to the attribute
73 /// \param theEvent key release event
74 void keyReleased(QKeyEvent* theEvent);
77 /// Perform completion by prefix
78 /// \param theCompletionPrefix a prefix for looking for completion
79 void performCompletion(const QString& theCompletionPrefix);
81 /// Redefinition of virtual method
82 /// \param theEvent a key press event
83 virtual void keyPressEvent(QKeyEvent* theEvent);
85 /// Key events processing
86 /// theEvent a key event
87 bool handledCompletedAndSelected(QKeyEvent* theEvent);
89 /// Redefinition of virtual method
90 virtual void paintEvent( QPaintEvent* );
92 /// The parent method that processes the "Tab"/"SHIF + Tab" keyboard events
93 /// Emits a signal about focus change
94 /// If theIsNext is true, this function searches forward, if next is false, it searches backward.
95 virtual bool focusNextPrevChild(bool theIsNext);
98 QStringListModel* myCompleterModel;
99 QCompleter* myCompleter;
100 bool myCompletedAndSelected;
101 QString myPlaceHolderText;
103 /// Boolean value whether the spin box content is modified
109 * A Widget which provides an input of an expression
111 class MODULEBASE_EXPORT ModuleBase_WidgetExprEditor : public ModuleBase_ModelWidget
116 /// \param theParent the parent object
117 /// \param theData the widget configuration.
118 /// \param theParentId is Id of a parent of the current attribute
119 /// \param thePlaceHolder a placeholder string
120 ModuleBase_WidgetExprEditor( QWidget* theParent,
121 const Config_WidgetAPI* theData,
122 const std::string& theParentId,
123 const std::string& thePlaceHolder );
124 virtual ~ModuleBase_WidgetExprEditor();
126 /// Redefinition of virtual method
127 virtual QList<QWidget*> getControls() const;
129 /// Returns true if the event is processed.
130 virtual bool processEnter();
133 /// A slot for processing text changed event
134 void onTextChanged();
137 /// Do not initialize value on the widget activation
138 virtual void initializeValueByActivate();
140 /// Saves the internal parameters to the given feature
141 /// \return True in success
142 virtual bool storeValueCustom() const;
144 /// Redefinition of virtual method
145 virtual bool restoreValueCustom();
148 /// A line edit control
149 QLabel* myResultLabel;
150 ExpressionEditor* myEditor;
153 #endif /* MODULEBASE_WIDGETEXPREDITOR_H_ */