ParaView
pqFlatTreeView.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ParaView
4  Module: pqFlatTreeView.h
5 
6  Copyright (c) 2005-2008 Sandia Corporation, Kitware Inc.
7  All rights reserved.
8 
9  ParaView is a free software; you can redistribute it and/or modify it
10  under the terms of the ParaView license version 1.2.
11 
12  See License_v1.2.txt for the full ParaView license.
13  A copy of this license can be obtained by contacting
14  Kitware Inc.
15  28 Corporate Drive
16  Clifton Park, NY 12065
17  USA
18 
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
23 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 =========================================================================*/
32 
35 
36 #ifndef _pqFlatTreeView_h
37 #define _pqFlatTreeView_h
38 
39 
40 #include "pqWidgetsModule.h"
41 #include <QAbstractScrollArea>
42 #include <QModelIndex> // Needed for return type
43 #include <QStyleOptionViewItem> // Needed for return type
44 
45 class pqFlatTreeViewItem;
46 class pqFlatTreeViewItemRows;
47 class pqFlatTreeViewInternal;
48 
49 class QAbstractItemModel;
50 class QColor;
51 class QFontMetrics;
52 class QHeaderView;
53 class QItemSelection;
54 class QItemSelectionModel;
55 class QPoint;
56 class QRect;
57 
58 
72 class PQWIDGETS_EXPORT pqFlatTreeView : public QAbstractScrollArea
73 {
74  Q_OBJECT
75 
76 public:
78  {
81  SelectColumns
82  };
83 
85  {
88  ExtendedSelection
89  };
90 
91 public:
95  pqFlatTreeView(QWidget *parent=0);
96  virtual ~pqFlatTreeView();
97 
106  virtual bool eventFilter(QObject *object, QEvent *e);
107 
109 
110  QAbstractItemModel *getModel() const {return this->Model;}
111  void setModel(QAbstractItemModel *model);
112 
113  QModelIndex getRootIndex() const;
114  void setRootIndex(const QModelIndex &index);
116 
118 
119  QItemSelectionModel *getSelectionModel() const {return this->Selection;}
120  void setSelectionModel(QItemSelectionModel *selectionModel);
121 
122  SelectionBehavior getSelectionBehavior() const {return this->Behavior;}
123  void setSelectionBehavior(SelectionBehavior behavior);
124 
125  SelectionMode getSelectionMode() const {return this->Mode;}
126  void setSelectionMode(SelectionMode mode);
128 
130 
131  QHeaderView *getHeader() const {return this->HeaderView;}
132  void setHeader(QHeaderView *headerView);
133 
143  bool isColumnSizeManaged() const {return this->ManageSizes;}
144 
150  void setColumnSizeManaged(bool managed);
152 
154 
155  int getIconSize() const;
156  void setIconSize(int iconSize);
158 
160 
161  bool isIndexHidden(const QModelIndex &index) const;
162  void getVisibleRect(const QModelIndex &index, QRect &area) const;
163  QModelIndex getIndexVisibleAt(const QPoint &point) const;
164  QModelIndex getIndexCellAt(const QPoint &point) const;
165  void getSelectionIn(const QRect &rect, QItemSelection &items) const;
167 
169 
170  bool isIndexExpanded(const QModelIndex &index) const;
171  QModelIndex getNextVisibleIndex(const QModelIndex &index,
172  const QModelIndex &root=QModelIndex()) const;
173  QModelIndex getRelativeIndex(const QString &id,
174  const QModelIndex &root=QModelIndex()) const;
175  void getRelativeIndexId(const QModelIndex &index, QString &id,
176  const QModelIndex &root=QModelIndex()) const;
178 
180 
181  bool startEditing(const QModelIndex &index);
182  void finishEditing();
183  void cancelEditing();
185 
186 signals:
187  void activated(const QModelIndex &index);
188  void clicked(const QModelIndex &index);
189 
190 public slots:
191  void reset();
192  void selectAll();
193  void setCurrentIndex(const QModelIndex &index);
194  void expandAll();
195  void expand(const QModelIndex &index);
196  void collapse(const QModelIndex &index);
197  void scrollTo(const QModelIndex &index);
198 
199 protected slots:
201 
202  void insertRows(const QModelIndex &parent, int start, int end);
203  void startRowRemoval(const QModelIndex &parent, int start, int end);
204  void finishRowRemoval(const QModelIndex &parent, int start, int end);
205  void insertColumns(const QModelIndex &parent, int start, int end);
206  void startColumnRemoval(const QModelIndex &parent, int start, int end);
207  void finishColumnRemoval(const QModelIndex &parent, int start, int end);
208  void updateData(const QModelIndex &topLeft, const QModelIndex &bottomRight);
210 
211 protected:
213 
214  virtual void keyPressEvent(QKeyEvent *e);
215  void keyboardSearch(const QString &search);
217 
219 
220  virtual void mousePressEvent(QMouseEvent *e);
221  virtual void mouseMoveEvent(QMouseEvent *e);
222  virtual void mouseReleaseEvent(QMouseEvent *e);
223  virtual void mouseDoubleClickEvent(QMouseEvent *e);
224  virtual void wheelEvent(QWheelEvent *e);
226 
228 
229  virtual bool event(QEvent *e);
231 
232  int horizontalOffset() const;
233  int verticalOffset() const;
234 
235  virtual void resizeEvent(QResizeEvent *e);
236  virtual bool viewportEvent(QEvent *e);
237  virtual void paintEvent(QPaintEvent *e);
238  QStyleOptionViewItem getViewOptions() const;
239 
240 private slots:
242 
243  void handleSectionResized(int index, int oldSize, int newSize);
244  void handleSectionMoved(int index, int oldVisual, int newVisual);
246 
248 
249  void changeCurrent(const QModelIndex &current, const QModelIndex &previous);
250  void changeCurrentRow(const QModelIndex &current,
251  const QModelIndex &previous);
252  void changeCurrentColumn(const QModelIndex &current,
253  const QModelIndex &previous);
254  void changeSelection(const QItemSelection &selected,
255  const QItemSelection &deselected);
257 
258 private:
259  void resetRoot();
260  void resetPreferredSizes();
261 
263 
264  void layoutEditor();
265  void layoutItems();
266  void layoutItem(pqFlatTreeViewItem *item, int &point,
267  const QFontMetrics &fm);
268  int getDataWidth(const QModelIndex &index, const QFontMetrics &fm) const;
269  int getWidthSum(pqFlatTreeViewItem *item, int column) const;
270  bool updateContentsWidth();
271  void updateScrollBars();
272  void addChildItems(pqFlatTreeViewItem *item, int parentChildCount);
274 
276 
277  bool getIndexRowList(const QModelIndex &index,
278  pqFlatTreeViewItemRows &rowList) const;
279  pqFlatTreeViewItem *getItem(const pqFlatTreeViewItemRows &rowList) const;
280  pqFlatTreeViewItem *getItem(const QModelIndex &index) const;
281  pqFlatTreeViewItem *getItemAt(int contentsY) const;
282  pqFlatTreeViewItem *getNextItem(pqFlatTreeViewItem *item) const;
283  pqFlatTreeViewItem *getNextVisibleItem(pqFlatTreeViewItem *item) const;
284  pqFlatTreeViewItem *getPreviousVisibleItem(pqFlatTreeViewItem *item) const;
285  pqFlatTreeViewItem *getLastVisibleItem() const;
287 
288  void expandItem(pqFlatTreeViewItem *item);
289 
290  void getSelectionIn(const QModelIndex &topLeft,
291  const QModelIndex &bottomRight, QItemSelection &items) const;
292 
293  void drawBranches(QPainter &painter, pqFlatTreeViewItem *item,
294  int halfIndent, const QColor &branchColor, const QColor &expandColor,
295  const QStyleOptionViewItem &options);
296  bool drawDecoration(QPainter &painter, int px, int py,
297  const QModelIndex &index, const QStyleOptionViewItem &options,
298  int itemHeight);
299  void drawData(QPainter &painter, int px, int py,
300  const QModelIndex &index, const QStyleOptionViewItem &options,
301  int itemHeight, int itemWidth, int columnWidth, bool selected);
302  void drawFocus(QPainter &painter, const QRect &cell,
303  const QStyleOptionViewItem &options, bool selected);
304 
305 private:
306  QAbstractItemModel *Model;
307  QItemSelectionModel *Selection;
308  SelectionBehavior Behavior;
309  SelectionMode Mode;
310  QHeaderView *HeaderView;
311  pqFlatTreeViewItem *Root;
312  pqFlatTreeViewInternal *Internal;
313  int IconSize;
314  int IndentWidth;
315  int ContentsWidth;
316  int ContentsHeight;
317  int TextMargin;
318  int DoubleTextMargin;
319  bool FontChanged;
320  bool ManageSizes;
321  bool InUpdateWidth;
322  bool HeaderOwned;
323  bool SelectionOwned;
324 
325  static int PipeLength;
326 };
327 
328 #endif
QItemSelectionModel * getSelectionModel() const
QHeaderView * getHeader() const
Gets whether or not the column size is managed by the view.
SelectionMode getSelectionMode() const
QAbstractItemModel * getModel() const
The pqFlatTreeView class is used to display a flattened tree view of a hierarchical model...
SelectionBehavior getSelectionBehavior() const
bool isColumnSizeManaged() const
Gets whether or not the column size is managed by the view.