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