1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : SalomeApp_ListView.h
24 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
26 #ifndef SALOMEAPP_LISTVIEW_H
27 #define SALOMEAPP_LISTVIEW_H
29 //#include <QtxListView.h>
31 #include <SUIT_PopupClient.h>
33 #include <QTreeWidget>
34 #include <QTreeWidgetItem>
39 #include <TColStd_ListOfInteger.hxx>
40 #include <TColStd_ListOfReal.hxx>
44 // enumeration for ListView updating mode
46 utCancel = -1, // cancel updating
47 utNone = 0, // needs no any update
48 utUpdateItem, // update one item
49 utUpdateParent, // update parent item too
50 utUpdateViewer, // update all viewer
51 utUpdateAll // strong update
54 class SalomeApp_ListViewItem;
55 class SalomeApp_EntityEdit;
58 \class SalomeApp_ListView
59 parent class for Data Viewer and Properties Viewer
61 class SalomeApp_ListView : public QTreeWidget/*QtxListView*/ , public SUIT_PopupClient {
67 SalomeApp_ListView(QWidget *parent);
69 virtual ~SalomeApp_ListView();
71 // updates list viewer
72 virtual void updateViewer();
73 // updtes currently selected item(s)
74 virtual void updateSelected();
76 // fills popup with items
77 virtual QString popupClientType() const;
78 virtual void contextMenuPopup( QMenu* );
80 // setting editing of items availbale/not available
81 void enableEditing(bool theFlag);
82 // says if editing is enabled
83 bool isEnableEditing();
84 // accepts user input by calling finishEditing(true)
91 bool eventFilter(QObject* object, QEvent* event) ;
93 // gets current tooltip for list view
94 // returns valid rect in success
95 QRect tip(QPoint aPos, QString& aText, QRect& dspRect, QFont& dspFnt) const;
98 // handler for resize event
99 void resizeEvent(QResizeEvent* e);
100 // handler for paint event
101 void viewportPaintEvent(QPaintEvent* e);
102 // finishes editing of entity
103 virtual UpdateType finishEditing(bool ok);
105 // returns true if mouse events are enabled
106 bool isMouseEnabled();
107 // enables/disables mouse events (excluding MouseMove)
108 void enableMouse(bool enable);
111 // called when selection changed in list
112 virtual void onSelectionChanged();
113 // called when user finishes in editing of item
115 // called when user cancels item editing
117 // called when columns sizes are changed
118 void onHeaderSizeChange(int, int, int);
121 SalomeApp_EntityEdit* myEdit;
122 SalomeApp_ListViewItem* myEditedItem;
123 bool myEditingEnabled;
128 class SalomeApp_EditBox: public QLineEdit
133 SalomeApp_EditBox(QWidget* parent);
136 void keyPressEvent(QKeyEvent* e);
139 void escapePressed();
142 class SalomeApp_ComboBox: public QComboBox
147 SalomeApp_ComboBox(bool rw, QWidget* parent = 0, const char* name = 0);
149 int findItem(const QString& theText);
150 void insertItem(const QString& theValue, int theIndex = -1);
151 void insertList(const QStringList& theList);
152 void insertItem(const int theValue);
153 void insertList(const TColStd_ListOfInteger& theList);
154 void insertItem(const double theValue);
155 void insertList(const TColStd_ListOfReal& theList);
158 class SalomeApp_EntityEdit : public QWidget
163 // enum for edit control type
165 etLineEdit, // simple edit box
166 etComboBox, // non-editable combo box
167 etComboEdit // editable combo box
169 // enum for value type
172 vtInteger, // integer value
173 vtDouble // double value
175 // enum for insertion order
182 // enum for edit box buttons (Apply = Cancel)
189 SalomeApp_EntityEdit( QWidget* parent,
190 int controlType = etLineEdit,
191 int valueType = vtString,
192 bool butApply = false,
193 bool butCancel = false);
194 ~SalomeApp_EntityEdit();
196 void finishEditing();
199 void setText(const QString& theText );
200 void insertItem( const QString& theValue,
201 bool theSetCurrent = false,
202 int theOrder = atBottom );
203 void insertList( const QStringList& theList,
204 const int theCurrent = -1 );
205 void insertItem( const int theValue,
206 bool theSetCurrent = false );
207 void insertList( const TColStd_ListOfInteger& theList,
208 const int theCurrent = -1 );
209 void insertItem( const double theValue,
210 bool theSetCurrent = false );
211 void insertList( const TColStd_ListOfReal& theList,
212 const int theCurrent = -1 );
213 QWidget* getControl();
215 void setValidator(const QValidator*);
216 void showButtons(bool show);
217 void setDuplicatesEnabled(bool enabled);
220 void keyPressEvent ( QKeyEvent * e);
223 void onComboActivated(const QString&);
224 void onTextChanged(const QString&);
228 void returnPressed();
229 void escapePressed();
233 SalomeApp_EditBox* myEdit;
234 SalomeApp_ComboBox* myCombo;
235 QToolButton* myApplyBtn;
236 QToolButton* myCancelBtn;
240 class SalomeApp_ListViewItem : public QTreeWidgetItem
243 SalomeApp_ListViewItem( SalomeApp_ListView* );
244 SalomeApp_ListViewItem( SalomeApp_ListView*,
245 SalomeApp_ListViewItem* );
246 SalomeApp_ListViewItem( SalomeApp_ListView*,
248 const bool = false );
249 SalomeApp_ListViewItem( SalomeApp_ListViewItem*,
251 const bool = false );
252 SalomeApp_ListViewItem( SalomeApp_ListView*,
253 SalomeApp_ListViewItem*,
255 const bool = false );
256 SalomeApp_ListViewItem( SalomeApp_ListViewItem*,
257 SalomeApp_ListViewItem*,
260 SalomeApp_ListViewItem( SalomeApp_ListView*,
261 SalomeApp_ListViewItem*,
262 const QString& theName,
263 const QString& theValue,
265 SalomeApp_ListViewItem( SalomeApp_ListViewItem*,
266 SalomeApp_ListViewItem*,
270 ~SalomeApp_ListViewItem();
273 void openAllLevels();
274 virtual void updateAllLevels();
275 bool isEditable() const;
276 void setEditable(bool theEditable);
278 // returns true if entitiy is accepted after editing
279 bool isAccepted() const;
280 // set entity accepted or not after editing
281 void setAccepted(bool theAccepted);
283 // returns name of entity (as default it is text in first column)
284 virtual QString getName() const;
285 // sets name of entity (as default it is text in first column)
286 virtual UpdateType setName(const QString& theName);
288 // returns value of entity (as default it is text in second column)
289 virtual QString getValue() const;
290 // sets value of entity (as default it is text in second column)
291 virtual UpdateType setValue(const QString& theValue);
293 // creates control for editing and fills it with values
294 SalomeApp_EntityEdit* startEditing();
295 // fills widget with initial values (list or single value)
296 virtual void fillWidgetWithValues(SalomeApp_EntityEdit* theWidget);
297 // finishes editing of entity
298 virtual UpdateType finishEditing(SalomeApp_EntityEdit* theWidget);
300 // returns type of edit control (0 - edit box, 1 - combo box, 2 - editable combo box)
301 virtual int getEditingType();
302 // sets type of edit control (0 - edit box, 1 - combo box, 2 - editable combo box)
303 virtual void setEditingType(const int);
304 // returns edited column
305 virtual int getEditedColumn();
306 // returns type of edited value (string, int, double)
307 virtual int getValueType();
308 // sets type of edited value (string, int, double)
309 virtual void setValueType(const int);
312 virtual int getUserType();
314 virtual void setUserType(const int);
316 // returns buttons for editing widget
317 virtual int getButtons();
318 // sets buttons for editing widget
319 virtual void setButtons(const int);
320 // returns text for tooltip
322 // calculates rectangle which should contain items tip
324 // calculates rect of item text in viewport coordinates
325 QRect textRect(const int column) const;
326 // calculates full rect of item data in viewport coordinates
327 QRect itemRect(const int column) const;
340 int myUserType; // user are welcome to put additional data here and use it in fillWidgetWithValues()