1 // File : QAD_ListView.h
2 // Created : 24/10/2002
3 // Descr : List view for editing of properties
5 // Author : Vadim SANDLER
6 // Project : SALOME Pro
8 // Copyright : Open CASCADE
11 #if !defined(_QAD_ListView_HeaderFile)
12 #define _QAD_ListView_HeaderFile
14 #include <qlistview.h>
18 #include <qlineedit.h>
19 #include <qcombobox.h>
21 //VRV: porting on Qt 3.0.5
22 #if QT_VERSION >= 0x030005
23 #include <qtoolbutton.h>
25 //VRV: porting on Qt 3.0.5
27 #include "QAD_Popup.h"
29 #include <TColStd_ListOfInteger.hxx>
30 #include <TColStd_ListOfReal.hxx>
32 // enumeration for ListView updating mode
34 utCancel = -1, // cancel updating
35 utNone = 0, // needs no any update
36 utUpdateItem, // update one item
37 utUpdateParent, // update parent item too
38 utUpdateViewer, // update all viewer
39 utUpdateAll // strong update
42 class QAD_ListViewItem;
45 //================================================================
46 // Class : QAD_ListView
47 // Description : parent class for Data Viewer and Properties Viewer
48 //================================================================
49 class QAD_ListView : public QListView , public QAD_PopupServer {
55 QAD_ListView(QWidget *parent);
57 virtual ~QAD_ListView();
59 // updates list viewer
60 virtual void updateViewer();
61 // updtes currently selected item(s)
62 virtual void updateSelected();
64 // fills popup with items
67 void deletePopupMenu();
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 mouse button release event (execute popup menu)
88 void contentsMouseReleaseEvent(QMouseEvent* e);
89 // handler for resize event
90 void resizeEvent(QResizeEvent* e);
91 // handler for paint event
92 void viewportPaintEvent(QPaintEvent* e);
93 // finishes editing of entity
94 virtual UpdateType finishEditing(bool ok);
96 // returns true if mouse events are enabled
97 bool isMouseEnabled();
98 // enables/disables mouse events (excluding MouseMove)
99 void enableMouse(bool enable);
102 // called when selection changed in list
103 virtual void onSelectionChanged();
104 // called when user finishes in editing of item
106 // called when user cancels item editing
108 // called when columns sizes are changed
109 void onHeaderSizeChange(int, int, int);
112 QAD_EntityEdit* myEdit;
113 QAD_ListViewItem* myEditedItem;
114 bool myEditingEnabled;
119 //================================================================
120 // Class : QAD_ListViewItem
121 // Purpose : List Viewer entity
122 //================================================================
123 class QAD_ListViewItem : public QListViewItem {
127 QAD_ListViewItem(QAD_ListView* parent);
129 QAD_ListViewItem(QAD_ListView* parent,
130 QAD_ListViewItem* after);
132 QAD_ListViewItem(QAD_ListView* parent,
133 const QString theName,
134 const bool theEditable = false);
136 QAD_ListViewItem(QAD_ListView* parent,
137 const QString theName,
138 const QString theValue,
139 const bool theEditable = false);
141 QAD_ListViewItem(QAD_ListViewItem* parent,
142 const QString theName,
143 const bool theEditable = false);
145 QAD_ListViewItem(QAD_ListView* parent,
146 QAD_ListViewItem* after,
147 const QString theName,
148 const bool theEditable = false);
150 QAD_ListViewItem(QAD_ListViewItem* parent,
151 QAD_ListViewItem* after,
152 const QString theName,
153 const bool theEditable = false);
155 QAD_ListViewItem(QAD_ListViewItem* parent,
156 const QString theName,
157 const QString theValue,
158 const bool theEditable = false);
160 QAD_ListViewItem(QAD_ListView* parent,
161 QAD_ListViewItem* after,
162 const QString theName,
163 const QString theValue,
164 const bool theEditable = false);
166 QAD_ListViewItem(QAD_ListViewItem* parent,
167 QAD_ListViewItem* after,
168 const QString theName,
169 const QString theValue,
170 const bool theEditable = false);
174 // returns full path to the entity (full name)
177 // expands all entities beginning from this level
178 void openAllLevels();
179 // updates all entites beginning from this level
180 virtual void updateAllLevels();
182 // returns true if entity can be edited
183 bool isEditable() const;
184 // set entity as editable/uneditable
185 void setEditable(bool theEditable);
187 // returns true if entitiy is accepted after editing
188 bool isAccepted() const;
189 // set entity accepted or not after editing
190 void setAccepted(bool theAccepted);
192 // returns name of entity (as default it is text in first column)
193 virtual QString getName() const;
194 // sets name of entity (as default it is text in first column)
195 virtual UpdateType setName(const QString theName);
197 // returns value of entity (as default it is text in second column)
198 virtual QString getValue() const;
199 // sets value of entity (as default it is text in second column)
200 virtual UpdateType setValue(const QString theValue);
202 // creates control for editing and fills it with values
203 QAD_EntityEdit* startEditing();
204 // fills widget with initial values (list or single value)
205 virtual void fillWidgetWithValues(QAD_EntityEdit* theWidget);
206 // finishes editing of entity
207 virtual UpdateType finishEditing(QAD_EntityEdit* theWidget);
209 // returns type of edit control (0 - edit box, 1 - combo box, 2 - editable combo box)
210 virtual int getEditingType();
211 // sets type of edit control (0 - edit box, 1 - combo box, 2 - editable combo box)
212 virtual void setEditingType(const int);
213 // returns edited column
214 virtual int getEditedColumn();
215 // returns type of edited value (string, int, double)
216 virtual int getValueType();
217 // sets type of edited value (string, int, double)
218 virtual void setValueType(const int);
221 virtual int getUserType();
223 virtual void setUserType(const int);
225 // returns buttons for editing widget
226 virtual int getButtons();
227 // sets buttons for editing widget
228 virtual void setButtons(const int);
229 // returns text for tooltip
231 // calculates rectangle which should contain items tip
233 // calculates rect of item text in viewport coordinates
234 QRect textRect(const int column) const;
235 // calculates full rect of item data in viewport coordinates
236 QRect itemRect(const int column) const;
248 int myUserType; // user are welcome to put additional data here and use it in fillWidgetWithValues()
252 //================================================================
253 // Class : QAD_EditBox
254 // Description : edit box for list entity editing
255 //================================================================
256 class QAD_EditBox: public QLineEdit {
262 QAD_EditBox(QWidget* parent);
265 // event filter (for KeyPress event)
266 void keyPressEvent(QKeyEvent* e);
269 void escapePressed();
274 //================================================================
275 // Class : QAD_ComboBox
276 // Description : combo box for list entity editing
277 //================================================================
278 class QAD_ComboBox: public QComboBox {
284 QAD_ComboBox(bool rw, QWidget* parent = 0, const char* name = 0);
286 // searches item in list and returns its index
287 int findItem(const QString theText);
288 // adds item in combo box
289 void insertItem(const QString& theValue, int theIndex = -1);
290 // adds list of items in combo box
291 void insertList(const QStringList& theList);
292 // adds item in combo box
293 void insertItem(const int theValue);
294 // adds list of items in combo box
295 void insertList(const TColStd_ListOfInteger& theList);
296 // adds item in combo box
297 void insertItem(const double theValue);
298 // adds list of items in combo box
299 void insertList(const TColStd_ListOfReal& theList);
304 //================================================================
305 // Class : QAD_EntityEdit
306 // Description : edit control for QAD List View
307 //================================================================
308 class QAD_EntityEdit : public QWidget {
313 // enum for edit control type
315 etLineEdit, // simple edit box
316 etComboBox, // non-editable combo box
317 etComboEdit // editable combo box
319 // enum for value type
322 vtInteger, // integer value
323 vtDouble // double value
325 // enum for insertion order
332 // enum for edit box buttons (Apply = Cancel)
339 QAD_EntityEdit(QWidget* parent,
340 int controlType = etLineEdit,
341 int valueType = vtString,
342 bool butApply = false,
343 bool butCancel = false);
348 void finishEditing();
349 // clears edit/combo box
351 // returns current text in edit box or combo box
354 void setText(const QString& theText);
355 // adds item in combo box
356 void insertItem(const QString& theValue,
357 bool theSetCurrent = false,
358 int theOrder = atBottom);
359 // adds list of items in combo box
360 void insertList(const QStringList& theList,
361 const int theCurrent = -1);
362 // adds item in combo box
363 void insertItem(const int theValue,
364 bool theSetCurrent = false);
365 // adds list of items in combo box
366 void insertList(const TColStd_ListOfInteger& theList,
367 const int theCurrent = -1);
368 // adds item in combo box
369 void insertItem(const double theValue,
370 bool theSetCurrent = false);
371 // adds list of items in combo box
372 void insertList(const TColStd_ListOfReal& theList,
373 const int theCurrent = -1);
374 // gets actual widget
375 QWidget* getControl();
376 // redirect focus to corresponding widget
378 // sets validator for the control
379 void setValidator(const QValidator*);
380 // shows/hides buttons
381 void showButtons(bool show);
382 // enables/disables data duplication (for combo box)
383 void setDuplicatesEnabled(bool enabled);
386 // event filter for KeyPress event
387 void keyPressEvent ( QKeyEvent * e);
390 // called when item activated in combo box
391 void onComboActivated(const QString&);
392 // called when text changed in control
393 void onTextChanged(const QString&);
394 // called when user presses Apply button
396 // called when user presses Cancel button
400 void returnPressed();
401 void escapePressed();
406 QAD_ComboBox* myCombo;
407 QToolButton* myApplyBtn;
408 QToolButton* myCancelBtn;