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();
86 /// Saves the internal parameters to the given feature
87 /// \return True in success
88 virtual bool storeValueCustom();
90 /// Restore value from attribute data to the widget's control
91 virtual bool restoreValueCustom();
93 /// Retunrs a list of possible shape types
94 /// \return a list of shapes
95 virtual QIntList shapeTypes() const;
97 /// Redefinition of virtual function
98 /// \param theObject an object for the event
99 /// \param theEvent an event
100 virtual bool eventFilter(QObject* theObject, QEvent* theEvent);
102 //virtual void showEvent(QShowEvent* theEvent);
105 /// Slot which is called on selection event
106 virtual void onSelectionChanged();
109 /// Slot called on number of component changed
110 /// \param theVal - a new components number
111 void onNbCompChanged(int theVal);
113 /// Slot called on add a step
116 /// Slot called on remove a step
119 /// Slot called on a navigation between steps
120 /// \param theStep - a current step
121 void onStepMove(int theStep);
123 /// Slot called on a navigation between steps
124 /// \param theIdx - a current step
125 void onFieldTypeChanged(int theIdx);
127 /// Slot called on editing of a table cell
128 /// \param theRow a row of the cell
129 /// \param theCol a column of the cell
130 void onTableEdited(int theRow, int theCol);
132 /// Slot called on selection mode changed
133 /// \param theType a new choice
134 void onShapeTypeChanged(int theType);
136 /// Slot called on widget focus changed
137 /// \param theOld a widget wgich lost focus
138 /// \param theNew a widget which get focus
139 void onFocusChanged(QWidget* theOld, QWidget* theNew);
141 /// Slot called on a slider navigation changed
142 /// \param theMin - a minimal value
143 /// \param theMax a maximal value
144 void onRangeChanged(int theMin, int theMax);
146 void onColumnResize(int theIndex, int theOld, int theNew);
149 /// Clear existing tables
152 /// Append controls for management of a new step
153 void appendStepControls();
155 /// Remove current step controls
156 void removeStepControls();
158 /// Update header of a table
159 /// \param theDataTbl a table widget
160 void updateHeaders(QTableWidget* theDataTbl) const;
162 /// Return Item Id of myShapeTypeCombo by selection mode
163 /// \param theStr a selection mode
164 int getSelectionType(const std::string& theStr) const;
166 /// Return selection mode by Item Id of myShapeTypeCombo
167 /// \param theType an item id
168 std::string getSelectionType(int theType) const;
170 /// Create default table item
171 QTableWidgetItem* createDefaultItem() const;
173 /// Create a table item from the given value
174 /// \param theVal a value for the item
175 QTableWidgetItem* createValueItem(ModelAPI_AttributeTables::Value& theVal) const;
177 QString getValueText(ModelAPI_AttributeTables::Value& theVal) const;
179 /// Return a value from the string
180 /// \param theStrVal a string
181 ModelAPI_AttributeTables::Value getValue(QString theStrVal) const;
183 /// Types of shapes selection
184 QComboBox* myShapeTypeCombo;
186 /// Types of field data
187 QComboBox* myFieldTypeCombo;
189 /// Number of components
190 QSpinBox* myNbComponentsSpn;
192 /// Label of current step
193 QLabel* myCurStepLbl;
195 /// Slider for steps management
196 QSlider* myStepSlider;
199 QList<QSpinBox*> myStampSpnList;
201 /// List of created tables
202 QList<QTableWidget*> myDataTblList;
204 /// Max value Label for the slider
207 /// A container for step controls
208 QStackedWidget* myStepWgt;
210 /// A list for component names
211 QStringList myCompNamesList;
214 QPushButton* myRemoveBtn;
216 /// Editor for table header
217 QLineEdit* myHeaderEditor;
219 /// Index of header section under editing
222 /// Stae of a table editing
227 DataTableItemDelegate* myDelegate;