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();
58 /// Perform completion by prefix
59 /// \param theCompletionPrefix a prefix for looking for completion
60 void performCompletion(const QString& theCompletionPrefix);
62 /// Redefinition of virtual method
63 /// \param theEvent a key press event
64 virtual void keyPressEvent(QKeyEvent* theEvent);
66 /// Key events processing
67 /// theEvent a key event
68 bool handledCompletedAndSelected(QKeyEvent* theEvent);
70 /// Redefinition of virtual method
71 virtual void paintEvent( QPaintEvent* );
74 QStringListModel* myCompleterModel;
75 QCompleter* myCompleter;
76 bool myCompletedAndSelected;
77 QString myPlaceHolderText;
82 * A Widget which provides an input of an expression
84 class MODULEBASE_EXPORT ModuleBase_WidgetExprEditor : public ModuleBase_ModelWidget
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();
99 /// Redefinition of virtual method
100 virtual QList<QWidget*> getControls() const;
103 /// A slot for processing text changed event
104 void onTextChanged();
107 /// Saves the internal parameters to the given feature
108 /// \return True in success
109 virtual bool storeValueCustom() const;
111 /// Redefinition of virtual method
112 virtual bool restoreValueCustom();
115 /// A line edit control
116 QLabel* myResultLabel;
117 ExpressionEditor* myEditor;
120 #endif /* MODULEBASE_WIDGETEXPREDITOR_H_ */