1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef MODULEBASE_WIDGETEXPREDITOR_H_
21 #define MODULEBASE_WIDGETEXPREDITOR_H_
23 #include <ModuleBase.h>
24 #include <ModuleBase_ModelWidget.h>
29 #include <QStringList>
30 #include <QPlainTextEdit>
33 class QStringListModel;
38 * A multi-line text editor which lets to input formula and provides a list of completion strings
40 class ExpressionEditor: public QPlainTextEdit
45 /// \param theParent a parent widget
46 explicit ExpressionEditor(QWidget* theParent = 0);
47 virtual ~ExpressionEditor();
49 /// Set list of completion strings
50 void setCompletionList(QStringList&);
52 /// Set a text which will be shown when the listr is empty
53 void setPlaceHolderText( const QString& );
55 /// Returns placeholder list
56 QString placeHolderText() const;
59 /// Insert additional string for completion
60 /// \param theCompletion a string to insert
61 /// \param isSingleWord a flag shows that inserted string is single word or not
62 void insertCompletion(const QString& theCompletion, bool isSingleWord = false);
64 /// Perform completion
65 void performCompletion();
67 /// A slot for processing text changed event
71 /// The signal about text change in the text editor
74 /// The signal about key release on the control, that corresponds to the attribute
75 /// \param theObject a sender of the event
76 /// \param theEvent key release event
77 void keyReleased(QObject* theObject, QKeyEvent* theEvent);
80 /// Perform completion by prefix
81 /// \param theCompletionPrefix a prefix for looking for completion
82 void performCompletion(const QString& theCompletionPrefix);
84 /// Redefinition of virtual method
85 /// \param theEvent a key press event
86 virtual void keyPressEvent(QKeyEvent* theEvent);
88 /// Key events processing
89 /// theEvent a key event
90 bool handledCompletedAndSelected(QKeyEvent* theEvent);
92 /// Redefinition of virtual method
93 virtual void paintEvent( QPaintEvent* );
96 QStringListModel* myCompleterModel;
97 QCompleter* myCompleter;
98 bool myCompletedAndSelected;
99 QString myPlaceHolderText;
104 * A Widget which provides an input of an expression
106 class MODULEBASE_EXPORT ModuleBase_WidgetExprEditor : public ModuleBase_ModelWidget
111 /// \param theParent the parent object
112 /// \param theData the widget configuration.
113 /// \param thePlaceHolder a placeholder string
114 ModuleBase_WidgetExprEditor( QWidget* theParent,
115 const Config_WidgetAPI* theData,
116 const std::string& thePlaceHolder );
117 virtual ~ModuleBase_WidgetExprEditor();
119 /// The methiod called when widget is activated
120 virtual void activateCustom();
122 /// Redefinition of virtual method
123 virtual QList<QWidget*> getControls() const;
126 /// A slot for processing text changed event
127 void onTextChanged();
130 /// Returns true if the event is processed.
131 virtual bool processEnter();
133 /// Do not initialize value on the widget activation
134 virtual void initializeValueByActivate();
136 /// Saves the internal parameters to the given feature
137 /// \return True in success
138 virtual bool storeValueCustom();
140 /// Redefinition of virtual method
141 virtual bool restoreValueCustom();
144 /// A line edit control
145 QLabel* myResultLabel;
146 ExpressionEditor* myEditor;
149 #endif /* MODULEBASE_WIDGETEXPREDITOR_H_ */