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