1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #ifndef ParametersPlugin_WidgetParamsMgr_H_
22 #define ParametersPlugin_WidgetParamsMgr_H_
24 #include <ModuleBase_ModelDialogWidget.h>
25 #include <QModelIndex>
26 #include <QAbstractItemDelegate>
27 #include <QTreeWidget>
29 class QTreeWidgetItem;
30 class ParametersPlugin_ItemDelegate;
37 * Redefinition of QTreeWidget for processing of closeEditor event
39 class ParametersPlugin_TreeWidget: public QTreeWidget
44 /// \param theParent a parent widget
45 ParametersPlugin_TreeWidget(QWidget* theParent = 0) : QTreeWidget(theParent) {}
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);
58 * Represent a content of the property panel to show/modify parameters of some feature.
60 class ParametersPlugin_WidgetParamsMgr : public ModuleBase_ModelDialogWidget
64 /// Constructs a model widget
65 ParametersPlugin_WidgetParamsMgr(QWidget* theParent, const Config_WidgetAPI* theData);
67 /// Destructs the model widget
68 virtual ~ParametersPlugin_WidgetParamsMgr() {}
70 /// Returns list of widget controls
71 /// \return a control list
72 virtual QList<QWidget*> getControls() const;
74 /// Set general buttons from dialog
75 /// \param theButtons the dialog buttons
76 virtual void setDialogButtons(QDialogButtonBox* theButtons);
79 /// Saves the internal parameters to the given feature
80 /// \return True in success
81 virtual bool storeValueCustom();
83 /// Restore value from attribute data to the widget's control
84 virtual bool restoreValueCustom();
86 /// The method called when widget is activated
87 virtual void activateCustom();
89 virtual void showEvent(QShowEvent* theEvent);
91 virtual void hideEvent(QHideEvent* theEvent);
94 /// Slot for reaction on double click in the table (start editing)
95 /// \param theIndex the clicked index
96 void onDoubleClick(const QModelIndex& theIndex);
98 /// Slot for reaction on end of cell editing
99 /// \param theEditor the editor widget
100 /// \param theHint end of edit type
101 void onCloseEditor(QWidget* theEditor, QAbstractItemDelegate::EndEditHint theHint);
103 /// Slot for reaction on add parameter
106 /// Slot for reaction on insert parameter
109 /// Slot for reaction on remove parameter
112 /// Slot for reaction on shift up
115 /// Slot for reaction on shift down
118 /// Slot to show message on closing of editor
121 /// Slot for reaction on selection in the table
122 void onSelectionChanged();
124 // A slot for show preview button
125 void onShowPreview();
128 /// Creates a new parameter feature
129 FeaturePtr createParameter() const;
131 /// Creates a new item
132 QTreeWidgetItem* createNewItem(QTreeWidgetItem* theParent) const;
134 /// Returns currently selected item
135 QTreeWidgetItem* selectedItem() const;
137 /// Select the given Item and scroll the table to make it visible
138 void selectItemScroll(QTreeWidgetItem* theItem);
140 /// Update values in features part
141 void updateItem(QTreeWidgetItem* theItem, const QList<QStringList>& theFeaturesList);
143 void updateFeaturesPart();
145 void updateParametersPart();
147 /// Returns true if values in the widget are valid
150 /// Returns true if parameter with the given name already exists
151 bool hasName(const QString& theName) const;
153 /// Enable or disable buttons for parameters managemnt
154 void enableButtons(bool theEnable);
156 QList<QStringList> featuresItems(const QList<FeaturePtr>& theFeatures,
157 QList<FeaturePtr>& theFeatureList) const;
158 QList<QStringList> parametersItems(const QList<FeaturePtr>& theFeatures) const;
160 void updateParametersFeatures();
162 ParametersPlugin_TreeWidget* myTable;
163 QTreeWidgetItem* myFeatures;
164 QTreeWidgetItem* myParameters;
165 ParametersPlugin_ItemDelegate* myDelegate;
167 QList<FeaturePtr> myParametersList;
171 QPushButton* myAddBtn;
172 QPushButton* myInsertBtn;
173 QPushButton* myRemoveBtn;
174 QToolButton* myUpBtn;
175 QToolButton* myDownBtn;