Salome HOME
Issue #1961: Filter not acceptable shapes and objects
[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   /// Set the given wrapped value to the current widget
86   /// This value should be processed in the widget according to the needs
87   /// \param theValues the wrapped selection values
88   /// \param theToValidate a validation of the values flag
89   virtual bool setSelection(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
90                             const bool theToValidate);
91
92 protected:
93   /// Saves the internal parameters to the given feature
94   /// \return True in success
95   virtual bool storeValueCustom();
96
97   /// Restore value from attribute data to the widget's control
98   virtual bool restoreValueCustom();
99
100   /// Retunrs a list of possible shape types
101   /// \return a list of shapes
102   virtual QIntList shapeTypes() const;
103
104   /// Redefinition of virtual function
105   /// \param theObject an object for the event
106   /// \param theEvent an event
107   virtual bool eventFilter(QObject* theObject, QEvent* theEvent);
108
109   //virtual void showEvent(QShowEvent* theEvent);
110
111   /// Return the attribute values wrapped in a list of viewer presentations
112   /// \return a list of viewer presentations, which contains an attribute result and
113   /// a shape. If the attribute do not uses the shape, it is empty
114   virtual QList<std::shared_ptr<ModuleBase_ViewerPrs>> getAttributeSelection() const;
115
116 private slots:
117   /// Slot called on number of component changed
118   /// \param theVal - a new components number
119   void onNbCompChanged(int theVal);
120
121   /// Slot called on add a step
122   void onAddStep();
123
124   /// Slot called on remove a step
125   void onRemoveStep();
126
127   /// Slot called on a navigation between steps
128   /// \param theStep - a current step
129   void onStepMove(int theStep);
130
131   /// Slot called on a navigation between steps
132   /// \param theIdx - a current step
133   void onFieldTypeChanged(int theIdx);
134
135   /// Slot called on editing of a table cell
136   /// \param theRow a row of the cell
137   /// \param theCol a column of the cell
138   void onTableEdited(int theRow, int theCol);
139
140   /// Slot called on selection mode changed
141   /// \param theType a new choice
142   void onShapeTypeChanged(int theType);
143
144   /// Slot called on widget focus changed
145   /// \param theOld a widget wgich lost focus
146   /// \param theNew a widget which get focus
147   void onFocusChanged(QWidget* theOld, QWidget* theNew);
148
149   /// Slot called on a slider navigation changed
150   /// \param theMin - a minimal value
151   /// \param theMax a maximal value
152   void onRangeChanged(int theMin, int theMax);
153
154   void onColumnResize(int theIndex, int theOld, int theNew);
155
156 private:
157   /// Clear existing tables
158   void clearData();
159
160   /// Append controls for management of a new step
161   void appendStepControls();
162
163   /// Remove current step controls
164   void removeStepControls();
165
166   /// Update header of a table
167   /// \param theDataTbl a table widget
168   void updateHeaders(QTableWidget* theDataTbl) const;
169
170   /// Return Item Id of myShapeTypeCombo by selection mode
171   /// \param theStr a selection mode
172   int getSelectionType(const std::string& theStr) const;
173
174   /// Return selection mode by Item Id of myShapeTypeCombo
175   /// \param theType an item id
176   std::string getSelectionType(int theType) const;
177
178   /// Create default table item
179   QTableWidgetItem* createDefaultItem() const;
180
181   /// Create a table item from the given value
182   /// \param theVal a value for the item
183   QTableWidgetItem* createValueItem(ModelAPI_AttributeTables::Value& theVal) const;
184
185   QString getValueText(ModelAPI_AttributeTables::Value& theVal) const;
186
187   /// Return a value from the string
188   /// \param theStrVal a string
189   ModelAPI_AttributeTables::Value getValue(QString theStrVal) const;
190
191   /// Types of shapes selection
192   QComboBox* myShapeTypeCombo;
193
194   /// Types of field data
195   QComboBox* myFieldTypeCombo;
196
197   /// Number of components
198   QSpinBox* myNbComponentsSpn;
199
200   /// Label of current step
201   QLabel* myCurStepLbl;
202
203   /// Slider for steps management
204   QSlider* myStepSlider;
205
206   /// Stamp value
207   QList<QSpinBox*> myStampSpnList;
208
209   /// List of created tables
210   QList<QTableWidget*> myDataTblList;
211
212   /// Max value Label for the slider
213   QLabel* myMaxLbl;
214
215   /// A container for step controls
216   QStackedWidget* myStepWgt;
217
218   /// A list for component names
219   QStringList myCompNamesList;
220
221   /// Remove button
222   QPushButton* myRemoveBtn;
223
224   /// Editor for table header
225   QLineEdit* myHeaderEditor;
226
227   /// Index of header section under editing
228   int myEditIndex;
229
230   /// Stae of a table editing
231   bool myIsTabEdit;
232
233   bool myActivation;
234
235   DataTableItemDelegate* myDelegate;
236 };
237
238 #endif