3 // Copyright (C) 2005 CEA/DEN, EDF R&D
7 // File : SalomeApp_ListView.h
8 // Author : Vadim SANDLER
12 #ifndef SALOMEAPP_LISTVIEW_H
13 #define SALOMEAPP_LISTVIEW_H
15 #include <qlistview.h>
19 #include <qlineedit.h>
20 #include <qcombobox.h>
22 //VRV: porting on Qt 3.0.5
23 #if QT_VERSION >= 0x030005
24 #include <qtoolbutton.h>
26 //VRV: porting on Qt 3.0.5
28 #include <TColStd_ListOfInteger.hxx>
29 #include <TColStd_ListOfReal.hxx>
31 #include <SUIT_PopupClient.h>
33 // enumeration for ListView updating mode
35 utCancel = -1, // cancel updating
36 utNone = 0, // needs no any update
37 utUpdateItem, // update one item
38 utUpdateParent, // update parent item too
39 utUpdateViewer, // update all viewer
40 utUpdateAll // strong update
43 class SalomeApp_ListViewItem;
44 class SalomeApp_EntityEdit;
46 //================================================================
47 // Class : SalomeApp_ListView
48 // Description : parent class for Data Viewer and Properties Viewer
49 //================================================================
50 class SalomeApp_ListView : public QListView , public SUIT_PopupClient {
56 SalomeApp_ListView(QWidget *parent);
58 virtual ~SalomeApp_ListView();
60 // updates list viewer
61 virtual void updateViewer();
62 // updtes currently selected item(s)
63 virtual void updateSelected();
65 // fills popup with items
66 virtual QString popupClientType() const;
67 virtual void contextMenuPopup( QPopupMenu* );
69 // setting editing of items availbale/not available
70 void enableEditing(bool theFlag);
71 // says if editing is enabled
72 bool isEnableEditing();
73 // accepts user input by calling finishEditing(true)
80 bool eventFilter(QObject* object, QEvent* event) ;
82 // gets current tooltip for list view
83 // returns valid rect in success
84 QRect tip(QPoint aPos, QString& aText, QRect& dspRect, QFont& dspFnt) const;
87 // handler for resize event
88 void resizeEvent(QResizeEvent* e);
89 // handler for paint event
90 void viewportPaintEvent(QPaintEvent* e);
91 // finishes editing of entity
92 virtual UpdateType finishEditing(bool ok);
94 // returns true if mouse events are enabled
95 bool isMouseEnabled();
96 // enables/disables mouse events (excluding MouseMove)
97 void enableMouse(bool enable);
100 // called when selection changed in list
101 virtual void onSelectionChanged();
102 // called when user finishes in editing of item
104 // called when user cancels item editing
106 // called when columns sizes are changed
107 void onHeaderSizeChange(int, int, int);
110 SalomeApp_EntityEdit* myEdit;
111 SalomeApp_ListViewItem* myEditedItem;
112 bool myEditingEnabled;
117 class SalomeApp_EditBox: public QLineEdit
122 SalomeApp_EditBox(QWidget* parent);
125 void keyPressEvent(QKeyEvent* e);
128 void escapePressed();
131 class SalomeApp_ComboBox: public QComboBox
136 SalomeApp_ComboBox(bool rw, QWidget* parent = 0, const char* name = 0);
138 int findItem(const QString& theText);
139 void insertItem(const QString& theValue, int theIndex = -1);
140 void insertList(const QStringList& theList);
141 void insertItem(const int theValue);
142 void insertList(const TColStd_ListOfInteger& theList);
143 void insertItem(const double theValue);
144 void insertList(const TColStd_ListOfReal& theList);
147 class SalomeApp_EntityEdit : public QWidget
152 // enum for edit control type
154 etLineEdit, // simple edit box
155 etComboBox, // non-editable combo box
156 etComboEdit // editable combo box
158 // enum for value type
161 vtInteger, // integer value
162 vtDouble // double value
164 // enum for insertion order
171 // enum for edit box buttons (Apply = Cancel)
178 SalomeApp_EntityEdit( QWidget* parent,
179 int controlType = etLineEdit,
180 int valueType = vtString,
181 bool butApply = false,
182 bool butCancel = false);
183 ~SalomeApp_EntityEdit();
185 void finishEditing();
188 void setText(const QString& theText );
189 void insertItem( const QString& theValue,
190 bool theSetCurrent = false,
191 int theOrder = atBottom );
192 void insertList( const QStringList& theList,
193 const int theCurrent = -1 );
194 void insertItem( const int theValue,
195 bool theSetCurrent = false );
196 void insertList( const TColStd_ListOfInteger& theList,
197 const int theCurrent = -1 );
198 void insertItem( const double theValue,
199 bool theSetCurrent = false );
200 void insertList( const TColStd_ListOfReal& theList,
201 const int theCurrent = -1 );
202 QWidget* getControl();
204 void setValidator(const QValidator*);
205 void showButtons(bool show);
206 void setDuplicatesEnabled(bool enabled);
209 void keyPressEvent ( QKeyEvent * e);
212 void onComboActivated(const QString&);
213 void onTextChanged(const QString&);
217 void returnPressed();
218 void escapePressed();
222 SalomeApp_EditBox* myEdit;
223 SalomeApp_ComboBox* myCombo;
224 QToolButton* myApplyBtn;
225 QToolButton* myCancelBtn;
229 class SalomeApp_ListViewItem : public QListViewItem
232 SalomeApp_ListViewItem( SalomeApp_ListView* );
233 SalomeApp_ListViewItem( SalomeApp_ListView*,
234 SalomeApp_ListViewItem* );
235 SalomeApp_ListViewItem( SalomeApp_ListView*,
237 const bool = false );
238 SalomeApp_ListViewItem( SalomeApp_ListView*,
239 const QString& theName,
240 const QString& theValue,
241 const bool = false );
242 SalomeApp_ListViewItem( SalomeApp_ListViewItem* theParent,
244 const bool = false );
245 SalomeApp_ListViewItem( SalomeApp_ListView*,
246 SalomeApp_ListViewItem*,
248 const bool = false );
249 SalomeApp_ListViewItem( SalomeApp_ListViewItem*,
250 SalomeApp_ListViewItem*,
253 SalomeApp_ListViewItem( SalomeApp_ListViewItem*,
254 const QString& theName,
255 const QString& theValue,
257 SalomeApp_ListViewItem( SalomeApp_ListView*,
258 SalomeApp_ListViewItem*,
259 const QString& theName,
260 const QString& theValue,
262 SalomeApp_ListViewItem( SalomeApp_ListViewItem*,
263 SalomeApp_ListViewItem*,
267 ~SalomeApp_ListViewItem();
270 void openAllLevels();
271 virtual void updateAllLevels();
272 bool isEditable() const;
273 void setEditable(bool theEditable);
275 // returns true if entitiy is accepted after editing
276 bool isAccepted() const;
277 // set entity accepted or not after editing
278 void setAccepted(bool theAccepted);
280 // returns name of entity (as default it is text in first column)
281 virtual QString getName() const;
282 // sets name of entity (as default it is text in first column)
283 virtual UpdateType setName(const QString& theName);
285 // returns value of entity (as default it is text in second column)
286 virtual QString getValue() const;
287 // sets value of entity (as default it is text in second column)
288 virtual UpdateType setValue(const QString& theValue);
290 // creates control for editing and fills it with values
291 SalomeApp_EntityEdit* startEditing();
292 // fills widget with initial values (list or single value)
293 virtual void fillWidgetWithValues(SalomeApp_EntityEdit* theWidget);
294 // finishes editing of entity
295 virtual UpdateType finishEditing(SalomeApp_EntityEdit* theWidget);
297 // returns type of edit control (0 - edit box, 1 - combo box, 2 - editable combo box)
298 virtual int getEditingType();
299 // sets type of edit control (0 - edit box, 1 - combo box, 2 - editable combo box)
300 virtual void setEditingType(const int);
301 // returns edited column
302 virtual int getEditedColumn();
303 // returns type of edited value (string, int, double)
304 virtual int getValueType();
305 // sets type of edited value (string, int, double)
306 virtual void setValueType(const int);
309 virtual int getUserType();
311 virtual void setUserType(const int);
313 // returns buttons for editing widget
314 virtual int getButtons();
315 // sets buttons for editing widget
316 virtual void setButtons(const int);
317 // returns text for tooltip
319 // calculates rectangle which should contain items tip
321 // calculates rect of item text in viewport coordinates
322 QRect textRect(const int column) const;
323 // calculates full rect of item data in viewport coordinates
324 QRect itemRect(const int column) const;
336 int myUserType; // user are welcome to put additional data here and use it in fillWidgetWithValues()