Salome HOME
Merge remote-tracking branch 'remotes/origin/master' into BR_coding_rules
[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
21
22 class QWidget;
23 class QComboBox;
24 class QSpinBox;
25 class QLabel;
26 class QSlider;
27 class QTableWidget;
28 class QStackedWidget;
29 class QPushButton;
30 class QTableWidgetItem;
31 class QLineEdit;
32
33 /*!
34  * \ingroup GUI
35  * Represent a content of the property panel to show/modify parameters of a Field feature.
36  */
37 class CollectionPlugin_WidgetField : public ModuleBase_WidgetSelector
38 {
39  Q_OBJECT
40 public:
41   CollectionPlugin_WidgetField(QWidget* theParent, 
42                                ModuleBase_IWorkshop* theWorkshop, 
43                                const Config_WidgetAPI* theData);
44
45   virtual ~CollectionPlugin_WidgetField() {}
46
47   /// Returns list of widget controls
48   /// \return a control list
49   virtual QList<QWidget*> getControls() const;
50
51   /// Checks the widget validity. By default, it returns true.
52   /// \param thePrs a selected presentation in the view
53   /// \return a boolean value
54   virtual bool isValidSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
55
56   /// Returns true if the event is processed.
57   virtual bool processEnter();
58
59   /// The methiod called when widget is deactivated
60   virtual void deactivate();
61
62 protected:
63   /// Saves the internal parameters to the given feature
64   /// \return True in success
65   virtual bool storeValueCustom();
66
67   /// Restore value from attribute data to the widget's control
68   virtual bool restoreValueCustom();
69
70   /// Retunrs a list of possible shape types
71   /// \return a list of shapes
72   virtual QIntList shapeTypes() const;
73
74   /// Redefinition of virtual function
75   /// \param theObject an object for the event
76   /// \param theEvent an event
77   virtual bool eventFilter(QObject* theObject, QEvent* theEvent);
78
79
80 protected slots:
81   /// Slot which is called on selection event
82   virtual void onSelectionChanged();
83
84 private slots:
85   /// Slot called on number of component changed
86   /// \param theVal - a new components number
87   void onNbCompChanged(int theVal);
88
89   /// Slot called on add a step
90   void onAddStep();
91
92   /// Slot called on remove a step
93   void onRemoveStep();
94
95   /// Slot called on a navigation between steps
96   /// \param theStep - a current step
97   void onStepMove(int theStep);
98
99   /// Slot called on a navigation between steps
100   /// \param theIdx - a current step
101   void onFieldTypeChanged(int theIdx);
102
103   /// Slot called on editing of a table cell
104   /// \param theRow a row of the cell
105   /// \param theCol a column of the cell
106   void onTableEdited(int theRow, int theCol);
107
108   /// Slot called on selection mode changed
109   /// \param theType a new choice
110   void onShapeTypeChanged(int theType);
111
112   /// Slot called on widget focus changed
113   /// \param theOld a widget wgich lost focus
114   /// \param theNew a widget which get focus
115   void onFocusChanged(QWidget* theOld, QWidget* theNew);
116
117   /// Slot called on a slider navigation changed
118   /// \param theMin - a minimal value
119   /// \param theMax a maximal value
120   void onRangeChanged(int theMin, int theMax);
121
122 private:
123   /// Clear existing tables
124   void clearData();
125
126   /// Append controls for management of a new step
127   void appendStepControls();
128
129   /// Remove current step controls
130   void removeStepControls();
131
132   /// Update header of a table
133   /// \param theDataTbl a table widget
134   void updateHeaders(QTableWidget* theDataTbl) const;
135
136   /// Return Item Id of myShapeTypeCombo by selection mode
137   /// \param theStr a selection mode
138   int getSelectionType(const std::string& theStr) const;
139
140   /// Return selection mode by Item Id of myShapeTypeCombo
141   /// \param theType an item id
142   std::string getSelectionType(int theType) const;
143
144   /// Create default table item
145   QTableWidgetItem* createDefaultItem() const;
146
147   /// Create a table item from the given value
148   /// \param theVal a value for the item
149   QTableWidgetItem* createValueItem(ModelAPI_AttributeTables::Value& theVal) const;
150
151   /// Return a value from the string
152   /// \param theStrVal a string
153   ModelAPI_AttributeTables::Value getValue(QString theStrVal) const;
154
155   /// Types of shapes selection
156   QComboBox* myShapeTypeCombo;
157
158   /// Types of field data
159   QComboBox* myFieldTypeCombo;
160
161   /// Number of components
162   QSpinBox* myNbComponentsSpn;
163
164   /// Label of current step
165   QLabel* myCurStepLbl;
166
167   /// Slider for steps management
168   QSlider* myStepSlider;
169
170   /// Stamp value
171   QList<QSpinBox*> myStampSpnList;
172
173   /// List of created tables
174   QList<QTableWidget*> myDataTblList;
175
176   /// Max value Label for the slider
177   QLabel* myMaxLbl;
178
179   /// A container for step controls
180   QStackedWidget* myStepWgt;
181
182   /// A list for component names
183   QStringList myCompNamesList;
184
185   /// Remove button
186   QPushButton* myRemoveBtn;
187
188   /// Editor for table header
189   QLineEdit* myHeaderEditor;
190
191   /// Index of header section under editing
192   int myEditIndex;
193
194   /// Stae of a table editing
195   bool myIsEditing;
196
197   bool myActivation;
198 };
199
200 #endif