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);
122 void onColumnResize(int theIndex, int theOld, int theNew);
125 /// Clear existing tables
128 /// Append controls for management of a new step
129 void appendStepControls();
131 /// Remove current step controls
132 void removeStepControls();
134 /// Update header of a table
135 /// \param theDataTbl a table widget
136 void updateHeaders(QTableWidget* theDataTbl) const;
138 /// Return Item Id of myShapeTypeCombo by selection mode
139 /// \param theStr a selection mode
140 int getSelectionType(const std::string& theStr) const;
142 /// Return selection mode by Item Id of myShapeTypeCombo
143 /// \param theType an item id
144 std::string getSelectionType(int theType) const;
146 /// Create default table item
147 QTableWidgetItem* createDefaultItem() const;
149 /// Create a table item from the given value
150 /// \param theVal a value for the item
151 QTableWidgetItem* createValueItem(ModelAPI_AttributeTables::Value& theVal) const;
153 QString getValueText(ModelAPI_AttributeTables::Value& theVal) const;
155 /// Return a value from the string
156 /// \param theStrVal a string
157 ModelAPI_AttributeTables::Value getValue(QString theStrVal) const;
159 /// Types of shapes selection
160 QComboBox* myShapeTypeCombo;
162 /// Types of field data
163 QComboBox* myFieldTypeCombo;
165 /// Number of components
166 QSpinBox* myNbComponentsSpn;
168 /// Label of current step
169 QLabel* myCurStepLbl;
171 /// Slider for steps management
172 QSlider* myStepSlider;
175 QList<QSpinBox*> myStampSpnList;
177 /// List of created tables
178 QList<QTableWidget*> myDataTblList;
180 /// Max value Label for the slider
183 /// A container for step controls
184 QStackedWidget* myStepWgt;
186 /// A list for component names
187 QStringList myCompNamesList;
190 QPushButton* myRemoveBtn;
192 /// Editor for table header
193 QLineEdit* myHeaderEditor;
195 /// Index of header section under editing
198 /// Stae of a table editing