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 
98  pqFlatTreeView(QWidget* parent = nullptr);
99  ~pqFlatTreeView() override;
100 
111  bool eventFilter(QObject* object, QEvent* e) override;
112 
117  QAbstractItemModel* getModel() const { return this->Model; }
118  void setModel(QAbstractItemModel* model);
119 
120  QModelIndex getRootIndex() const;
121  void setRootIndex(const QModelIndex& index);
123 
128  QItemSelectionModel* getSelectionModel() const { return this->Selection; }
129  void setSelectionModel(QItemSelectionModel* selectionModel);
130 
131  SelectionBehavior getSelectionBehavior() const { return this->Behavior; }
132  void setSelectionBehavior(SelectionBehavior behavior);
133 
134  SelectionMode getSelectionMode() const { return this->Mode; }
135  void setSelectionMode(SelectionMode mode);
137 
142  QHeaderView* getHeader() const { return this->HeaderView; }
143  void setHeader(QHeaderView* headerView);
144 
156  bool isColumnSizeManaged() const { return this->ManageSizes; }
157 
165  void setColumnSizeManaged(bool managed);
167 
172  int getIconSize() const;
173  void setIconSize(int iconSize);
175 
180  bool isIndexHidden(const QModelIndex& index) const;
181  void getVisibleRect(const QModelIndex& index, QRect& area) const;
182  QModelIndex getIndexVisibleAt(const QPoint& point) const;
183  QModelIndex getIndexCellAt(const QPoint& point) const;
184  void getSelectionIn(const QRect& rect, QItemSelection& items) const;
186 
191  bool isIndexExpanded(const QModelIndex& index) const;
192  QModelIndex getNextVisibleIndex(
193  const QModelIndex& index, const QModelIndex& root = QModelIndex()) const;
194  QModelIndex getRelativeIndex(const QString& id, const QModelIndex& root = QModelIndex()) const;
195  void getRelativeIndexId(
196  const QModelIndex& index, QString& id, const QModelIndex& root = QModelIndex()) const;
198 
203  bool startEditing(const QModelIndex& index);
204  void finishEditing();
205  void cancelEditing();
207 
208 Q_SIGNALS:
209  void activated(const QModelIndex& index);
210  void clicked(const QModelIndex& index);
211 
212 public Q_SLOTS:
213  void reset();
214  void selectAll();
215  void setCurrentIndex(const QModelIndex& index);
216  void expandAll();
217  void expand(const QModelIndex& index);
218  void collapse(const QModelIndex& index);
219  void scrollTo(const QModelIndex& index);
220 
221 protected Q_SLOTS:
226  void insertRows(const QModelIndex& parent, int start, int end);
227  void startRowRemoval(const QModelIndex& parent, int start, int end);
228  void finishRowRemoval(const QModelIndex& parent, int start, int end);
229  void insertColumns(const QModelIndex& parent, int start, int end);
230  void startColumnRemoval(const QModelIndex& parent, int start, int end);
231  void finishColumnRemoval(const QModelIndex& parent, int start, int end);
232  void updateData(const QModelIndex& topLeft, const QModelIndex& bottomRight);
234 
235 protected: // NOLINT(readability-redundant-access-specifiers)
240  void keyPressEvent(QKeyEvent* e) override;
241  void keyboardSearch(const QString& search);
243 
248  void mousePressEvent(QMouseEvent* e) override;
249  void mouseMoveEvent(QMouseEvent* e) override;
250  void mouseReleaseEvent(QMouseEvent* e) override;
251  void mouseDoubleClickEvent(QMouseEvent* e) override;
253 
258  bool event(QEvent* e) override;
260 
261  int horizontalOffset() const;
262  int verticalOffset() const;
263 
264  void resizeEvent(QResizeEvent* e) override;
265  bool viewportEvent(QEvent* e) override;
266  void paintEvent(QPaintEvent* e) override;
267  QStyleOptionViewItem getViewOptions() const;
268 
269 private Q_SLOTS:
274  void handleSectionResized(int index, int oldSize, int newSize);
275  void handleSectionMoved(int index, int oldVisual, int newVisual);
277 
282  void changeCurrent(const QModelIndex& current, const QModelIndex& previous);
283  void changeCurrentRow(const QModelIndex& current, const QModelIndex& previous);
284  void changeCurrentColumn(const QModelIndex& current, const QModelIndex& previous);
285  void changeSelection(const QItemSelection& selected, const QItemSelection& deselected);
287 
288 private: // NOLINT(readability-redundant-access-specifiers)
289  void resetRoot();
290  void resetPreferredSizes();
291 
296  void layoutEditor();
297  void layoutItems();
298  void layoutItem(pqFlatTreeViewItem* item, int& point, const QFontMetrics& fm);
299  int getDataWidth(const QModelIndex& index, const QFontMetrics& fm) const;
300  int getWidthSum(pqFlatTreeViewItem* item, int column) const;
301  bool updateContentsWidth();
302  void updateScrollBars();
303  void addChildItems(pqFlatTreeViewItem* item, int parentChildCount);
305 
310  bool getIndexRowList(const QModelIndex& index, pqFlatTreeViewItemRows& rowList) const;
311  pqFlatTreeViewItem* getItem(const pqFlatTreeViewItemRows& rowList) const;
312  pqFlatTreeViewItem* getItem(const QModelIndex& index) const;
313  pqFlatTreeViewItem* getItemAt(int contentsY) const;
314  pqFlatTreeViewItem* getNextItem(pqFlatTreeViewItem* item) const;
315  pqFlatTreeViewItem* getNextVisibleItem(pqFlatTreeViewItem* item) const;
316  pqFlatTreeViewItem* getPreviousVisibleItem(pqFlatTreeViewItem* item) const;
317  pqFlatTreeViewItem* getLastVisibleItem() const;
319 
320  void expandItem(pqFlatTreeViewItem* item);
321 
322  void getSelectionIn(
323  const QModelIndex& topLeft, const QModelIndex& bottomRight, QItemSelection& items) const;
324 
325  void drawBranches(QPainter& painter, pqFlatTreeViewItem* item, int halfIndent,
326  const QColor& branchColor, const QColor& expandColor, const QStyleOptionViewItem& options);
327  bool drawDecoration(QPainter& painter, int px, int py, const QModelIndex& index,
328  const QStyleOptionViewItem& options, int itemHeight);
329  void drawData(QPainter& painter, int px, int py, const QModelIndex& index,
330  const QStyleOptionViewItem& options, int itemHeight, int itemWidth, int columnWidth,
331  bool selected);
332  void drawFocus(
333  QPainter& painter, const QRect& cell, const QStyleOptionViewItem& options, bool selected);
334 
335  QAbstractItemModel* Model;
336  QItemSelectionModel* Selection;
337  SelectionBehavior Behavior;
338  SelectionMode Mode;
339  QHeaderView* HeaderView;
340  pqFlatTreeViewItem* Root;
341  pqFlatTreeViewInternal* Internal;
342  int IconSize;
343  int IndentWidth;
344  int ContentsWidth;
345  int ContentsHeight;
346  int TextMargin;
347  int DoubleTextMargin;
348  bool FontChanged;
349  bool ManageSizes;
350  bool InUpdateWidth;
351  bool HeaderOwned;
352  bool SelectionOwned;
353 
354  static int PipeLength;
355 };
356 
357 #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