Salome HOME
Merge branch 'master' of newgeom:newgeom.git
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetSelector.h
1 // File:        ModuleBase_WidgetSelector.h
2 // Created:     2 June 2014
3 // Author:      Vitaly Smetannikov
4
5 #ifndef ModuleBase_WidgetSelector_H
6 #define ModuleBase_WidgetSelector_H
7
8 #include "ModuleBase.h"
9 #include "ModuleBase_ModelWidget.h"
10
11 #include <ModelAPI_Object.h>
12
13 #include <TopAbs_ShapeEnum.hxx>
14
15 #include <QStringList>
16
17 class Config_WidgetAPI;
18 class QWidget;
19 class QLabel;
20 class QLineEdit;
21 class QToolButton;
22 class ModuleBase_IWorkshop;
23
24 class MODULEBASE_EXPORT ModuleBase_WidgetSelector : public ModuleBase_ModelWidget
25 {
26 Q_OBJECT
27  public:
28   ModuleBase_WidgetSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
29                             const Config_WidgetAPI* theData, const std::string& theParentId);
30
31   virtual ~ModuleBase_WidgetSelector();
32
33   /// Saves the internal parameters to the given feature
34   /// \param theObject a model feature to be changed
35   virtual bool storeValue() const;
36
37   virtual bool restoreValue();
38
39   /// Returns the internal parent wiget control, that can be shown anywhere
40   /// \returns the widget
41   QWidget* getControl() const
42   {
43     return myContainer;
44   }
45
46   /// Returns list of widget controls
47   /// \return a control list
48   virtual QList<QWidget*> getControls() const;
49
50   void setActivationOnStart(bool toActivate)
51   {
52     myActivateOnStart = toActivate;
53   }
54   bool activateOnStart() const
55   {
56     return myActivateOnStart;
57   }
58
59   ObjectPtr selectedFeature() const
60   {
61     return mySelectedObject;
62   }
63
64  public slots:
65
66   /// Activate or deactivate selection
67   void activateSelection(bool toActivate);
68
69  protected:
70   bool eventFilter(QObject* theObj, QEvent* theEvent);
71
72  private slots:
73   void onSelectionChanged();
74
75  private:
76   void enableOthersControls(bool toEnable) const;
77   void updateSelectionName();
78   void raisePanel() const;
79   bool isAccepted(const ObjectPtr theObject) const;
80
81   static TopAbs_ShapeEnum shapeType(const QString& theType);
82
83   QWidget* myContainer;
84   QLabel* myLabel;
85   QLineEdit* myTextLine;
86   QToolButton* myActivateBtn;
87
88   ModuleBase_IWorkshop* myWorkshop;
89
90   bool myActivateOnStart;
91
92   ObjectPtr mySelectedObject;
93   QStringList myShapeTypes;
94 };
95
96 #endif