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);
41 virtual QWidget* createEditor(QWidget* theParent,
42 const QStyleOptionViewItem & theOption,
43 const QModelIndex& theIndex) const;
45 ModelAPI_AttributeTables::ValueType dataType() const { return myType; }
47 void setDataType(ModelAPI_AttributeTables::ValueType theType) { myType = theType; }
50 // bool eventFilter(QObject* theObj, QEvent* theEvent);
53 void onEditItem(const QString& theText);
56 ModelAPI_AttributeTables::ValueType myType;
63 * Represent a content of the property panel to show/modify parameters of a Field feature.
65 class CollectionPlugin_WidgetField : public ModuleBase_WidgetSelector
69 CollectionPlugin_WidgetField(QWidget* theParent,
70 ModuleBase_IWorkshop* theWorkshop,
71 const Config_WidgetAPI* theData);
73 virtual ~CollectionPlugin_WidgetField() {}
75 /// Returns list of widget controls
76 /// \return a control list
77 virtual QList<QWidget*> getControls() const;
79 /// Checks the widget validity. By default, it returns true.
80 /// \param thePrs a selected presentation in the view
81 /// \return a boolean value
82 virtual bool isValidSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
84 /// Returns true if the event is processed.
85 virtual bool processEnter();
87 /// The methiod called when widget is deactivated
88 virtual void deactivate();
90 /// Set the given wrapped value to the current widget
91 /// This value should be processed in the widget according to the needs
92 /// \param theValues the wrapped selection values
93 /// \param theToValidate a validation of the values flag
94 virtual bool setSelection(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
95 const bool theToValidate);
98 /// Saves the internal parameters to the given feature
99 /// \return True in success
100 virtual bool storeValueCustom();
102 /// Restore value from attribute data to the widget's control
103 virtual bool restoreValueCustom();
105 /// Retunrs a list of possible shape types
106 /// \return a list of shapes
107 virtual QIntList shapeTypes() const;
109 /// Redefinition of virtual function
110 /// \param theObject an object for the event
111 /// \param theEvent an event
112 virtual bool eventFilter(QObject* theObject, QEvent* theEvent);
114 //virtual void showEvent(QShowEvent* theEvent);
116 /// Return the attribute values wrapped in a list of viewer presentations
117 /// \return a list of viewer presentations, which contains an attribute result and
118 /// a shape. If the attribute do not uses the shape, it is empty
119 virtual QList<std::shared_ptr<ModuleBase_ViewerPrs>> getAttributeSelection() const;
122 /// Slot called on number of component changed
123 /// \param theVal - a new components number
124 void onNbCompChanged(int theVal);
126 /// Slot called on add a step
129 /// Slot called on remove a step
132 /// Slot called on a navigation between steps
133 /// \param theStep - a current step
134 void onStepMove(int theStep);
136 /// Slot called on a navigation between steps
137 /// \param theIdx - a current step
138 void onFieldTypeChanged(int theIdx);
140 /// Slot called on editing of a table cell
141 /// \param theRow a row of the cell
142 /// \param theCol a column of the cell
143 void onTableEdited(int theRow, int theCol);
145 /// Slot called on selection mode changed
146 /// \param theType a new choice
147 void onShapeTypeChanged(int theType);
149 /// Slot called on widget focus changed
150 /// \param theOld a widget wgich lost focus
151 /// \param theNew a widget which get focus
152 void onFocusChanged(QWidget* theOld, QWidget* theNew);
154 /// Slot called on a slider navigation changed
155 /// \param theMin - a minimal value
156 /// \param theMax a maximal value
157 void onRangeChanged(int theMin, int theMax);
159 void onColumnResize(int theIndex, int theOld, int theNew);
162 /// Clear existing tables
165 /// Append controls for management of a new step
166 void appendStepControls();
168 /// Remove current step controls
169 void removeStepControls();
171 /// Update header of a table
172 /// \param theDataTbl a table widget
173 void updateHeaders(QTableWidget* theDataTbl) const;
175 /// Return Item Id of myShapeTypeCombo by selection mode
176 /// \param theStr a selection mode
177 int getSelectionType(const std::string& theStr) const;
179 /// Return selection mode by Item Id of myShapeTypeCombo
180 /// \param theType an item id
181 std::string getSelectionType(int theType) const;
183 /// Create default table item
184 QTableWidgetItem* createDefaultItem() const;
186 /// Create a table item from the given value
187 /// \param theVal a value for the item
188 QTableWidgetItem* createValueItem(ModelAPI_AttributeTables::Value& theVal) const;
190 QString getValueText(ModelAPI_AttributeTables::Value& theVal) const;
192 /// Return a value from the string
193 /// \param theStrVal a string
194 ModelAPI_AttributeTables::Value getValue(QString theStrVal) const;
196 /// Types of shapes selection
197 QComboBox* myShapeTypeCombo;
199 /// Types of field data
200 QComboBox* myFieldTypeCombo;
202 /// Number of components
203 QSpinBox* myNbComponentsSpn;
205 /// Label of current step
206 QLabel* myCurStepLbl;
208 /// Slider for steps management
209 QSlider* myStepSlider;
212 QList<QSpinBox*> myStampSpnList;
214 /// List of created tables
215 QList<QTableWidget*> myDataTblList;
217 /// Max value Label for the slider
220 /// A container for step controls
221 QStackedWidget* myStepWgt;
223 /// A list for component names
224 QStringList myCompNamesList;
227 QPushButton* myRemoveBtn;
229 /// Editor for table header
230 QLineEdit* myHeaderEditor;
232 /// Index of header section under editing
235 /// Stae of a table editing
240 DataTableItemDelegate* myDelegate;