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 CollectionPlugin_WidgetField_H
22 #define CollectionPlugin_WidgetField_H
25 #include "CollectionPlugin.h"
27 #include <ModuleBase_WidgetSelector.h>
28 #include <ModuleBase_ViewerPrs.h>
29 #include <ModelAPI_AttributeTables.h>
32 #include <QStringList>
33 #include <QStyledItemDelegate>
44 class QTableWidgetItem;
48 class DataTableItemDelegate : public QStyledItemDelegate
52 DataTableItemDelegate(ModelAPI_AttributeTables::ValueType theType);
54 virtual QWidget* createEditor(QWidget* theParent,
55 const QStyleOptionViewItem & theOption,
56 const QModelIndex& theIndex) const;
58 ModelAPI_AttributeTables::ValueType dataType() const { return myType; }
60 void setDataType(ModelAPI_AttributeTables::ValueType theType) { myType = theType; }
63 void onEditItem(const QString& theText);
66 ModelAPI_AttributeTables::ValueType myType;
73 * Represent a content of the property panel to show/modify parameters of a Field feature.
75 class CollectionPlugin_WidgetField : public ModuleBase_WidgetSelector
79 CollectionPlugin_WidgetField(QWidget* theParent,
80 ModuleBase_IWorkshop* theWorkshop,
81 const Config_WidgetAPI* theData);
83 virtual ~CollectionPlugin_WidgetField() {}
85 /// Returns list of widget controls
86 /// \return a control list
87 virtual QList<QWidget*> getControls() const;
89 /// Checks the widget validity. By default, it returns true.
90 /// \param thePrs a selected presentation in the view
91 /// \return a boolean value
92 virtual bool isValidSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
94 /// Returns true if the event is processed.
95 virtual bool processEnter();
97 /// The methiod called when widget is deactivated
98 virtual void deactivate();
100 /// Set the given wrapped value to the current widget
101 /// This value should be processed in the widget according to the needs
102 /// \param theValues the wrapped selection values
103 /// \param theToValidate a validation of the values flag
104 virtual bool setSelection(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
105 const bool theToValidate);
108 /// Saves the internal parameters to the given feature
109 /// \return True in success
110 virtual bool storeValueCustom();
112 /// Restore value from attribute data to the widget's control
113 virtual bool restoreValueCustom();
115 /// Retunrs a list of possible shape types
116 /// \return a list of shapes
117 virtual QIntList shapeTypes() const;
119 /// Redefinition of virtual function
120 /// \param theObject an object for the event
121 /// \param theEvent an event
122 virtual bool eventFilter(QObject* theObject, QEvent* theEvent);
124 //virtual void showEvent(QShowEvent* theEvent);
126 /// Return the attribute values wrapped in a list of viewer presentations
127 /// \return a list of viewer presentations, which contains an attribute result and
128 /// a shape. If the attribute do not uses the shape, it is empty
129 virtual QList<std::shared_ptr<ModuleBase_ViewerPrs>> getAttributeSelection() const;
132 /// Slot called on number of component changed
133 /// \param theVal - a new components number
134 void onNbCompChanged(int theVal);
136 /// Slot called on add a step
139 /// Slot called on remove a step
142 /// Slot called on a navigation between steps
143 /// \param theStep - a current step
144 void onStepMove(int theStep);
146 /// Slot called on a navigation between steps
147 /// \param theIdx - a current step
148 void onFieldTypeChanged(int theIdx);
150 /// Slot called on editing of a table cell
151 /// \param theRow a row of the cell
152 /// \param theCol a column of the cell
153 void onTableEdited(int theRow, int theCol);
155 /// Slot called on selection mode changed
156 /// \param theType a new choice
157 void onShapeTypeChanged(int theType);
159 /// Slot called on widget focus changed
160 /// \param theOld a widget wgich lost focus
161 /// \param theNew a widget which get focus
162 void onFocusChanged(QWidget* theOld, QWidget* theNew);
164 /// Slot called on a slider navigation changed
165 /// \param theMin - a minimal value
166 /// \param theMax a maximal value
167 void onRangeChanged(int theMin, int theMax);
169 void onColumnResize(int theIndex, int theOld, int theNew);
172 /// Clear existing tables
175 /// Append controls for management of a new step
176 void appendStepControls();
178 /// Remove current step controls
179 void removeStepControls();
181 /// Update header of a table
182 /// \param theDataTbl a table widget
183 void updateHeaders(QTableWidget* theDataTbl) const;
185 /// Return Item Id of myShapeTypeCombo by selection mode
186 /// \param theStr a selection mode
187 int getSelectionType(const std::string& theStr) const;
189 /// Return selection mode by Item Id of myShapeTypeCombo
190 /// \param theType an item id
191 std::string getSelectionType(int theType) const;
193 /// Create default table item
194 QTableWidgetItem* createDefaultItem() const;
196 /// Create a table item from the given value
197 /// \param theVal a value for the item
198 QTableWidgetItem* createValueItem(ModelAPI_AttributeTables::Value& theVal) const;
200 QString getValueText(ModelAPI_AttributeTables::Value& theVal) const;
202 /// Return a value from the string
203 /// \param theStrVal a string
204 ModelAPI_AttributeTables::Value getValue(QString theStrVal) const;
206 /// Types of shapes selection
207 QComboBox* myShapeTypeCombo;
209 /// Types of field data
210 QComboBox* myFieldTypeCombo;
212 /// Number of components
213 QSpinBox* myNbComponentsSpn;
215 /// Label of current step
216 QLabel* myCurStepLbl;
218 /// Slider for steps management
219 QSlider* myStepSlider;
222 QList<QSpinBox*> myStampSpnList;
224 /// List of created tables
225 QList<QTableWidget*> myDataTblList;
227 /// Max value Label for the slider
230 /// A container for step controls
231 QStackedWidget* myStepWgt;
233 /// A list for component names
234 QStringList myCompNamesList;
237 QPushButton* myRemoveBtn;
239 /// Editor for table header
240 QLineEdit* myHeaderEditor;
242 /// Index of header section under editing
245 /// Stae of a table editing
250 DataTableItemDelegate* myDelegate;