1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: CollectionPlugin_WidgetField.h
4 // Created: 16 Nov 2016
5 // Author: Vitaly SMETANNIKOV
8 #ifndef CollectionPlugin_WidgetField_H
9 #define CollectionPlugin_WidgetField_H
12 #include "CollectionPlugin.h"
14 #include <ModuleBase_WidgetSelector.h>
15 #include <ModuleBase_ViewerPrs.h>
16 #include <ModelAPI_AttributeTables.h>
19 #include <QStringList>
30 class QTableWidgetItem;
35 * Represent a content of the property panel to show/modify parameters of a Field feature.
37 class CollectionPlugin_WidgetField : public ModuleBase_WidgetSelector
41 CollectionPlugin_WidgetField(QWidget* theParent,
42 ModuleBase_IWorkshop* theWorkshop,
43 const Config_WidgetAPI* theData);
45 virtual ~CollectionPlugin_WidgetField() {}
47 /// Returns list of widget controls
48 /// \return a control list
49 virtual QList<QWidget*> getControls() const;
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);
56 /// Returns true if the event is processed.
57 virtual bool processEnter();
59 /// The methiod called when widget is deactivated
60 virtual void deactivate();
63 /// Saves the internal parameters to the given feature
64 /// \return True in success
65 virtual bool storeValueCustom();
67 /// Restore value from attribute data to the widget's control
68 virtual bool restoreValueCustom();
70 /// Retunrs a list of possible shape types
71 /// \return a list of shapes
72 virtual QIntList shapeTypes() const;
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);
81 /// Slot which is called on selection event
82 virtual void onSelectionChanged();
85 /// Slot called on number of component changed
86 /// \param theVal - a new components number
87 void onNbCompChanged(int theVal);
89 /// Slot called on add a step
92 /// Slot called on remove a step
95 /// Slot called on a navigation between steps
96 /// \param theStep - a current step
97 void onStepMove(int theStep);
99 /// Slot called on a navigation between steps
100 /// \param theIdx - a current step
101 void onFieldTypeChanged(int theIdx);
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);
108 /// Slot called on selection mode changed
109 /// \param theType a new choice
110 void onShapeTypeChanged(int theType);
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);
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);
123 /// Clear existing tables
126 /// Append controls for management of a new step
127 void appendStepControls();
129 /// Remove current step controls
130 void removeStepControls();
132 /// Update header of a table
133 /// \param theDataTbl a table widget
134 void updateHeaders(QTableWidget* theDataTbl) const;
136 /// Return Item Id of myShapeTypeCombo by selection mode
137 /// \param theStr a selection mode
138 int getSelectionType(const std::string& theStr) const;
140 /// Return selection mode by Item Id of myShapeTypeCombo
141 /// \param theType an item id
142 std::string getSelectionType(int theType) const;
144 /// Create default table item
145 QTableWidgetItem* createDefaultItem() const;
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;
151 /// Return a value from the string
152 /// \param theStrVal a string
153 ModelAPI_AttributeTables::Value getValue(QString theStrVal) const;
155 /// Types of shapes selection
156 QComboBox* myShapeTypeCombo;
158 /// Types of field data
159 QComboBox* myFieldTypeCombo;
161 /// Number of components
162 QSpinBox* myNbComponentsSpn;
164 /// Label of current step
165 QLabel* myCurStepLbl;
167 /// Slider for steps management
168 QSlider* myStepSlider;
171 QList<QSpinBox*> myStampSpnList;
173 /// List of created tables
174 QList<QTableWidget*> myDataTblList;
176 /// Max value Label for the slider
179 /// A container for step controls
180 QStackedWidget* myStepWgt;
182 /// A list for component names
183 QStringList myCompNamesList;
186 QPushButton* myRemoveBtn;
188 /// Editor for table header
189 QLineEdit* myHeaderEditor;
191 /// Index of header section under editing
194 /// Stae of a table editing