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 
38 #ifndef _pqFlatTreeView_h
39 #define _pqFlatTreeView_h
40 
41 #include "pqWidgetsModule.h"
42 #include <QAbstractScrollArea>
43 #include <QModelIndex> // Needed for return type
44 #include <QStyleOptionViewItem> // Needed for return type
45 
46 class pqFlatTreeViewItem;
47 class pqFlatTreeViewItemRows;
48 class pqFlatTreeViewInternal;
49 
50 class QAbstractItemModel;
51 class QColor;
52 class QFontMetrics;
53 class QHeaderView;
54 class QItemSelection;
55 class QItemSelectionModel;
56 class QPoint;
57 class QRect;
58 
74 class PQWIDGETS_EXPORT pqFlatTreeView : public QAbstractScrollArea
75 {
76  Q_OBJECT
77 
78 public:
80  {
83  SelectColumns
84  };
85 
87  {
90  ExtendedSelection
91  };
92 
93 public:
99  pqFlatTreeView(QWidget* parent = 0);
100  ~pqFlatTreeView() override;
101 
112  bool eventFilter(QObject* object, QEvent* e) override;
113 
118  QAbstractItemModel* getModel() const { return this->Model; }
119  void setModel(QAbstractItemModel* model);
120 
121  QModelIndex getRootIndex() const;
122  void setRootIndex(const QModelIndex& index);
124 
129  QItemSelectionModel* getSelectionModel() const { return this->Selection; }
130  void setSelectionModel(QItemSelectionModel* selectionModel);
131 
132  SelectionBehavior getSelectionBehavior() const { return this->Behavior; }
133  void setSelectionBehavior(SelectionBehavior behavior);
134 
135  SelectionMode getSelectionMode() const { return this->Mode; }
136  void setSelectionMode(SelectionMode mode);
138 
143  QHeaderView* getHeader() const { return this->HeaderView; }
144  void setHeader(QHeaderView* headerView);
145 
157  bool isColumnSizeManaged() const { return this->ManageSizes; }
158 
166  void setColumnSizeManaged(bool managed);
168 
173  int getIconSize() const;
174  void setIconSize(int iconSize);
176 
181  bool isIndexHidden(const QModelIndex& index) const;
182  void getVisibleRect(const QModelIndex& index, QRect& area) const;
183  QModelIndex getIndexVisibleAt(const QPoint& point) const;
184  QModelIndex getIndexCellAt(const QPoint& point) const;
185  void getSelectionIn(const QRect& rect, QItemSelection& items) const;
187 
192  bool isIndexExpanded(const QModelIndex& index) const;
193  QModelIndex getNextVisibleIndex(
194  const QModelIndex& index, const QModelIndex& root = QModelIndex()) const;
195  QModelIndex getRelativeIndex(const QString& id, const QModelIndex& root = QModelIndex()) const;
196  void getRelativeIndexId(
197  const QModelIndex& index, QString& id, const QModelIndex& root = QModelIndex()) const;
199 
204  bool startEditing(const QModelIndex& index);
205  void finishEditing();
206  void cancelEditing();
208 
209 Q_SIGNALS:
210  void activated(const QModelIndex& index);
211  void clicked(const QModelIndex& index);
212 
213 public Q_SLOTS:
214  void reset();
215  void selectAll();
216  void setCurrentIndex(const QModelIndex& index);
217  void expandAll();
218  void expand(const QModelIndex& index);
219  void collapse(const QModelIndex& index);
220  void scrollTo(const QModelIndex& index);
221 
222 protected Q_SLOTS:
227  void insertRows(const QModelIndex& parent, int start, int end);
228  void startRowRemoval(const QModelIndex& parent, int start, int end);
229  void finishRowRemoval(const QModelIndex& parent, int start, int end);
230  void insertColumns(const QModelIndex& parent, int start, int end);
231  void startColumnRemoval(const QModelIndex& parent, int start, int end);
232  void finishColumnRemoval(const QModelIndex& parent, int start, int end);
233  void updateData(const QModelIndex& topLeft, const QModelIndex& bottomRight);
235 
236 protected:
241  void keyPressEvent(QKeyEvent* e) override;
242  void keyboardSearch(const QString& search);
244 
249  void mousePressEvent(QMouseEvent* e) override;
250  void mouseMoveEvent(QMouseEvent* e) override;
251  void mouseReleaseEvent(QMouseEvent* e) override;
252  void mouseDoubleClickEvent(QMouseEvent* e) override;
254 
259  bool event(QEvent* e) override;
261 
262  int horizontalOffset() const;
263  int verticalOffset() const;
264 
265  void resizeEvent(QResizeEvent* e) override;
266  bool viewportEvent(QEvent* e) override;
267  void paintEvent(QPaintEvent* e) override;
268  QStyleOptionViewItem getViewOptions() const;
269 
270 private Q_SLOTS:
275  void handleSectionResized(int index, int oldSize, int newSize);
276  void handleSectionMoved(int index, int oldVisual, int newVisual);
278 
283  void changeCurrent(const QModelIndex& current, const QModelIndex& previous);
284  void changeCurrentRow(const QModelIndex& current, const QModelIndex& previous);
285  void changeCurrentColumn(const QModelIndex& current, const QModelIndex& previous);
286  void changeSelection(const QItemSelection& selected, const QItemSelection& deselected);
288 
289 private:
290  void resetRoot();
291  void resetPreferredSizes();
292 
297  void layoutEditor();
298  void layoutItems();
299  void layoutItem(pqFlatTreeViewItem* item, int& point, const QFontMetrics& fm);
300  int getDataWidth(const QModelIndex& index, const QFontMetrics& fm) const;
301  int getWidthSum(pqFlatTreeViewItem* item, int column) const;
302  bool updateContentsWidth();
303  void updateScrollBars();
304  void addChildItems(pqFlatTreeViewItem* item, int parentChildCount);
306 
311  bool getIndexRowList(const QModelIndex& index, pqFlatTreeViewItemRows& rowList) const;
312  pqFlatTreeViewItem* getItem(const pqFlatTreeViewItemRows& rowList) const;
313  pqFlatTreeViewItem* getItem(const QModelIndex& index) const;
314  pqFlatTreeViewItem* getItemAt(int contentsY) const;
315  pqFlatTreeViewItem* getNextItem(pqFlatTreeViewItem* item) const;
316  pqFlatTreeViewItem* getNextVisibleItem(pqFlatTreeViewItem* item) const;
317  pqFlatTreeViewItem* getPreviousVisibleItem(pqFlatTreeViewItem* item) const;
318  pqFlatTreeViewItem* getLastVisibleItem() const;
320 
321  void expandItem(pqFlatTreeViewItem* item);
322 
323  void getSelectionIn(
324  const QModelIndex& topLeft, const QModelIndex& bottomRight, QItemSelection& items) const;
325 
326  void drawBranches(QPainter& painter, pqFlatTreeViewItem* item, int halfIndent,
327  const QColor& branchColor, const QColor& expandColor, const QStyleOptionViewItem& options);
328  bool drawDecoration(QPainter& painter, int px, int py, const QModelIndex& index,
329  const QStyleOptionViewItem& options, int itemHeight);
330  void drawData(QPainter& painter, int px, int py, const QModelIndex& index,
331  const QStyleOptionViewItem& options, int itemHeight, int itemWidth, int columnWidth,
332  bool selected);
333  void drawFocus(
334  QPainter& painter, const QRect& cell, const QStyleOptionViewItem& options, bool selected);
335 
336 private:
337  QAbstractItemModel* Model;
338  QItemSelectionModel* Selection;
339  SelectionBehavior Behavior;
340  SelectionMode Mode;
341  QHeaderView* HeaderView;
342  pqFlatTreeViewItem* Root;
343  pqFlatTreeViewInternal* Internal;
344  int IconSize;
345  int IndentWidth;
346  int ContentsWidth;
347  int ContentsHeight;
348  int TextMargin;
349  int DoubleTextMargin;
350  bool FontChanged;
351  bool ManageSizes;
352  bool InUpdateWidth;
353  bool HeaderOwned;
354  bool SelectionOwned;
355 
356  static int PipeLength;
357 };
358 
359 #endif
QItemSelectionModel * getSelectionModel() const
previous
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...
#define PQWIDGETS_EXPORT
mode
SelectionBehavior getSelectionBehavior() const
bool isColumnSizeManaged() const
Gets whether or not the column size is managed by the view.
point
index