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