1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: CollectionPlugin_WidgetField.h
4 // Created: 16 Nov 2016
5 // Author: Vitaly SMETANNIKOV
8 #ifndef CollectionPlugin_WidgetField_H
9 #define CollectionPlugin_WidgetField_H
12 #include "CollectionPlugin.h"
14 #include <ModuleBase_WidgetSelector.h>
15 #include <ModuleBase_ViewerPrs.h>
16 #include <ModelAPI_AttributeTables.h>
19 #include <QStringList>
20 #include <QStyledItemDelegate>
31 class QTableWidgetItem;
35 class DataTableItemDelegate : public QStyledItemDelegate
39 DataTableItemDelegate(ModelAPI_AttributeTables::ValueType theType) :
40 QStyledItemDelegate() { myType = theType; }
42 virtual QWidget* createEditor(QWidget* theParent,
43 const QStyleOptionViewItem & theOption,
44 const QModelIndex& theIndex) const;
46 ModelAPI_AttributeTables::ValueType dataType() const { return myType; }
48 void setDataType(ModelAPI_AttributeTables::ValueType theType) { myType = theType; }
51 ModelAPI_AttributeTables::ValueType myType;
58 * Represent a content of the property panel to show/modify parameters of a Field feature.
60 class CollectionPlugin_WidgetField : public ModuleBase_WidgetSelector
64 CollectionPlugin_WidgetField(QWidget* theParent,
65 ModuleBase_IWorkshop* theWorkshop,
66 const Config_WidgetAPI* theData);
68 virtual ~CollectionPlugin_WidgetField() {}
70 /// Returns list of widget controls
71 /// \return a control list
72 virtual QList<QWidget*> getControls() const;
74 /// Checks the widget validity. By default, it returns true.
75 /// \param thePrs a selected presentation in the view
76 /// \return a boolean value
77 virtual bool isValidSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
79 /// Returns true if the event is processed.
80 virtual bool processEnter();
82 /// The methiod called when widget is deactivated
83 virtual void deactivate();
85 /// Set the given wrapped value to the current widget
86 /// This value should be processed in the widget according to the needs
87 /// \param theValues the wrapped selection values
88 /// \param theToValidate a validation of the values flag
89 virtual bool setSelection(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
90 const bool theToValidate);
93 /// Saves the internal parameters to the given feature
94 /// \return True in success
95 virtual bool storeValueCustom();
97 /// Restore value from attribute data to the widget's control
98 virtual bool restoreValueCustom();
100 /// Retunrs a list of possible shape types
101 /// \return a list of shapes
102 virtual QIntList shapeTypes() const;
104 /// Redefinition of virtual function
105 /// \param theObject an object for the event
106 /// \param theEvent an event
107 virtual bool eventFilter(QObject* theObject, QEvent* theEvent);
109 //virtual void showEvent(QShowEvent* theEvent);
111 /// Return the attribute values wrapped in a list of viewer presentations
112 /// \return a list of viewer presentations, which contains an attribute result and
113 /// a shape. If the attribute do not uses the shape, it is empty
114 virtual QList<std::shared_ptr<ModuleBase_ViewerPrs>> getAttributeSelection() const;
117 /// Slot called on number of component changed
118 /// \param theVal - a new components number
119 void onNbCompChanged(int theVal);
121 /// Slot called on add a step
124 /// Slot called on remove a step
127 /// Slot called on a navigation between steps
128 /// \param theStep - a current step
129 void onStepMove(int theStep);
131 /// Slot called on a navigation between steps
132 /// \param theIdx - a current step
133 void onFieldTypeChanged(int theIdx);
135 /// Slot called on editing of a table cell
136 /// \param theRow a row of the cell
137 /// \param theCol a column of the cell
138 void onTableEdited(int theRow, int theCol);
140 /// Slot called on selection mode changed
141 /// \param theType a new choice
142 void onShapeTypeChanged(int theType);
144 /// Slot called on widget focus changed
145 /// \param theOld a widget wgich lost focus
146 /// \param theNew a widget which get focus
147 void onFocusChanged(QWidget* theOld, QWidget* theNew);
149 /// Slot called on a slider navigation changed
150 /// \param theMin - a minimal value
151 /// \param theMax a maximal value
152 void onRangeChanged(int theMin, int theMax);
154 void onColumnResize(int theIndex, int theOld, int theNew);
157 /// Clear existing tables
160 /// Append controls for management of a new step
161 void appendStepControls();
163 /// Remove current step controls
164 void removeStepControls();
166 /// Update header of a table
167 /// \param theDataTbl a table widget
168 void updateHeaders(QTableWidget* theDataTbl) const;
170 /// Return Item Id of myShapeTypeCombo by selection mode
171 /// \param theStr a selection mode
172 int getSelectionType(const std::string& theStr) const;
174 /// Return selection mode by Item Id of myShapeTypeCombo
175 /// \param theType an item id
176 std::string getSelectionType(int theType) const;
178 /// Create default table item
179 QTableWidgetItem* createDefaultItem() const;
181 /// Create a table item from the given value
182 /// \param theVal a value for the item
183 QTableWidgetItem* createValueItem(ModelAPI_AttributeTables::Value& theVal) const;
185 QString getValueText(ModelAPI_AttributeTables::Value& theVal) const;
187 /// Return a value from the string
188 /// \param theStrVal a string
189 ModelAPI_AttributeTables::Value getValue(QString theStrVal) const;
191 /// Types of shapes selection
192 QComboBox* myShapeTypeCombo;
194 /// Types of field data
195 QComboBox* myFieldTypeCombo;
197 /// Number of components
198 QSpinBox* myNbComponentsSpn;
200 /// Label of current step
201 QLabel* myCurStepLbl;
203 /// Slider for steps management
204 QSlider* myStepSlider;
207 QList<QSpinBox*> myStampSpnList;
209 /// List of created tables
210 QList<QTableWidget*> myDataTblList;
212 /// Max value Label for the slider
215 /// A container for step controls
216 QStackedWidget* myStepWgt;
218 /// A list for component names
219 QStringList myCompNamesList;
222 QPushButton* myRemoveBtn;
224 /// Editor for table header
225 QLineEdit* myHeaderEditor;
227 /// Index of header section under editing
230 /// Stae of a table editing
235 DataTableItemDelegate* myDelegate;