1 // Copyright (C) 2014-2017 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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #ifndef MODULEBASE_WIDGETEXPREDITOR_H_
22 #define MODULEBASE_WIDGETEXPREDITOR_H_
24 #include <ModuleBase.h>
25 #include <ModuleBase_ModelWidget.h>
30 #include <QStringList>
31 #include <QPlainTextEdit>
34 class QStringListModel;
39 * A multi-line text editor which lets to input formula and provides a list of completion strings
41 class ExpressionEditor: public QPlainTextEdit
46 /// \param theParent a parent widget
47 explicit ExpressionEditor(QWidget* theParent = 0);
48 virtual ~ExpressionEditor();
50 /// Set list of completion strings
51 void setCompletionList(QStringList&);
53 /// Set a text which will be shown when the listr is empty
54 void setPlaceHolderText( const QString& );
56 /// Returns placeholder list
57 QString placeHolderText() const;
60 /// Insert additional string for completion
61 /// \param theCompletion a string to insert
62 /// \param isSingleWord a flag shows that inserted string is single word or not
63 void insertCompletion(const QString& theCompletion, bool isSingleWord = false);
65 /// Perform completion
66 void performCompletion();
68 /// A slot for processing text changed event
72 /// The signal about text change in the text editor
75 /// The signal about key release on the control, that corresponds to the attribute
76 /// \param theObject a sender of the event
77 /// \param theEvent key release event
78 void keyReleased(QObject* theObject, QKeyEvent* theEvent);
81 /// Perform completion by prefix
82 /// \param theCompletionPrefix a prefix for looking for completion
83 void performCompletion(const QString& theCompletionPrefix);
85 /// Redefinition of virtual method
86 /// \param theEvent a key press event
87 virtual void keyPressEvent(QKeyEvent* theEvent);
89 /// Key events processing
90 /// theEvent a key event
91 bool handledCompletedAndSelected(QKeyEvent* theEvent);
93 /// Redefinition of virtual method
94 virtual void paintEvent( QPaintEvent* );
97 QStringListModel* myCompleterModel;
98 QCompleter* myCompleter;
99 bool myCompletedAndSelected;
100 QString myPlaceHolderText;
105 * A Widget which provides an input of an expression
107 class MODULEBASE_EXPORT ModuleBase_WidgetExprEditor : public ModuleBase_ModelWidget
112 /// \param theParent the parent object
113 /// \param theData the widget configuration.
114 /// \param thePlaceHolder a placeholder string
115 ModuleBase_WidgetExprEditor( QWidget* theParent,
116 const Config_WidgetAPI* theData,
117 const std::string& thePlaceHolder );
118 virtual ~ModuleBase_WidgetExprEditor();
120 /// The methiod called when widget is activated
121 virtual void activateCustom();
123 /// Redefinition of virtual method
124 virtual QList<QWidget*> getControls() const;
127 /// A slot for processing text changed event
128 void onTextChanged();
131 /// Returns true if the event is processed.
132 virtual bool processEnter();
134 /// Do not initialize value on the widget activation
135 virtual void initializeValueByActivate();
137 /// Saves the internal parameters to the given feature
138 /// \return True in success
139 virtual bool storeValueCustom();
141 /// Redefinition of virtual method
142 virtual bool restoreValueCustom();
145 /// A line edit control
146 QLabel* myResultLabel;
147 ExpressionEditor* myEditor;
150 #endif /* MODULEBASE_WIDGETEXPREDITOR_H_ */