qtableview.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 QTABLEVIEW_H
  40. #define QTABLEVIEW_H
  41. #include <QtWidgets/qabstractitemview.h>
  42. QT_BEGIN_NAMESPACE
  43. #ifndef QT_NO_TABLEVIEW
  44. class QHeaderView;
  45. class QTableViewPrivate;
  46. class Q_WIDGETS_EXPORT QTableView : public QAbstractItemView
  47. {
  48. Q_OBJECT
  49. Q_PROPERTY(bool showGrid READ showGrid WRITE setShowGrid)
  50. Q_PROPERTY(Qt::PenStyle gridStyle READ gridStyle WRITE setGridStyle)
  51. Q_PROPERTY(bool sortingEnabled READ isSortingEnabled WRITE setSortingEnabled)
  52. Q_PROPERTY(bool wordWrap READ wordWrap WRITE setWordWrap)
  53. Q_PROPERTY(bool cornerButtonEnabled READ isCornerButtonEnabled WRITE setCornerButtonEnabled)
  54. public:
  55. explicit QTableView(QWidget *parent = Q_NULLPTR);
  56. ~QTableView();
  57. void setModel(QAbstractItemModel *model) Q_DECL_OVERRIDE;
  58. void setRootIndex(const QModelIndex &index) Q_DECL_OVERRIDE;
  59. void setSelectionModel(QItemSelectionModel *selectionModel) Q_DECL_OVERRIDE;
  60. void doItemsLayout() Q_DECL_OVERRIDE;
  61. QHeaderView *horizontalHeader() const;
  62. QHeaderView *verticalHeader() const;
  63. void setHorizontalHeader(QHeaderView *header);
  64. void setVerticalHeader(QHeaderView *header);
  65. int rowViewportPosition(int row) const;
  66. int rowAt(int y) const;
  67. void setRowHeight(int row, int height);
  68. int rowHeight(int row) const;
  69. int columnViewportPosition(int column) const;
  70. int columnAt(int x) const;
  71. void setColumnWidth(int column, int width);
  72. int columnWidth(int column) const;
  73. bool isRowHidden(int row) const;
  74. void setRowHidden(int row, bool hide);
  75. bool isColumnHidden(int column) const;
  76. void setColumnHidden(int column, bool hide);
  77. void setSortingEnabled(bool enable);
  78. bool isSortingEnabled() const;
  79. bool showGrid() const;
  80. Qt::PenStyle gridStyle() const;
  81. void setGridStyle(Qt::PenStyle style);
  82. void setWordWrap(bool on);
  83. bool wordWrap() const;
  84. void setCornerButtonEnabled(bool enable);
  85. bool isCornerButtonEnabled() const;
  86. QRect visualRect(const QModelIndex &index) const Q_DECL_OVERRIDE;
  87. void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible) Q_DECL_OVERRIDE;
  88. QModelIndex indexAt(const QPoint &p) const Q_DECL_OVERRIDE;
  89. void setSpan(int row, int column, int rowSpan, int columnSpan);
  90. int rowSpan(int row, int column) const;
  91. int columnSpan(int row, int column) const;
  92. void clearSpans();
  93. void sortByColumn(int column, Qt::SortOrder order);
  94. public Q_SLOTS:
  95. void selectRow(int row);
  96. void selectColumn(int column);
  97. void hideRow(int row);
  98. void hideColumn(int column);
  99. void showRow(int row);
  100. void showColumn(int column);
  101. void resizeRowToContents(int row);
  102. void resizeRowsToContents();
  103. void resizeColumnToContents(int column);
  104. void resizeColumnsToContents();
  105. void sortByColumn(int column);
  106. void setShowGrid(bool show);
  107. protected Q_SLOTS:
  108. void rowMoved(int row, int oldIndex, int newIndex);
  109. void columnMoved(int column, int oldIndex, int newIndex);
  110. void rowResized(int row, int oldHeight, int newHeight);
  111. void columnResized(int column, int oldWidth, int newWidth);
  112. void rowCountChanged(int oldCount, int newCount);
  113. void columnCountChanged(int oldCount, int newCount);
  114. protected:
  115. QTableView(QTableViewPrivate &, QWidget *parent);
  116. void scrollContentsBy(int dx, int dy) Q_DECL_OVERRIDE;
  117. QStyleOptionViewItem viewOptions() const Q_DECL_OVERRIDE;
  118. void paintEvent(QPaintEvent *e) Q_DECL_OVERRIDE;
  119. void timerEvent(QTimerEvent *event) Q_DECL_OVERRIDE;
  120. int horizontalOffset() const Q_DECL_OVERRIDE;
  121. int verticalOffset() const Q_DECL_OVERRIDE;
  122. QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) Q_DECL_OVERRIDE;
  123. void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command) Q_DECL_OVERRIDE;
  124. QRegion visualRegionForSelection(const QItemSelection &selection) const Q_DECL_OVERRIDE;
  125. QModelIndexList selectedIndexes() const Q_DECL_OVERRIDE;
  126. void updateGeometries() Q_DECL_OVERRIDE;
  127. QSize viewportSizeHint() const Q_DECL_OVERRIDE;
  128. int sizeHintForRow(int row) const Q_DECL_OVERRIDE;
  129. int sizeHintForColumn(int column) const Q_DECL_OVERRIDE;
  130. void verticalScrollbarAction(int action) Q_DECL_OVERRIDE;
  131. void horizontalScrollbarAction(int action) Q_DECL_OVERRIDE;
  132. bool isIndexHidden(const QModelIndex &index) const Q_DECL_OVERRIDE;
  133. void selectionChanged(const QItemSelection &selected,
  134. const QItemSelection &deselected) Q_DECL_OVERRIDE;
  135. void currentChanged(const QModelIndex &current,
  136. const QModelIndex &previous) Q_DECL_OVERRIDE;
  137. private:
  138. friend class QAccessibleItemView;
  139. int visualIndex(const QModelIndex &index) const;
  140. Q_DECLARE_PRIVATE(QTableView)
  141. Q_DISABLE_COPY(QTableView)
  142. Q_PRIVATE_SLOT(d_func(), void _q_selectRow(int))
  143. Q_PRIVATE_SLOT(d_func(), void _q_selectColumn(int))
  144. Q_PRIVATE_SLOT(d_func(), void _q_updateSpanInsertedRows(QModelIndex,int,int))
  145. Q_PRIVATE_SLOT(d_func(), void _q_updateSpanInsertedColumns(QModelIndex,int,int))
  146. Q_PRIVATE_SLOT(d_func(), void _q_updateSpanRemovedRows(QModelIndex,int,int))
  147. Q_PRIVATE_SLOT(d_func(), void _q_updateSpanRemovedColumns(QModelIndex,int,int))
  148. };
  149. #endif // QT_NO_TABLEVIEW
  150. QT_END_NAMESPACE
  151. #endif // QTABLEVIEW_H