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 isValidSelectionCustom(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);
79 //virtual void showEvent(QShowEvent* theEvent);
82 /// Slot which is called on selection event
83 virtual void onSelectionChanged();
86 /// Slot called on number of component changed
87 /// \param theVal - a new components number
88 void onNbCompChanged(int theVal);
90 /// Slot called on add a step
93 /// Slot called on remove a step
96 /// Slot called on a navigation between steps
97 /// \param theStep - a current step
98 void onStepMove(int theStep);
100 /// Slot called on a navigation between steps
101 /// \param theIdx - a current step
102 void onFieldTypeChanged(int theIdx);
104 /// Slot called on editing of a table cell
105 /// \param theRow a row of the cell
106 /// \param theCol a column of the cell
107 void onTableEdited(int theRow, int theCol);
109 /// Slot called on selection mode changed
110 /// \param theType a new choice
111 void onShapeTypeChanged(int theType);
113 /// Slot called on widget focus changed
114 /// \param theOld a widget wgich lost focus
115 /// \param theNew a widget which get focus
116 void onFocusChanged(QWidget* theOld, QWidget* theNew);
118 /// Slot called on a slider navigation changed
119 /// \param theMin - a minimal value
120 /// \param theMax a maximal value
121 void onRangeChanged(int theMin, int theMax);
123 void onColumnResize(int theIndex, int theOld, int theNew);
126 /// Clear existing tables
129 /// Append controls for management of a new step
130 void appendStepControls();
132 /// Remove current step controls
133 void removeStepControls();
135 /// Update header of a table
136 /// \param theDataTbl a table widget
137 void updateHeaders(QTableWidget* theDataTbl) const;
139 /// Return Item Id of myShapeTypeCombo by selection mode
140 /// \param theStr a selection mode
141 int getSelectionType(const std::string& theStr) const;
143 /// Return selection mode by Item Id of myShapeTypeCombo
144 /// \param theType an item id
145 std::string getSelectionType(int theType) const;
147 /// Create default table item
148 QTableWidgetItem* createDefaultItem() const;
150 /// Create a table item from the given value
151 /// \param theVal a value for the item
152 QTableWidgetItem* createValueItem(ModelAPI_AttributeTables::Value& theVal) const;
154 QString getValueText(ModelAPI_AttributeTables::Value& theVal) const;
156 /// Return a value from the string
157 /// \param theStrVal a string
158 ModelAPI_AttributeTables::Value getValue(QString theStrVal) const;
160 /// Types of shapes selection
161 QComboBox* myShapeTypeCombo;
163 /// Types of field data
164 QComboBox* myFieldTypeCombo;
166 /// Number of components
167 QSpinBox* myNbComponentsSpn;
169 /// Label of current step
170 QLabel* myCurStepLbl;
172 /// Slider for steps management
173 QSlider* myStepSlider;
176 QList<QSpinBox*> myStampSpnList;
178 /// List of created tables
179 QList<QTableWidget*> myDataTblList;
181 /// Max value Label for the slider
184 /// A container for step controls
185 QStackedWidget* myStepWgt;
187 /// A list for component names
188 QStringList myCompNamesList;
191 QPushButton* myRemoveBtn;
193 /// Editor for table header
194 QLineEdit* myHeaderEditor;
196 /// Index of header section under editing
199 /// Stae of a table editing