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