Version: 8.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SalomeApp_ListView.h
Go to the documentation of this file.
1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 
23 // File : SalomeApp_ListView.h
24 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
25 //
26 #ifndef SALOMEAPP_LISTVIEW_H
27 #define SALOMEAPP_LISTVIEW_H
28 
29 //#include <QtxListView.h>
30 
31 #include <SUIT_PopupClient.h>
32 
33 #include <QTreeWidget>
34 #include <QTreeWidgetItem>
35 #include <QString>
36 #include <QLineEdit>
37 #include <QComboBox>
38 
39 #include <TColStd_ListOfInteger.hxx>
40 #include <TColStd_ListOfReal.hxx>
41 
42 class QToolButton;
43 
44 // enumeration for ListView updating mode
45 enum UpdateType {
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
52 };
53 
56 
61 class SalomeApp_ListView : public QTreeWidget/*QtxListView*/ , public SUIT_PopupClient {
62 
63  Q_OBJECT
64 
65 public:
66 // constructor
67  SalomeApp_ListView(QWidget *parent);
68 // destructor
69  virtual ~SalomeApp_ListView();
70 
71 // updates list viewer
72  virtual void updateViewer();
73 // updtes currently selected item(s)
74  virtual void updateSelected();
75 
76 // fills popup with items
77  virtual QString popupClientType() const;
78  virtual void contextMenuPopup( QMenu* );
79 
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)
85  void accept();
86 
87 // clears view
88  void clear();
89 
90 // event filter
91  bool eventFilter(QObject* object, QEvent* event) ;
92 
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;
96 
97 protected:
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);
104 
105 // returns true if mouse events are enabled
106  bool isMouseEnabled();
107 // enables/disables mouse events (excluding MouseMove)
108  void enableMouse(bool enable);
109 
110 protected slots:
111 // called when selection changed in list
112  virtual void onSelectionChanged();
113 // called when user finishes in editing of item
114  void onEditOk();
115 // called when user cancels item editing
116  void onEditCancel();
117 // called when columns sizes are changed
118  void onHeaderSizeChange(int, int, int);
119 
120 protected:
125 };
126 
127 
129 {
130  Q_OBJECT
131 
132 public:
133  SalomeApp_EditBox(QWidget* parent);
134 
135 protected:
136  void keyPressEvent(QKeyEvent* e);
137 
138 signals:
139  void escapePressed();
140 };
141 
143 {
144  Q_OBJECT
145 
146 public:
147  SalomeApp_ComboBox(bool rw, QWidget* parent = 0, const char* name = 0);
148 
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);
156 };
157 
159 {
160  Q_OBJECT
161 
162 public:
163  // enum for edit control type
164  enum {
165  etLineEdit, // simple edit box
166  etComboBox, // non-editable combo box
167  etComboEdit // editable combo box
168  };
169  // enum for value type
170  enum {
171  vtString, // string
172  vtInteger, // integer value
173  vtDouble // double value
174  };
175  // enum for insertion order
176  enum {
181  };
182  // enum for edit box buttons (Apply = Cancel)
183  enum {
184  btApply = 0x0001,
185  btCancel = 0x0002
186  };
187 
188 public:
189  SalomeApp_EntityEdit( QWidget* parent,
190  int controlType = etLineEdit,
191  int valueType = vtString,
192  bool butApply = false,
193  bool butCancel = false);
195 
196  void finishEditing();
197  void clear();
198  QString getText();
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();
214  void setFocus();
215  void setValidator(const QValidator*);
216  void showButtons(bool show);
217  void setDuplicatesEnabled(bool enabled);
218 
219 protected:
220  void keyPressEvent ( QKeyEvent * e);
221 
222 private slots:
223  void onComboActivated(const QString&);
224  void onTextChanged(const QString&);
225  void onApply();
226  void onCancel();
227 signals:
228  void returnPressed();
229  void escapePressed();
230 
231 private:
232  // Widgets
237  QString myString;
238 };
239 
241 {
242 public:
247  const QStringList&,
248  const bool = false );
250  const QStringList&,
251  const bool = false );
254  const QString&,
255  const bool = false );
258  const QString&,
259  const bool = false);
262  const QString& theName,
263  const QString& theValue,
264  const bool = false);
267  const QString&,
268  const QString&,
269  const bool = false);
271 
272  QString fullName();
273  void openAllLevels();
274  virtual void updateAllLevels();
275  bool isEditable() const;
276  void setEditable(bool theEditable);
277 
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);
282 
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);
287 
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);
292 
293  // creates control for editing and fills it with values
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);
299 
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);
310 
311  // gets user type
312  virtual int getUserType();
313  // sets user type
314  virtual void setUserType(const int);
315 
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
321  QString tipText();
322  // calculates rectangle which should contain items tip
323  QRect tipRect();
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;
328 
329 protected:
330  // initialization
331  void init();
332  int depth() const;
333 
334 private:
340  int myUserType; // user are welcome to put additional data here and use it in fillWidgetWithValues()
341 };
342 
343 
344 #endif