Salome HOME
Shape plane filter should process shapes of objects selected in object browser.
[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  public slots:
37   void insertCompletion(const QString&, bool isSingleWord = false);
38   void performCompletion();
39
40  protected:
41   void performCompletion(const QString& theCompletionPrefix);
42   virtual void keyPressEvent(QKeyEvent* theEvent);
43   bool handledCompletedAndSelected(QKeyEvent* theEvent);
44
45  private:
46   QStringListModel* myCompleterModel;
47   QCompleter* myCompleter;
48   bool myCompletedAndSelected;
49 };
50
51 /**
52 * \ingroup GUI
53 * TODO(sbh) add doc
54 */
55 class MODULEBASE_EXPORT ModuleBase_WidgetExprEditor : public ModuleBase_ModelWidget
56 {
57   Q_OBJECT
58  public:
59   /// Constructor
60   /// \param theParent the parent object
61   /// \param theData the widget configuration.
62   /// \param theParentId is Id of a parent of the current attribute
63   ModuleBase_WidgetExprEditor(QWidget* theParent,
64                                 const Config_WidgetAPI* theData,
65                                 const std::string& theParentId);
66   virtual ~ModuleBase_WidgetExprEditor();
67
68   virtual bool restoreValue();
69
70   virtual QList<QWidget*> getControls() const;
71
72  public slots:
73    /// A slot for processing text changed event
74   void onTextChanged();
75
76 protected:
77   /// Saves the internal parameters to the given feature
78   /// \return True in success
79   virtual bool storeValueCustom() const;
80
81 private:
82    /// A line edit control
83   QLabel* myResultLabel;
84   ExpressionEditor* myEditor;
85 };
86
87 #endif /* MODULEBASE_WIDGETEXPREDITOR_H_ */