SHAPER  9.12.0
ModuleBase_WidgetExprEditor.h
1 // Copyright (C) 2014-2023 CEA, EDF
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 
20 #ifndef MODULEBASE_WIDGETEXPREDITOR_H_
21 #define MODULEBASE_WIDGETEXPREDITOR_H_
22 
23 #include <ModuleBase.h>
24 #include <ModuleBase_ModelWidget.h>
25 
26 #include <QList>
27 #include <QLabel>
28 #include <QString>
29 #include <QStringList>
30 #include <QPlainTextEdit>
31 
32 class QWidget;
33 class QStringListModel;
34 class QCompleter;
35 
41 {
42  Q_OBJECT
43  public:
46  explicit ExpressionEditor(QWidget* theParent = 0);
47  virtual ~ExpressionEditor();
48 
50  void setCompletionList(QStringList&);
51 
53  void setPlaceHolderText( const QString& );
54 
56  QString placeHolderText() const;
57 
58  public slots:
62  void insertCompletion(const QString& theCompletion, bool isSingleWord = false);
63 
65  void performCompletion();
66 
68  void onTextChanged();
69 
70 signals:
72  void valueModified();
73 
77  void keyReleased(QObject* theObject, QKeyEvent* theEvent);
78 
79  protected:
82  void performCompletion(const QString& theCompletionPrefix);
83 
86  virtual void keyPressEvent(QKeyEvent* theEvent);
87 
90  bool handledCompletedAndSelected(QKeyEvent* theEvent);
91 
93  virtual void paintEvent( QPaintEvent* );
94 
95 private:
96  QStringListModel* myCompleterModel;
97  QCompleter* myCompleter;
98  bool myCompletedAndSelected;
99  QString myPlaceHolderText;
100 };
101 
106 class MODULEBASE_EXPORT ModuleBase_WidgetExprEditor : public ModuleBase_ModelWidget
107 {
108  Q_OBJECT
109  public:
115  const Config_WidgetAPI* theData,
116  const std::string& thePlaceHolder );
117  virtual ~ModuleBase_WidgetExprEditor();
118 
120  virtual void activateCustom();
121 
123  virtual QList<QWidget*> getControls() const;
124 
125 protected slots:
127  void onTextChanged();
128 
129 protected:
131  virtual bool processEnter();
132 
134  virtual void initializeValueByActivate();
135 
138  virtual bool storeValueCustom();
139 
141  virtual bool restoreValueCustom();
142 
143 private:
145  QLabel* myResultLabel;
146  ExpressionEditor* myEditor;
147 };
148 
149 #endif /* MODULEBASE_WIDGETEXPREDITOR_H_ */
Provides low-level API for WidgetFactory for reading xml definitions of widgets.
Definition: Config_WidgetAPI.h:46
A multi-line text editor which lets to input formula and provides a list of completion strings.
Definition: ModuleBase_WidgetExprEditor.h:41
bool handledCompletedAndSelected(QKeyEvent *theEvent)
Key events processing theEvent a key event.
Definition: ModuleBase_WidgetExprEditor.cpp:161
QString placeHolderText() const
Returns placeholder list.
Definition: ModuleBase_WidgetExprEditor.cpp:181
void valueModified()
The signal about text change in the text editor.
virtual void keyPressEvent(QKeyEvent *theEvent)
Redefinition of virtual method.
Definition: ModuleBase_WidgetExprEditor.cpp:127
void insertCompletion(const QString &theCompletion, bool isSingleWord=false)
Insert additional string for completion.
Definition: ModuleBase_WidgetExprEditor.cpp:87
ExpressionEditor(QWidget *theParent=0)
Constructor.
Definition: ModuleBase_WidgetExprEditor.cpp:52
void keyReleased(QObject *theObject, QKeyEvent *theEvent)
The signal about key release on the control, that corresponds to the attribute.
void setPlaceHolderText(const QString &)
Set a text which will be shown when the listr is empty.
Definition: ModuleBase_WidgetExprEditor.cpp:176
virtual void paintEvent(QPaintEvent *)
Redefinition of virtual method.
Definition: ModuleBase_WidgetExprEditor.cpp:186
void setCompletionList(QStringList &)
Set list of completion strings.
Definition: ModuleBase_WidgetExprEditor.cpp:80
void performCompletion()
Perform completion.
Definition: ModuleBase_WidgetExprEditor.cpp:102
void onTextChanged()
A slot for processing text changed event.
Definition: ModuleBase_WidgetExprEditor.cpp:216
An abstract custom widget class.
Definition: ModuleBase_ModelWidget.h:60
virtual void activateCustom()
The method called when widget is activated.
Definition: ModuleBase_ModelWidget.h:410
virtual QList< QWidget * > getControls() const =0
Returns list of widget controls.
virtual void initializeValueByActivate()
Compute the feature default value and fill the controls with it or store the control value to the fea...
Definition: ModuleBase_ModelWidget.cpp:315
virtual bool storeValueCustom()=0
Saves the internal parameters to the given feature.
virtual bool restoreValueCustom()=0
Restore value from attribute data to the widget's control.
A Widget which provides an input of an expression.
Definition: ModuleBase_WidgetExprEditor.h:107