Salome HOME
Issue #2971: Naming issue in a group when loading a dump file
[modules/shaper.git] / src / ParametersPlugin / ParametersPlugin_WidgetParamsMgr.h
1 // Copyright (C) 2014-2019  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef ParametersPlugin_WidgetParamsMgr_H_
21 #define ParametersPlugin_WidgetParamsMgr_H_
22
23 #include <ModuleBase_ModelDialogWidget.h>
24 #include <QModelIndex>
25 #include <QAbstractItemDelegate>
26 #include <QTreeWidget>
27
28 class QTreeWidgetItem;
29 class ParametersPlugin_ItemDelegate;
30 class QPushButton;
31 class QToolButton;
32
33
34 /*!
35  * \ingroup GUI
36  * Redefinition of QTreeWidget for processing of closeEditor event
37  */
38 class ParametersPlugin_TreeWidget: public QTreeWidget
39 {
40  Q_OBJECT
41 public:
42   /// Constructor
43   /// \param theParent a parent widget
44   ParametersPlugin_TreeWidget(QWidget* theParent = 0) : QTreeWidget(theParent) {}
45
46 protected slots:
47   /// Redefinition of virtual method
48   /// \param theEditor a editor widget
49   /// \param theHint end of editing hint
50   virtual void closeEditor(QWidget* theEditor, QAbstractItemDelegate::EndEditHint theHint);
51 };
52
53
54
55 /*!
56  * \ingroup GUI
57  * Represent a content of the property panel to show/modify parameters of some feature.
58  */
59 class ParametersPlugin_WidgetParamsMgr : public ModuleBase_ModelDialogWidget
60 {
61  Q_OBJECT
62 public:
63   /// Constructs a model widget
64   ParametersPlugin_WidgetParamsMgr(QWidget* theParent, const Config_WidgetAPI* theData);
65
66   /// Destructs the model widget
67   virtual ~ParametersPlugin_WidgetParamsMgr() {}
68
69   /// Returns list of widget controls
70   /// \return a control list
71   virtual QList<QWidget*> getControls() const;
72
73   /// Set general buttons from dialog
74   /// \param theButtons the dialog buttons
75   virtual void setDialogButtons(QDialogButtonBox* theButtons);
76
77 protected:
78   /// Saves the internal parameters to the given feature
79   /// \return True in success
80   virtual bool storeValueCustom();
81
82   /// Restore value from attribute data to the widget's control
83   virtual bool restoreValueCustom();
84
85   /// The method called when widget is activated
86   virtual void activateCustom();
87
88   virtual void showEvent(QShowEvent* theEvent);
89
90   virtual void hideEvent(QHideEvent* theEvent);
91
92 private slots:
93   /// Slot for reaction on double click in the table (start editing)
94   /// \param theIndex the clicked index
95   void onDoubleClick(const QModelIndex& theIndex);
96
97   /// Slot for reaction on end of cell editing
98   /// \param theEditor the editor widget
99   /// \param theHint end of edit type
100   void onCloseEditor(QWidget* theEditor, QAbstractItemDelegate::EndEditHint theHint);
101
102   /// Slot for reaction on add parameter
103   void onAdd();
104
105   /// Slot for reaction on insert parameter
106   void onInsert();
107
108   /// Slot for reaction on remove parameter
109   void onRemove();
110
111   /// Slot for reaction on shift up
112   void onUp();
113
114   /// Slot for reaction on shift down
115   void onDown();
116
117   /// Slot to show message on closing of editor
118   void sendWarning();
119
120   /// Slot for reaction on selection in the table
121   void onSelectionChanged();
122
123   // A slot for show preview button
124   void onShowPreview();
125
126 private:
127   /// Creates a new parameter feature
128   FeaturePtr createParameter() const;
129
130   /// Creates a new item
131   QTreeWidgetItem* createNewItem(QTreeWidgetItem* theParent) const;
132
133   /// Returns currently selected item
134   QTreeWidgetItem* selectedItem() const;
135
136   /// Select the given Item and scroll the table to make it visible
137   void selectItemScroll(QTreeWidgetItem* theItem);
138
139   /// Update values in features part
140   void updateItem(QTreeWidgetItem* theItem, const QList<QStringList>& theFeaturesList);
141
142   void updateFeaturesPart();
143
144   void updateParametersPart();
145
146   /// Returns true if values in the widget are valid
147   bool isValid();
148
149   /// Returns true if parameter with the given name already exists
150   bool hasName(const QString& theName) const;
151
152   /// Enable or disable buttons for parameters managemnt
153   void enableButtons(bool theEnable);
154
155   QList<QStringList> featuresItems(const QList<FeaturePtr>& theFeatures,
156                                    QList<FeaturePtr>& theFeatureList) const;
157   QList<QStringList> parametersItems(const QList<FeaturePtr>& theFeatures) const;
158
159   void updateParametersFeatures();
160
161   ParametersPlugin_TreeWidget* myTable;
162   QTreeWidgetItem* myFeatures;
163   QTreeWidgetItem* myParameters;
164   ParametersPlugin_ItemDelegate* myDelegate;
165
166   QList<FeaturePtr> myParametersList;
167
168   QString myMessage;
169
170   QPushButton* myAddBtn;
171   QPushButton* myInsertBtn;
172   QPushButton* myRemoveBtn;
173   QToolButton* myUpBtn;
174   QToolButton* myDownBtn;
175
176   bool isUpplyBlocked;
177 };
178
179
180 #endif