Salome HOME
Make Table of parameters view according to proposal of DBC
[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_ModelWidget.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 class ParametersPlugin_TreeWidget: public QTreeWidget
22 {
23  Q_OBJECT
24 public:
25   ParametersPlugin_TreeWidget(QWidget* theParent = 0) : QTreeWidget(theParent) {}
26
27 protected slots:
28   virtual void closeEditor(QWidget* theEditor, QAbstractItemDelegate::EndEditHint theHint);
29 };
30
31
32
33 /*!
34  * \ingroup GUI
35  * Represent a content of the property panel to show/modify parameters of some feature.
36  */
37 class ParametersPlugin_WidgetParamsMgr : public ModuleBase_ModelWidget
38 {
39  Q_OBJECT
40 public:
41   /// Constructs a model widget
42   ParametersPlugin_WidgetParamsMgr(QWidget* theParent, const Config_WidgetAPI* theData);
43
44   /// Destructs the model widget
45   virtual ~ParametersPlugin_WidgetParamsMgr() {}
46
47   /// Returns list of widget controls
48   /// \return a control list
49   virtual QList<QWidget*> getControls() const;
50
51 protected:
52   /// Saves the internal parameters to the given feature
53   /// \return True in success
54   virtual bool storeValueCustom();
55
56   /// Restore value from attribute data to the widget's control
57   virtual bool restoreValueCustom();
58
59   /// The method called when widget is activated
60   virtual void activateCustom();
61
62 private slots:
63   /// Slot for reaction on double click in the table (start editing)
64   /// \param theIndex the clicked index
65   void onDoubleClick(const QModelIndex& theIndex);
66
67   /// Slot for reaction on end of cell editing
68   /// \param theEditor the editor widget
69   /// \param theHint end of edit type
70   void onCloseEditor(QWidget* theEditor, QAbstractItemDelegate::EndEditHint theHint);
71
72   /// Slot for reaction on add parameter
73   void onAdd();
74
75   /// Slot for reaction on insert parameter
76   void onInsert();
77
78   /// Slot for reaction on remove parameter
79   void onRemove();
80
81   /// Slot for reaction on shift up
82   void onUp();
83
84   /// Slot for reaction on shift down
85   void onDown();
86
87   /// Slot to show message on closing of editor
88   void sendWarning();
89
90   /// Slot for reaction on selection in the table
91   void onSelectionChanged();
92
93 private:
94   /// Creates a new parameter feature
95   FeaturePtr createParameter() const;
96
97   /// Creates a new item
98   QTreeWidgetItem* createNewItem(QTreeWidgetItem* theParent) const;
99
100   /// Returns currently selected item
101   QTreeWidgetItem* selectedItem() const;
102
103   /// Select the given Item and scroll the table to make it visible
104   void selectItemScroll(QTreeWidgetItem* theItem);
105
106   /// Update values in features part
107   void updateItem(QTreeWidgetItem* theItem, const QList<QStringList>& theFeaturesList);
108
109   void updateFeaturesPart();
110
111   void updateParametersPart();
112
113   /// Returns true if parameter with the given name already exists
114   bool hasName(const QString& theName) const;
115
116   /// Enable or disable buttons for parameters managemnt
117   void enableButtons(bool theEnable);
118
119   bool checkIsValid();
120
121   QList<QStringList> featuresItems(const QList<FeaturePtr>& theFeatures) const;
122   QList<QStringList> parametersItems(const QList<FeaturePtr>& theFeatures) const;
123
124   void updateParametersFeatures();
125
126   ParametersPlugin_TreeWidget* myTable;
127   QTreeWidgetItem* myFeatures;
128   QTreeWidgetItem* myParameters;
129   ParametersPlugin_ItemDelegate* myDelegate;
130
131   QList<FeaturePtr> myParametersList;
132
133   QString myMessage;
134
135   QPushButton* myAddBtn;
136   QPushButton* myInsertBtn;
137   QPushButton* myRemoveBtn;
138   QToolButton* myUpBtn;
139   QToolButton* myDownBtn;
140 };
141
142
143 #endif