qtreeview.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2016 The Qt Company Ltd.
  4. ** Contact: https://www.qt.io/licensing/
  5. **
  6. ** This file is part of the QtWidgets module of the Qt Toolkit.
  7. **
  8. ** $QT_BEGIN_LICENSE:LGPL$
  9. ** Commercial License Usage
  10. ** Licensees holding valid commercial Qt licenses may use this file in
  11. ** accordance with the commercial license agreement provided with the
  12. ** Software or, alternatively, in accordance with the terms contained in
  13. ** a written agreement between you and The Qt Company. For licensing terms
  14. ** and conditions see https://www.qt.io/terms-conditions. For further
  15. ** information use the contact form at https://www.qt.io/contact-us.
  16. **
  17. ** GNU Lesser General Public License Usage
  18. ** Alternatively, this file may be used under the terms of the GNU Lesser
  19. ** General Public License version 3 as published by the Free Software
  20. ** Foundation and appearing in the file LICENSE.LGPL3 included in the
  21. ** packaging of this file. Please review the following information to
  22. ** ensure the GNU Lesser General Public License version 3 requirements
  23. ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
  24. **
  25. ** GNU General Public License Usage
  26. ** Alternatively, this file may be used under the terms of the GNU
  27. ** General Public License version 2.0 or (at your option) the GNU General
  28. ** Public license version 3 or any later version approved by the KDE Free
  29. ** Qt Foundation. The licenses are as published by the Free Software
  30. ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
  31. ** included in the packaging of this file. Please review the following
  32. ** information to ensure the GNU General Public License requirements will
  33. ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
  34. ** https://www.gnu.org/licenses/gpl-3.0.html.
  35. **
  36. ** $QT_END_LICENSE$
  37. **
  38. ****************************************************************************/
  39. #ifndef QTREEVIEW_H
  40. #define QTREEVIEW_H
  41. #include <QtWidgets/qabstractitemview.h>
  42. class tst_QTreeView;
  43. QT_BEGIN_NAMESPACE
  44. #ifndef QT_NO_TREEVIEW
  45. class QTreeViewPrivate;
  46. class QHeaderView;
  47. class Q_WIDGETS_EXPORT QTreeView : public QAbstractItemView
  48. {
  49. Q_OBJECT
  50. Q_PROPERTY(int autoExpandDelay READ autoExpandDelay WRITE setAutoExpandDelay)
  51. Q_PROPERTY(int indentation READ indentation WRITE setIndentation RESET resetIndentation)
  52. Q_PROPERTY(bool rootIsDecorated READ rootIsDecorated WRITE setRootIsDecorated)
  53. Q_PROPERTY(bool uniformRowHeights READ uniformRowHeights WRITE setUniformRowHeights)
  54. Q_PROPERTY(bool itemsExpandable READ itemsExpandable WRITE setItemsExpandable)
  55. Q_PROPERTY(bool sortingEnabled READ isSortingEnabled WRITE setSortingEnabled)
  56. Q_PROPERTY(bool animated READ isAnimated WRITE setAnimated)
  57. Q_PROPERTY(bool allColumnsShowFocus READ allColumnsShowFocus WRITE setAllColumnsShowFocus)
  58. Q_PROPERTY(bool wordWrap READ wordWrap WRITE setWordWrap)
  59. Q_PROPERTY(bool headerHidden READ isHeaderHidden WRITE setHeaderHidden)
  60. Q_PROPERTY(bool expandsOnDoubleClick READ expandsOnDoubleClick WRITE setExpandsOnDoubleClick)
  61. public:
  62. explicit QTreeView(QWidget *parent = Q_NULLPTR);
  63. ~QTreeView();
  64. void setModel(QAbstractItemModel *model) Q_DECL_OVERRIDE;
  65. void setRootIndex(const QModelIndex &index) Q_DECL_OVERRIDE;
  66. void setSelectionModel(QItemSelectionModel *selectionModel) Q_DECL_OVERRIDE;
  67. QHeaderView *header() const;
  68. void setHeader(QHeaderView *header);
  69. int autoExpandDelay() const;
  70. void setAutoExpandDelay(int delay);
  71. int indentation() const;
  72. void setIndentation(int i);
  73. void resetIndentation();
  74. bool rootIsDecorated() const;
  75. void setRootIsDecorated(bool show);
  76. bool uniformRowHeights() const;
  77. void setUniformRowHeights(bool uniform);
  78. bool itemsExpandable() const;
  79. void setItemsExpandable(bool enable);
  80. bool expandsOnDoubleClick() const;
  81. void setExpandsOnDoubleClick(bool enable);
  82. int columnViewportPosition(int column) const;
  83. int columnWidth(int column) const;
  84. void setColumnWidth(int column, int width);
  85. int columnAt(int x) const;
  86. bool isColumnHidden(int column) const;
  87. void setColumnHidden(int column, bool hide);
  88. bool isHeaderHidden() const;
  89. void setHeaderHidden(bool hide);
  90. bool isRowHidden(int row, const QModelIndex &parent) const;
  91. void setRowHidden(int row, const QModelIndex &parent, bool hide);
  92. bool isFirstColumnSpanned(int row, const QModelIndex &parent) const;
  93. void setFirstColumnSpanned(int row, const QModelIndex &parent, bool span);
  94. bool isExpanded(const QModelIndex &index) const;
  95. void setExpanded(const QModelIndex &index, bool expand);
  96. void setSortingEnabled(bool enable);
  97. bool isSortingEnabled() const;
  98. void setAnimated(bool enable);
  99. bool isAnimated() const;
  100. void setAllColumnsShowFocus(bool enable);
  101. bool allColumnsShowFocus() const;
  102. void setWordWrap(bool on);
  103. bool wordWrap() const;
  104. void setTreePosition(int logicalIndex);
  105. int treePosition() const;
  106. void keyboardSearch(const QString &search) Q_DECL_OVERRIDE;
  107. QRect visualRect(const QModelIndex &index) const Q_DECL_OVERRIDE;
  108. void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible) Q_DECL_OVERRIDE;
  109. QModelIndex indexAt(const QPoint &p) const Q_DECL_OVERRIDE;
  110. QModelIndex indexAbove(const QModelIndex &index) const;
  111. QModelIndex indexBelow(const QModelIndex &index) const;
  112. void doItemsLayout() Q_DECL_OVERRIDE;
  113. void reset() Q_DECL_OVERRIDE;
  114. void sortByColumn(int column, Qt::SortOrder order);
  115. void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>()) Q_DECL_OVERRIDE;
  116. void selectAll() Q_DECL_OVERRIDE;
  117. Q_SIGNALS:
  118. void expanded(const QModelIndex &index);
  119. void collapsed(const QModelIndex &index);
  120. public Q_SLOTS:
  121. void hideColumn(int column);
  122. void showColumn(int column);
  123. void expand(const QModelIndex &index);
  124. void collapse(const QModelIndex &index);
  125. void resizeColumnToContents(int column);
  126. void sortByColumn(int column);
  127. void expandAll();
  128. void collapseAll();
  129. void expandToDepth(int depth);
  130. protected Q_SLOTS:
  131. void columnResized(int column, int oldSize, int newSize);
  132. void columnCountChanged(int oldCount, int newCount);
  133. void columnMoved();
  134. void reexpand();
  135. void rowsRemoved(const QModelIndex &parent, int first, int last);
  136. protected:
  137. QTreeView(QTreeViewPrivate &dd, QWidget *parent = Q_NULLPTR);
  138. void scrollContentsBy(int dx, int dy) Q_DECL_OVERRIDE;
  139. void rowsInserted(const QModelIndex &parent, int start, int end) Q_DECL_OVERRIDE;
  140. void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) Q_DECL_OVERRIDE;
  141. QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) Q_DECL_OVERRIDE;
  142. int horizontalOffset() const Q_DECL_OVERRIDE;
  143. int verticalOffset() const Q_DECL_OVERRIDE;
  144. void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command) Q_DECL_OVERRIDE;
  145. QRegion visualRegionForSelection(const QItemSelection &selection) const Q_DECL_OVERRIDE;
  146. QModelIndexList selectedIndexes() const Q_DECL_OVERRIDE;
  147. void timerEvent(QTimerEvent *event) Q_DECL_OVERRIDE;
  148. void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
  149. void drawTree(QPainter *painter, const QRegion &region) const;
  150. virtual void drawRow(QPainter *painter,
  151. const QStyleOptionViewItem &options,
  152. const QModelIndex &index) const;
  153. virtual void drawBranches(QPainter *painter,
  154. const QRect &rect,
  155. const QModelIndex &index) const;
  156. void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
  157. void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
  158. void mouseDoubleClickEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
  159. void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
  160. void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
  161. #ifndef QT_NO_DRAGANDDROP
  162. void dragMoveEvent(QDragMoveEvent *event) Q_DECL_OVERRIDE;
  163. #endif
  164. bool viewportEvent(QEvent *event) Q_DECL_OVERRIDE;
  165. void updateGeometries() Q_DECL_OVERRIDE;
  166. QSize viewportSizeHint() const Q_DECL_OVERRIDE;
  167. int sizeHintForColumn(int column) const Q_DECL_OVERRIDE;
  168. int indexRowSizeHint(const QModelIndex &index) const;
  169. int rowHeight(const QModelIndex &index) const;
  170. void horizontalScrollbarAction(int action) Q_DECL_OVERRIDE;
  171. bool isIndexHidden(const QModelIndex &index) const Q_DECL_OVERRIDE;
  172. void selectionChanged(const QItemSelection &selected,
  173. const QItemSelection &deselected) Q_DECL_OVERRIDE;
  174. void currentChanged(const QModelIndex &current, const QModelIndex &previous) Q_DECL_OVERRIDE;
  175. private:
  176. friend class ::tst_QTreeView;
  177. friend class QAccessibleTable;
  178. friend class QAccessibleTree;
  179. friend class QAccessibleTableCell;
  180. int visualIndex(const QModelIndex &index) const;
  181. Q_DECLARE_PRIVATE(QTreeView)
  182. Q_DISABLE_COPY(QTreeView)
  183. #ifndef QT_NO_ANIMATION
  184. Q_PRIVATE_SLOT(d_func(), void _q_endAnimatedOperation())
  185. #endif //QT_NO_ANIMATION
  186. Q_PRIVATE_SLOT(d_func(), void _q_modelAboutToBeReset())
  187. Q_PRIVATE_SLOT(d_func(), void _q_sortIndicatorChanged(int column, Qt::SortOrder order))
  188. };
  189. #endif // QT_NO_TREEVIEW
  190. QT_END_NAMESPACE
  191. #endif // QTREEVIEW_H