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 email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 * ModuleBase_WidgetExprEditor.h
23 * Created on: Oct 8, 2014
27 #ifndef MODULEBASE_WIDGETEXPREDITOR_H_
28 #define MODULEBASE_WIDGETEXPREDITOR_H_
30 #include <ModuleBase.h>
31 #include <ModuleBase_ModelWidget.h>
36 #include <QStringList>
37 #include <QPlainTextEdit>
40 class QStringListModel;
45 * A multi-line text editor which lets to input formula and provides a list of completion strings
47 class ExpressionEditor: public QPlainTextEdit
52 /// \param theParent a parent widget
53 explicit ExpressionEditor(QWidget* theParent = 0);
54 virtual ~ExpressionEditor();
56 /// Set list of completion strings
57 void setCompletionList(QStringList&);
59 /// Set a text which will be shown when the listr is empty
60 void setPlaceHolderText( const QString& );
62 /// Returns placeholder list
63 QString placeHolderText() const;
66 /// Insert additional string for completion
67 /// \param theCompletion a string to insert
68 /// \param isSingleWord a flag shows that inserted string is single word or not
69 void insertCompletion(const QString& theCompletion, bool isSingleWord = false);
71 /// Perform completion
72 void performCompletion();
74 /// A slot for processing text changed event
78 /// The signal about text change in the text editor
81 /// The signal about key release on the control, that corresponds to the attribute
82 /// \param theObject a sender of the event
83 /// \param theEvent key release event
84 void keyReleased(QObject* theObject, QKeyEvent* theEvent);
87 /// Perform completion by prefix
88 /// \param theCompletionPrefix a prefix for looking for completion
89 void performCompletion(const QString& theCompletionPrefix);
91 /// Redefinition of virtual method
92 /// \param theEvent a key press event
93 virtual void keyPressEvent(QKeyEvent* theEvent);
95 /// Key events processing
96 /// theEvent a key event
97 bool handledCompletedAndSelected(QKeyEvent* theEvent);
99 /// Redefinition of virtual method
100 virtual void paintEvent( QPaintEvent* );
103 QStringListModel* myCompleterModel;
104 QCompleter* myCompleter;
105 bool myCompletedAndSelected;
106 QString myPlaceHolderText;
111 * A Widget which provides an input of an expression
113 class MODULEBASE_EXPORT ModuleBase_WidgetExprEditor : public ModuleBase_ModelWidget
118 /// \param theParent the parent object
119 /// \param theData the widget configuration.
120 /// \param thePlaceHolder a placeholder string
121 ModuleBase_WidgetExprEditor( QWidget* theParent,
122 const Config_WidgetAPI* theData,
123 const std::string& thePlaceHolder );
124 virtual ~ModuleBase_WidgetExprEditor();
126 /// The methiod called when widget is activated
127 virtual void activateCustom();
129 /// Redefinition of virtual method
130 virtual QList<QWidget*> getControls() const;
132 /// Returns true if the event is processed.
133 virtual bool processEnter();
136 /// A slot for processing text changed event
137 void onTextChanged();
140 /// Do not initialize value on the widget activation
141 virtual void initializeValueByActivate();
143 /// Saves the internal parameters to the given feature
144 /// \return True in success
145 virtual bool storeValueCustom();
147 /// Redefinition of virtual method
148 virtual bool restoreValueCustom();
151 /// A line edit control
152 QLabel* myResultLabel;
153 ExpressionEditor* myEditor;
156 #endif /* MODULEBASE_WIDGETEXPREDITOR_H_ */