Salome HOME
Fix for #767: correct the internal history structure for nested features
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetExprEditor.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 /*
4  * ModuleBase_WidgetExprEditor.h
5  *
6  *  Created on: Oct 8, 2014
7  *      Author: sbh
8  */
9
10 #ifndef MODULEBASE_WIDGETEXPREDITOR_H_
11 #define MODULEBASE_WIDGETEXPREDITOR_H_
12
13 #include <ModuleBase.h>
14 #include <ModuleBase_ModelWidget.h>
15
16 #include <QList>
17 #include <QLabel>
18 #include <QString>
19 #include <QStringList>
20 #include <QPlainTextEdit>
21
22 class QWidget;
23 class QStringListModel;
24 class QCompleter;
25
26 class ExpressionEditor: public QPlainTextEdit
27 {
28   Q_OBJECT
29
30  public:
31   explicit ExpressionEditor(QWidget* theParent = 0);
32   virtual ~ExpressionEditor();
33
34   void setCompletionList(QStringList&);
35
36   void setPlaceHolderText( const QString& );
37   QString placeHolderText() const;
38
39  public slots:
40   void insertCompletion(const QString&, bool isSingleWord = false);
41   void performCompletion();
42
43  protected:
44   void performCompletion(const QString& theCompletionPrefix);
45   virtual void keyPressEvent(QKeyEvent* theEvent);
46   bool handledCompletedAndSelected(QKeyEvent* theEvent);
47   virtual void paintEvent( QPaintEvent* );
48
49  private:
50   QStringListModel* myCompleterModel;
51   QCompleter* myCompleter;
52   bool myCompletedAndSelected;
53   QString myPlaceHolderText;
54 };
55
56 /**
57 * \ingroup GUI
58 * TODO(sbh) add doc
59 */
60 class MODULEBASE_EXPORT ModuleBase_WidgetExprEditor : public ModuleBase_ModelWidget
61 {
62   Q_OBJECT
63  public:
64   /// Constructor
65   /// \param theParent the parent object
66   /// \param theData the widget configuration.
67   /// \param theParentId is Id of a parent of the current attribute
68   ModuleBase_WidgetExprEditor( QWidget* theParent,
69                                const Config_WidgetAPI* theData,
70                                const std::string& theParentId,
71                                const std::string& thePlaceHolder );
72   virtual ~ModuleBase_WidgetExprEditor();
73
74   virtual QList<QWidget*> getControls() const;
75
76  public slots:
77    /// A slot for processing text changed event
78   void onTextChanged();
79
80 protected:
81   /// Saves the internal parameters to the given feature
82   /// \return True in success
83   virtual bool storeValueCustom() const;
84
85   virtual bool restoreValueCustom();
86
87 private:
88    /// A line edit control
89   QLabel* myResultLabel;
90   ExpressionEditor* myEditor;
91 };
92
93 #endif /* MODULEBASE_WIDGETEXPREDITOR_H_ */