1 // Copyright (C) 2014-2020 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 email : webmaster.salome@opencascade.com
20 #ifndef CollectionPlugin_WidgetField_H
21 #define CollectionPlugin_WidgetField_H
24 #include "CollectionPlugin.h"
26 #include <ModuleBase_WidgetSelector.h>
27 #include <ModuleBase_ViewerPrs.h>
28 #include <ModelAPI_AttributeTables.h>
31 #include <QStringList>
32 #include <QStyledItemDelegate>
43 class QTableWidgetItem;
47 class DataTableItemDelegate : public QStyledItemDelegate
51 DataTableItemDelegate(ModelAPI_AttributeTables::ValueType theType);
53 virtual QWidget* createEditor(QWidget* theParent,
54 const QStyleOptionViewItem & theOption,
55 const QModelIndex& theIndex) const;
57 ModelAPI_AttributeTables::ValueType dataType() const { return myType; }
59 void setDataType(ModelAPI_AttributeTables::ValueType theType) { myType = theType; }
62 void onEditItem(const QString& theText);
65 ModelAPI_AttributeTables::ValueType myType;
72 * Represent a content of the property panel to show/modify parameters of a Field feature.
74 class CollectionPlugin_WidgetField : public ModuleBase_WidgetSelector
78 CollectionPlugin_WidgetField(QWidget* theParent,
79 ModuleBase_IWorkshop* theWorkshop,
80 const Config_WidgetAPI* theData);
82 virtual ~CollectionPlugin_WidgetField() {}
84 /// Returns list of widget controls
85 /// \return a control list
86 virtual QList<QWidget*> getControls() const;
88 /// Checks the widget validity. By default, it returns true.
89 /// \param thePrs a selected presentation in the view
90 /// \return a boolean value
91 virtual bool isValidSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
93 /// Returns true if the event is processed.
94 virtual bool processEnter();
96 /// The methiod called when widget is deactivated
97 virtual void deactivate();
99 /// Set the given wrapped value to the current widget
100 /// This value should be processed in the widget according to the needs
101 /// \param theValues the wrapped selection values
102 /// \param theToValidate a validation of the values flag
103 virtual bool setSelection(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
104 const bool theToValidate);
107 /// Saves the internal parameters to the given feature
108 /// \return True in success
109 virtual bool storeValueCustom();
111 /// Restore value from attribute data to the widget's control
112 virtual bool restoreValueCustom();
114 /// Retunrs a list of possible shape types
115 /// \return a list of shapes
116 virtual QIntList shapeTypes() const;
118 /// Redefinition of virtual function
119 /// \param theObject an object for the event
120 /// \param theEvent an event
121 virtual bool eventFilter(QObject* theObject, QEvent* theEvent);
123 //virtual void showEvent(QShowEvent* theEvent);
125 /// Return the attribute values wrapped in a list of viewer presentations
126 /// \return a list of viewer presentations, which contains an attribute result and
127 /// a shape. If the attribute do not uses the shape, it is empty
128 virtual QList<std::shared_ptr<ModuleBase_ViewerPrs>> getAttributeSelection() const;
131 /// Slot called on number of component changed
132 /// \param theVal - a new components number
133 void onNbCompChanged(int theVal);
135 /// Slot called on add a step
138 /// Slot called on remove a step
141 /// Slot called on a navigation between steps
142 /// \param theStep - a current step
143 void onStepMove(int theStep);
145 /// Slot called on a navigation between steps
146 /// \param theIdx - a current step
147 void onFieldTypeChanged(int theIdx);
149 /// Slot called on editing of a table cell
150 /// \param theRow a row of the cell
151 /// \param theCol a column of the cell
152 void onTableEdited(int theRow, int theCol);
154 /// Slot called on selection mode changed
155 /// \param theType a new choice
156 void onShapeTypeChanged(int theType);
158 /// Slot called on widget focus changed
159 /// \param theOld a widget wgich lost focus
160 /// \param theNew a widget which get focus
161 void onFocusChanged(QWidget* theOld, QWidget* theNew);
163 /// Slot called on a slider navigation changed
164 /// \param theMin - a minimal value
165 /// \param theMax a maximal value
166 void onRangeChanged(int theMin, int theMax);
168 void onColumnResize(int theIndex, int theOld, int theNew);
171 /// Clear existing tables
174 /// Append controls for management of a new step
175 void appendStepControls();
177 /// Remove current step controls
178 void removeStepControls();
180 /// Update header of a table
181 /// \param theDataTbl a table widget
182 void updateHeaders(QTableWidget* theDataTbl) const;
184 /// Return Item Id of myShapeTypeCombo by selection mode
185 /// \param theStr a selection mode
186 int getSelectionType(const std::string& theStr) const;
188 /// Return selection mode by Item Id of myShapeTypeCombo
189 /// \param theType an item id
190 std::string getSelectionType(int theType) const;
192 /// Create default table item
193 QTableWidgetItem* createDefaultItem() const;
195 /// Create a table item from the given value
196 /// \param theVal a value for the item
197 QTableWidgetItem* createValueItem(ModelAPI_AttributeTables::Value& theVal) const;
199 QString getValueText(ModelAPI_AttributeTables::Value& theVal) const;
201 /// Return a value from the string
202 /// \param theStrVal a string
203 ModelAPI_AttributeTables::Value getValue(QString theStrVal) const;
205 /// Types of shapes selection
206 QComboBox* myShapeTypeCombo;
208 /// Types of field data
209 QComboBox* myFieldTypeCombo;
211 /// Number of components
212 QSpinBox* myNbComponentsSpn;
214 /// Label of current step
215 QLabel* myCurStepLbl;
217 /// Slider for steps management
218 QSlider* myStepSlider;
221 QList<QSpinBox*> myStampSpnList;
223 /// List of created tables
224 QList<QTableWidget*> myDataTblList;
226 /// Max value Label for the slider
229 /// A container for step controls
230 QStackedWidget* myStepWgt;
232 /// A list for component names
233 QStringList myCompNamesList;
236 QPushButton* myRemoveBtn;
238 /// Editor for table header
239 QLineEdit* myHeaderEditor;
241 /// Index of header section under editing
244 /// Stae of a table editing
249 DataTableItemDelegate* myDelegate;