Salome HOME
Merge branch 'Pre_2.8.0_development'
[modules/shaper.git] / src / CollectionPlugin / CollectionPlugin_WidgetField.h
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #ifndef CollectionPlugin_WidgetField_H
22 #define CollectionPlugin_WidgetField_H
23
24
25 #include "CollectionPlugin.h"
26
27 #include <ModuleBase_WidgetSelector.h>
28 #include <ModuleBase_ViewerPrs.h>
29 #include <ModelAPI_AttributeTables.h>
30
31 #include <QList>
32 #include <QStringList>
33 #include <QStyledItemDelegate>
34
35
36 class QWidget;
37 class QComboBox;
38 class QSpinBox;
39 class QLabel;
40 class QSlider;
41 class QTableWidget;
42 class QStackedWidget;
43 class QPushButton;
44 class QTableWidgetItem;
45 class QLineEdit;
46
47
48 class DataTableItemDelegate : public QStyledItemDelegate
49 {
50  Q_OBJECT
51 public:
52   DataTableItemDelegate(ModelAPI_AttributeTables::ValueType theType);
53
54   virtual QWidget* createEditor(QWidget* theParent,
55                                 const QStyleOptionViewItem & theOption,
56                                 const QModelIndex& theIndex) const;
57
58   ModelAPI_AttributeTables::ValueType dataType() const { return myType; }
59
60   void setDataType(ModelAPI_AttributeTables::ValueType theType) { myType = theType; }
61
62 private slots:
63   void onEditItem(const QString& theText);
64
65 private:
66   ModelAPI_AttributeTables::ValueType myType;
67 };
68
69
70
71 /*!
72  * \ingroup GUI
73  * Represent a content of the property panel to show/modify parameters of a Field feature.
74  */
75 class CollectionPlugin_WidgetField : public ModuleBase_WidgetSelector
76 {
77  Q_OBJECT
78 public:
79   CollectionPlugin_WidgetField(QWidget* theParent,
80                                ModuleBase_IWorkshop* theWorkshop,
81                                const Config_WidgetAPI* theData);
82
83   virtual ~CollectionPlugin_WidgetField() {}
84
85   /// Returns list of widget controls
86   /// \return a control list
87   virtual QList<QWidget*> getControls() const;
88
89   /// Checks the widget validity. By default, it returns true.
90   /// \param thePrs a selected presentation in the view
91   /// \return a boolean value
92   virtual bool isValidSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
93
94   /// Returns true if the event is processed.
95   virtual bool processEnter();
96
97   /// The methiod called when widget is deactivated
98   virtual void deactivate();
99
100   /// Set the given wrapped value to the current widget
101   /// This value should be processed in the widget according to the needs
102   /// \param theValues the wrapped selection values
103   /// \param theToValidate a validation of the values flag
104   virtual bool setSelection(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
105                             const bool theToValidate);
106
107 protected:
108   /// Saves the internal parameters to the given feature
109   /// \return True in success
110   virtual bool storeValueCustom();
111
112   /// Restore value from attribute data to the widget's control
113   virtual bool restoreValueCustom();
114
115   /// Retunrs a list of possible shape types
116   /// \return a list of shapes
117   virtual QIntList shapeTypes() const;
118
119   /// Redefinition of virtual function
120   /// \param theObject an object for the event
121   /// \param theEvent an event
122   virtual bool eventFilter(QObject* theObject, QEvent* theEvent);
123
124   //virtual void showEvent(QShowEvent* theEvent);
125
126   /// Return the attribute values wrapped in a list of viewer presentations
127   /// \return a list of viewer presentations, which contains an attribute result and
128   /// a shape. If the attribute do not uses the shape, it is empty
129   virtual QList<std::shared_ptr<ModuleBase_ViewerPrs>> getAttributeSelection() const;
130
131 private slots:
132   /// Slot called on number of component changed
133   /// \param theVal - a new components number
134   void onNbCompChanged(int theVal);
135
136   /// Slot called on add a step
137   void onAddStep();
138
139   /// Slot called on remove a step
140   void onRemoveStep();
141
142   /// Slot called on a navigation between steps
143   /// \param theStep - a current step
144   void onStepMove(int theStep);
145
146   /// Slot called on a navigation between steps
147   /// \param theIdx - a current step
148   void onFieldTypeChanged(int theIdx);
149
150   /// Slot called on editing of a table cell
151   /// \param theRow a row of the cell
152   /// \param theCol a column of the cell
153   void onTableEdited(int theRow, int theCol);
154
155   /// Slot called on selection mode changed
156   /// \param theType a new choice
157   void onShapeTypeChanged(int theType);
158
159   /// Slot called on widget focus changed
160   /// \param theOld a widget wgich lost focus
161   /// \param theNew a widget which get focus
162   void onFocusChanged(QWidget* theOld, QWidget* theNew);
163
164   /// Slot called on a slider navigation changed
165   /// \param theMin - a minimal value
166   /// \param theMax a maximal value
167   void onRangeChanged(int theMin, int theMax);
168
169   void onColumnResize(int theIndex, int theOld, int theNew);
170
171 private:
172   /// Clear existing tables
173   void clearData();
174
175   /// Append controls for management of a new step
176   void appendStepControls();
177
178   /// Remove current step controls
179   void removeStepControls();
180
181   /// Update header of a table
182   /// \param theDataTbl a table widget
183   void updateHeaders(QTableWidget* theDataTbl) const;
184
185   /// Return Item Id of myShapeTypeCombo by selection mode
186   /// \param theStr a selection mode
187   int getSelectionType(const std::string& theStr) const;
188
189   /// Return selection mode by Item Id of myShapeTypeCombo
190   /// \param theType an item id
191   std::string getSelectionType(int theType) const;
192
193   /// Create default table item
194   QTableWidgetItem* createDefaultItem() const;
195
196   /// Create a table item from the given value
197   /// \param theVal a value for the item
198   QTableWidgetItem* createValueItem(ModelAPI_AttributeTables::Value& theVal) const;
199
200   QString getValueText(ModelAPI_AttributeTables::Value& theVal) const;
201
202   /// Return a value from the string
203   /// \param theStrVal a string
204   ModelAPI_AttributeTables::Value getValue(QString theStrVal) const;
205
206   /// Types of shapes selection
207   QComboBox* myShapeTypeCombo;
208
209   /// Types of field data
210   QComboBox* myFieldTypeCombo;
211
212   /// Number of components
213   QSpinBox* myNbComponentsSpn;
214
215   /// Label of current step
216   QLabel* myCurStepLbl;
217
218   /// Slider for steps management
219   QSlider* myStepSlider;
220
221   /// Stamp value
222   QList<QSpinBox*> myStampSpnList;
223
224   /// List of created tables
225   QList<QTableWidget*> myDataTblList;
226
227   /// Max value Label for the slider
228   QLabel* myMaxLbl;
229
230   /// A container for step controls
231   QStackedWidget* myStepWgt;
232
233   /// A list for component names
234   QStringList myCompNamesList;
235
236   /// Remove button
237   QPushButton* myRemoveBtn;
238
239   /// Editor for table header
240   QLineEdit* myHeaderEditor;
241
242   /// Index of header section under editing
243   int myEditIndex;
244
245   /// Stae of a table editing
246   bool myIsTabEdit;
247
248   bool myActivation;
249
250   DataTableItemDelegate* myDelegate;
251 };
252
253 #endif