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