Salome HOME
74ae279627ece880070d98e06565a2d908c2f1d8
[modules/shaper.git] / src / ParametersPlugin / ParametersPlugin_WidgetParamsMgr.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        ParametersPlugin_WidgetParamsMgr.h
4 // Created:     11 Apr 2016
5 // Author:      Vitaly SMETANNIKOV
6
7 #ifndef ParametersPlugin_WidgetParamsMgr_H_
8 #define ParametersPlugin_WidgetParamsMgr_H_
9
10 #include <ModuleBase_ModelDialogWidget.h>
11 #include <QModelIndex>
12 #include <QAbstractItemDelegate>
13 #include <QTreeWidget>
14
15 class QTreeWidgetItem;
16 class ParametersPlugin_ItemDelegate;
17 class QPushButton;
18 class QToolButton;
19
20
21 /*!
22  * \ingroup GUI
23  * Redefinition of QTreeWidget for processing of closeEditor event
24  */
25 class ParametersPlugin_TreeWidget: public QTreeWidget
26 {
27  Q_OBJECT
28 public:
29   /// Constructor
30   /// \param theParent a parent widget
31   ParametersPlugin_TreeWidget(QWidget* theParent = 0) : QTreeWidget(theParent) {}
32
33 protected slots:
34   /// Redefinition of virtual method
35   /// \param theEditor a editor widget
36   /// \param theHint end of editing hint
37   virtual void closeEditor(QWidget* theEditor, QAbstractItemDelegate::EndEditHint theHint);
38 };
39
40
41
42 /*!
43  * \ingroup GUI
44  * Represent a content of the property panel to show/modify parameters of some feature.
45  */
46 class ParametersPlugin_WidgetParamsMgr : public ModuleBase_ModelDialogWidget
47 {
48  Q_OBJECT
49 public:
50   /// Constructs a model widget
51   ParametersPlugin_WidgetParamsMgr(QWidget* theParent, const Config_WidgetAPI* theData);
52
53   /// Destructs the model widget
54   virtual ~ParametersPlugin_WidgetParamsMgr() {}
55
56   /// Returns list of widget controls
57   /// \return a control list
58   virtual QList<QWidget*> getControls() const;
59
60 protected:
61   /// Saves the internal parameters to the given feature
62   /// \return True in success
63   virtual bool storeValueCustom();
64
65   /// Restore value from attribute data to the widget's control
66   virtual bool restoreValueCustom();
67
68   /// The method called when widget is activated
69   virtual void activateCustom();
70
71 private slots:
72   /// Slot for reaction on double click in the table (start editing)
73   /// \param theIndex the clicked index
74   void onDoubleClick(const QModelIndex& theIndex);
75
76   /// Slot for reaction on end of cell editing
77   /// \param theEditor the editor widget
78   /// \param theHint end of edit type
79   void onCloseEditor(QWidget* theEditor, QAbstractItemDelegate::EndEditHint theHint);
80
81   /// Slot for reaction on add parameter
82   void onAdd();
83
84   /// Slot for reaction on insert parameter
85   void onInsert();
86
87   /// Slot for reaction on remove parameter
88   void onRemove();
89
90   /// Slot for reaction on shift up
91   void onUp();
92
93   /// Slot for reaction on shift down
94   void onDown();
95
96   /// Slot to show message on closing of editor
97   void sendWarning();
98
99   /// Slot for reaction on selection in the table
100   void onSelectionChanged();
101
102 private:
103   /// Creates a new parameter feature
104   FeaturePtr createParameter() const;
105
106   /// Creates a new item
107   QTreeWidgetItem* createNewItem(QTreeWidgetItem* theParent) const;
108
109   /// Returns currently selected item
110   QTreeWidgetItem* selectedItem() const;
111
112   /// Select the given Item and scroll the table to make it visible
113   void selectItemScroll(QTreeWidgetItem* theItem);
114
115   /// Update values in features part
116   void updateItem(QTreeWidgetItem* theItem, const QList<QStringList>& theFeaturesList);
117
118   void updateFeaturesPart();
119
120   void updateParametersPart();
121
122   /// Returns true if values in the widget are valid
123   bool isValid();
124
125   /// Returns true if parameter with the given name already exists
126   bool hasName(const QString& theName) const;
127
128   /// Enable or disable buttons for parameters managemnt
129   void enableButtons(bool theEnable);
130
131   QList<QStringList> featuresItems(const QList<FeaturePtr>& theFeatures, 
132                                    QList<FeaturePtr>& theFeatureList) const;
133   QList<QStringList> parametersItems(const QList<FeaturePtr>& theFeatures) const;
134
135   void updateParametersFeatures();
136
137   ParametersPlugin_TreeWidget* myTable;
138   QTreeWidgetItem* myFeatures;
139   QTreeWidgetItem* myParameters;
140   ParametersPlugin_ItemDelegate* myDelegate;
141
142   QList<FeaturePtr> myParametersList;
143
144   QString myMessage;
145
146   QPushButton* myAddBtn;
147   QPushButton* myInsertBtn;
148   QPushButton* myRemoveBtn;
149   QToolButton* myUpBtn;
150   QToolButton* myDownBtn;
151 };
152
153
154 #endif