]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_WidgetExprEditor.h
Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom into Dev_1.1.0
[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 <QString>
18 #include <QStringList>
19 #include <QPlainTextEdit>
20
21 class QWidget;
22 class QStringListModel;
23 class QCompleter;
24
25 class ExpressionEditor: public QPlainTextEdit
26 {
27   Q_OBJECT
28
29  public:
30   explicit ExpressionEditor(QWidget* theParent = 0);
31   virtual ~ExpressionEditor();
32
33   void setCompletionList(QStringList&);
34
35  public slots:
36   void insertCompletion(const QString&, bool isSingleWord = false);
37   void performCompletion();
38
39  protected:
40   void performCompletion(const QString& theCompletionPrefix);
41   virtual void keyPressEvent(QKeyEvent* theEvent);
42   bool handledCompletedAndSelected(QKeyEvent* theEvent);
43
44  private:
45   QStringListModel* myCompleterModel;
46   QCompleter* myCompleter;
47   bool myCompletedAndSelected;
48 };
49
50 /**
51 * \ingroup GUI
52 * TODO(sbh) add doc
53 */
54 class MODULEBASE_EXPORT ModuleBase_WidgetExprEditor : public ModuleBase_ModelWidget
55 {
56   Q_OBJECT
57  public:
58   /// Constructor
59   /// \param theParent the parent object
60   /// \param theData the widget configuration.
61   /// \param theParentId is Id of a parent of the current attribute
62   ModuleBase_WidgetExprEditor(QWidget* theParent,
63                                 const Config_WidgetAPI* theData,
64                                 const std::string& theParentId);
65   virtual ~ModuleBase_WidgetExprEditor();
66
67   virtual bool restoreValue();
68
69   virtual QList<QWidget*> getControls() const;
70
71  public slots:
72    /// A slot for processing text changed event
73   void onTextChanged();
74
75 protected:
76   /// Saves the internal parameters to the given feature
77   /// \return True in success
78   virtual bool storeValueCustom() const;
79
80 private:
81    /// A line edit control
82   ExpressionEditor* myEditor;
83 };
84
85 #endif /* MODULEBASE_WIDGETEXPREDITOR_H_ */