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;
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);
54 /// Perform completion
55 void performCompletion();
57 /// A slot for processing text changed event
61 /// The signal about text change in the text editor
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);
70 /// Perform completion by prefix
71 /// \param theCompletionPrefix a prefix for looking for completion
72 void performCompletion(const QString& theCompletionPrefix);
74 /// Redefinition of virtual method
75 /// \param theEvent a key press event
76 virtual void keyPressEvent(QKeyEvent* theEvent);
78 /// Key events processing
79 /// theEvent a key event
80 bool handledCompletedAndSelected(QKeyEvent* theEvent);
82 /// Redefinition of virtual method
83 virtual void paintEvent( QPaintEvent* );
86 QStringListModel* myCompleterModel;
87 QCompleter* myCompleter;
88 bool myCompletedAndSelected;
89 QString myPlaceHolderText;
94 * A Widget which provides an input of an expression
96 class MODULEBASE_EXPORT ModuleBase_WidgetExprEditor : public ModuleBase_ModelWidget
101 /// \param theParent the parent object
102 /// \param theData the widget configuration.
103 /// \param theParentId is Id of a parent of the current attribute
104 /// \param thePlaceHolder a placeholder string
105 ModuleBase_WidgetExprEditor( QWidget* theParent,
106 const Config_WidgetAPI* theData,
107 const std::string& thePlaceHolder );
108 virtual ~ModuleBase_WidgetExprEditor();
110 /// The methiod called when widget is activated
111 virtual void activateCustom();
113 /// Redefinition of virtual method
114 virtual QList<QWidget*> getControls() const;
116 /// Returns true if the event is processed.
117 virtual bool processEnter();
120 /// A slot for processing text changed event
121 void onTextChanged();
124 /// Do not initialize value on the widget activation
125 virtual void initializeValueByActivate();
127 /// Saves the internal parameters to the given feature
128 /// \return True in success
129 virtual bool storeValueCustom() const;
131 /// Redefinition of virtual method
132 virtual bool restoreValueCustom();
135 /// A line edit control
136 QLabel* myResultLabel;
137 ExpressionEditor* myEditor;
140 #endif /* MODULEBASE_WIDGETEXPREDITOR_H_ */