Salome HOME
Store content of table item when user presses Ok button
[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
41   virtual QWidget* createEditor(QWidget* theParent,
42                                 const QStyleOptionViewItem & theOption,
43                                 const QModelIndex& theIndex) const;
44
45   ModelAPI_AttributeTables::ValueType dataType() const { return myType; }
46
47   void setDataType(ModelAPI_AttributeTables::ValueType theType) { myType = theType; }
48
49 //protected:
50 //  bool eventFilter(QObject* theObj, QEvent* theEvent);
51
52 private slots:
53   void onEditItem(const QString& theText);
54
55 private:
56   ModelAPI_AttributeTables::ValueType myType;
57 };
58
59
60
61 /*!
62  * \ingroup GUI
63  * Represent a content of the property panel to show/modify parameters of a Field feature.
64  */
65 class CollectionPlugin_WidgetField : public ModuleBase_WidgetSelector
66 {
67  Q_OBJECT
68 public:
69   CollectionPlugin_WidgetField(QWidget* theParent,
70                                ModuleBase_IWorkshop* theWorkshop,
71                                const Config_WidgetAPI* theData);
72
73   virtual ~CollectionPlugin_WidgetField() {}
74
75   /// Returns list of widget controls
76   /// \return a control list
77   virtual QList<QWidget*> getControls() const;
78
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);
83
84   /// Returns true if the event is processed.
85   virtual bool processEnter();
86
87   /// The methiod called when widget is deactivated
88   virtual void deactivate();
89
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);
96
97 protected:
98   /// Saves the internal parameters to the given feature
99   /// \return True in success
100   virtual bool storeValueCustom();
101
102   /// Restore value from attribute data to the widget's control
103   virtual bool restoreValueCustom();
104
105   /// Retunrs a list of possible shape types
106   /// \return a list of shapes
107   virtual QIntList shapeTypes() const;
108
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);
113
114   //virtual void showEvent(QShowEvent* theEvent);
115
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;
120
121 private slots:
122   /// Slot called on number of component changed
123   /// \param theVal - a new components number
124   void onNbCompChanged(int theVal);
125
126   /// Slot called on add a step
127   void onAddStep();
128
129   /// Slot called on remove a step
130   void onRemoveStep();
131
132   /// Slot called on a navigation between steps
133   /// \param theStep - a current step
134   void onStepMove(int theStep);
135
136   /// Slot called on a navigation between steps
137   /// \param theIdx - a current step
138   void onFieldTypeChanged(int theIdx);
139
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);
144
145   /// Slot called on selection mode changed
146   /// \param theType a new choice
147   void onShapeTypeChanged(int theType);
148
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);
153
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);
158
159   void onColumnResize(int theIndex, int theOld, int theNew);
160
161 private:
162   /// Clear existing tables
163   void clearData();
164
165   /// Append controls for management of a new step
166   void appendStepControls();
167
168   /// Remove current step controls
169   void removeStepControls();
170
171   /// Update header of a table
172   /// \param theDataTbl a table widget
173   void updateHeaders(QTableWidget* theDataTbl) const;
174
175   /// Return Item Id of myShapeTypeCombo by selection mode
176   /// \param theStr a selection mode
177   int getSelectionType(const std::string& theStr) const;
178
179   /// Return selection mode by Item Id of myShapeTypeCombo
180   /// \param theType an item id
181   std::string getSelectionType(int theType) const;
182
183   /// Create default table item
184   QTableWidgetItem* createDefaultItem() const;
185
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;
189
190   QString getValueText(ModelAPI_AttributeTables::Value& theVal) const;
191
192   /// Return a value from the string
193   /// \param theStrVal a string
194   ModelAPI_AttributeTables::Value getValue(QString theStrVal) const;
195
196   /// Types of shapes selection
197   QComboBox* myShapeTypeCombo;
198
199   /// Types of field data
200   QComboBox* myFieldTypeCombo;
201
202   /// Number of components
203   QSpinBox* myNbComponentsSpn;
204
205   /// Label of current step
206   QLabel* myCurStepLbl;
207
208   /// Slider for steps management
209   QSlider* myStepSlider;
210
211   /// Stamp value
212   QList<QSpinBox*> myStampSpnList;
213
214   /// List of created tables
215   QList<QTableWidget*> myDataTblList;
216
217   /// Max value Label for the slider
218   QLabel* myMaxLbl;
219
220   /// A container for step controls
221   QStackedWidget* myStepWgt;
222
223   /// A list for component names
224   QStringList myCompNamesList;
225
226   /// Remove button
227   QPushButton* myRemoveBtn;
228
229   /// Editor for table header
230   QLineEdit* myHeaderEditor;
231
232   /// Index of header section under editing
233   int myEditIndex;
234
235   /// Stae of a table editing
236   bool myIsTabEdit;
237
238   bool myActivation;
239
240   DataTableItemDelegate* myDelegate;
241 };
242
243 #endif