Salome HOME
Issue #1954: Set type of data into items delegate on restore data
[modules/shaper.git] / src / CollectionPlugin / CollectionPlugin_WidgetField.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        CollectionPlugin_WidgetField.h
4 // Created:     16 Nov 2016
5 // Author:      Vitaly SMETANNIKOV
6
7
8 #ifndef CollectionPlugin_WidgetField_H
9 #define CollectionPlugin_WidgetField_H
10
11
12 #include "CollectionPlugin.h"
13
14 #include <ModuleBase_WidgetSelector.h>
15 #include <ModuleBase_ViewerPrs.h>
16 #include <ModelAPI_AttributeTables.h>
17
18 #include <QList>
19 #include <QStringList>
20 #include <QStyledItemDelegate>
21
22
23 class QWidget;
24 class QComboBox;
25 class QSpinBox;
26 class QLabel;
27 class QSlider;
28 class QTableWidget;
29 class QStackedWidget;
30 class QPushButton;
31 class QTableWidgetItem;
32 class QLineEdit;
33
34
35 class DataTableItemDelegate : public QStyledItemDelegate
36 {
37  Q_OBJECT
38 public:
39   DataTableItemDelegate(ModelAPI_AttributeTables::ValueType theType) :
40       QStyledItemDelegate() { myType = theType; }
41
42   virtual QWidget* createEditor(QWidget* theParent,
43                                 const QStyleOptionViewItem & theOption,
44                                 const QModelIndex& theIndex) const;
45
46   ModelAPI_AttributeTables::ValueType dataType() const { return myType; }
47
48   void setDataType(ModelAPI_AttributeTables::ValueType theType) { myType = theType; }
49
50 private:
51   ModelAPI_AttributeTables::ValueType myType;
52 };
53
54
55
56 /*!
57  * \ingroup GUI
58  * Represent a content of the property panel to show/modify parameters of a Field feature.
59  */
60 class CollectionPlugin_WidgetField : public ModuleBase_WidgetSelector
61 {
62  Q_OBJECT
63 public:
64   CollectionPlugin_WidgetField(QWidget* theParent,
65                                ModuleBase_IWorkshop* theWorkshop,
66                                const Config_WidgetAPI* theData);
67
68   virtual ~CollectionPlugin_WidgetField() {}
69
70   /// Returns list of widget controls
71   /// \return a control list
72   virtual QList<QWidget*> getControls() const;
73
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);
78
79   /// Returns true if the event is processed.
80   virtual bool processEnter();
81
82   /// The methiod called when widget is deactivated
83   virtual void deactivate();
84
85 protected:
86   /// Saves the internal parameters to the given feature
87   /// \return True in success
88   virtual bool storeValueCustom();
89
90   /// Restore value from attribute data to the widget's control
91   virtual bool restoreValueCustom();
92
93   /// Retunrs a list of possible shape types
94   /// \return a list of shapes
95   virtual QIntList shapeTypes() const;
96
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);
101
102   //virtual void showEvent(QShowEvent* theEvent);
103
104 protected slots:
105   /// Slot which is called on selection event
106   virtual void onSelectionChanged();
107
108 private slots:
109   /// Slot called on number of component changed
110   /// \param theVal - a new components number
111   void onNbCompChanged(int theVal);
112
113   /// Slot called on add a step
114   void onAddStep();
115
116   /// Slot called on remove a step
117   void onRemoveStep();
118
119   /// Slot called on a navigation between steps
120   /// \param theStep - a current step
121   void onStepMove(int theStep);
122
123   /// Slot called on a navigation between steps
124   /// \param theIdx - a current step
125   void onFieldTypeChanged(int theIdx);
126
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);
131
132   /// Slot called on selection mode changed
133   /// \param theType a new choice
134   void onShapeTypeChanged(int theType);
135
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);
140
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);
145
146   void onColumnResize(int theIndex, int theOld, int theNew);
147
148 private:
149   /// Clear existing tables
150   void clearData();
151
152   /// Append controls for management of a new step
153   void appendStepControls();
154
155   /// Remove current step controls
156   void removeStepControls();
157
158   /// Update header of a table
159   /// \param theDataTbl a table widget
160   void updateHeaders(QTableWidget* theDataTbl) const;
161
162   /// Return Item Id of myShapeTypeCombo by selection mode
163   /// \param theStr a selection mode
164   int getSelectionType(const std::string& theStr) const;
165
166   /// Return selection mode by Item Id of myShapeTypeCombo
167   /// \param theType an item id
168   std::string getSelectionType(int theType) const;
169
170   /// Create default table item
171   QTableWidgetItem* createDefaultItem() const;
172
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;
176
177   QString getValueText(ModelAPI_AttributeTables::Value& theVal) const;
178
179   /// Return a value from the string
180   /// \param theStrVal a string
181   ModelAPI_AttributeTables::Value getValue(QString theStrVal) const;
182
183   /// Types of shapes selection
184   QComboBox* myShapeTypeCombo;
185
186   /// Types of field data
187   QComboBox* myFieldTypeCombo;
188
189   /// Number of components
190   QSpinBox* myNbComponentsSpn;
191
192   /// Label of current step
193   QLabel* myCurStepLbl;
194
195   /// Slider for steps management
196   QSlider* myStepSlider;
197
198   /// Stamp value
199   QList<QSpinBox*> myStampSpnList;
200
201   /// List of created tables
202   QList<QTableWidget*> myDataTblList;
203
204   /// Max value Label for the slider
205   QLabel* myMaxLbl;
206
207   /// A container for step controls
208   QStackedWidget* myStepWgt;
209
210   /// A list for component names
211   QStringList myCompNamesList;
212
213   /// Remove button
214   QPushButton* myRemoveBtn;
215
216   /// Editor for table header
217   QLineEdit* myHeaderEditor;
218
219   /// Index of header section under editing
220   int myEditIndex;
221
222   /// Stae of a table editing
223   bool myIsTabEdit;
224
225   bool myActivation;
226
227   DataTableItemDelegate* myDelegate;
228 };
229
230 #endif