| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QTABLEVIEW_H |
| 5 | #define QTABLEVIEW_H |
| 6 | |
| 7 | #include <QtWidgets/qtwidgetsglobal.h> |
| 8 | #include <QtWidgets/qabstractitemview.h> |
| 9 | |
| 10 | QT_REQUIRE_CONFIG(tableview); |
| 11 | |
| 12 | QT_BEGIN_NAMESPACE |
| 13 | |
| 14 | class ; |
| 15 | class QTableViewPrivate; |
| 16 | |
| 17 | class Q_WIDGETS_EXPORT QTableView : public QAbstractItemView |
| 18 | { |
| 19 | Q_OBJECT |
| 20 | Q_PROPERTY(bool showGrid READ showGrid WRITE setShowGrid) |
| 21 | Q_PROPERTY(Qt::PenStyle gridStyle READ gridStyle WRITE setGridStyle) |
| 22 | Q_PROPERTY(bool sortingEnabled READ isSortingEnabled WRITE setSortingEnabled) |
| 23 | Q_PROPERTY(bool wordWrap READ wordWrap WRITE setWordWrap) |
| 24 | #if QT_CONFIG(abstractbutton) |
| 25 | Q_PROPERTY(bool cornerButtonEnabled READ isCornerButtonEnabled WRITE setCornerButtonEnabled) |
| 26 | #endif |
| 27 | |
| 28 | public: |
| 29 | explicit QTableView(QWidget *parent = nullptr); |
| 30 | ~QTableView(); |
| 31 | |
| 32 | void setModel(QAbstractItemModel *model) override; |
| 33 | void setRootIndex(const QModelIndex &index) override; |
| 34 | void setSelectionModel(QItemSelectionModel *selectionModel) override; |
| 35 | void doItemsLayout() override; |
| 36 | |
| 37 | QHeaderView *() const; |
| 38 | QHeaderView *() const; |
| 39 | void (QHeaderView *); |
| 40 | void (QHeaderView *); |
| 41 | |
| 42 | int rowViewportPosition(int row) const; |
| 43 | int rowAt(int y) const; |
| 44 | |
| 45 | void setRowHeight(int row, int height); |
| 46 | int rowHeight(int row) const; |
| 47 | |
| 48 | int columnViewportPosition(int column) const; |
| 49 | int columnAt(int x) const; |
| 50 | |
| 51 | void setColumnWidth(int column, int width); |
| 52 | int columnWidth(int column) const; |
| 53 | |
| 54 | bool isRowHidden(int row) const; |
| 55 | void setRowHidden(int row, bool hide); |
| 56 | |
| 57 | bool isColumnHidden(int column) const; |
| 58 | void setColumnHidden(int column, bool hide); |
| 59 | |
| 60 | void setSortingEnabled(bool enable); |
| 61 | bool isSortingEnabled() const; |
| 62 | |
| 63 | bool showGrid() const; |
| 64 | |
| 65 | Qt::PenStyle gridStyle() const; |
| 66 | void setGridStyle(Qt::PenStyle style); |
| 67 | |
| 68 | void setWordWrap(bool on); |
| 69 | bool wordWrap() const; |
| 70 | |
| 71 | #if QT_CONFIG(abstractbutton) |
| 72 | void setCornerButtonEnabled(bool enable); |
| 73 | bool isCornerButtonEnabled() const; |
| 74 | #endif |
| 75 | |
| 76 | QRect visualRect(const QModelIndex &index) const override; |
| 77 | void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible) override; |
| 78 | QModelIndex indexAt(const QPoint &p) const override; |
| 79 | |
| 80 | void setSpan(int row, int column, int rowSpan, int columnSpan); |
| 81 | int rowSpan(int row, int column) const; |
| 82 | int columnSpan(int row, int column) const; |
| 83 | void clearSpans(); |
| 84 | |
| 85 | |
| 86 | public Q_SLOTS: |
| 87 | void selectRow(int row); |
| 88 | void selectColumn(int column); |
| 89 | void hideRow(int row); |
| 90 | void hideColumn(int column); |
| 91 | void showRow(int row); |
| 92 | void showColumn(int column); |
| 93 | void resizeRowToContents(int row); |
| 94 | void resizeRowsToContents(); |
| 95 | void resizeColumnToContents(int column); |
| 96 | void resizeColumnsToContents(); |
| 97 | void sortByColumn(int column, Qt::SortOrder order); |
| 98 | void setShowGrid(bool show); |
| 99 | |
| 100 | protected Q_SLOTS: |
| 101 | void rowMoved(int row, int oldIndex, int newIndex); |
| 102 | void columnMoved(int column, int oldIndex, int newIndex); |
| 103 | void rowResized(int row, int oldHeight, int newHeight); |
| 104 | void columnResized(int column, int oldWidth, int newWidth); |
| 105 | void rowCountChanged(int oldCount, int newCount); |
| 106 | void columnCountChanged(int oldCount, int newCount); |
| 107 | |
| 108 | protected: |
| 109 | QTableView(QTableViewPrivate &, QWidget *parent); |
| 110 | void scrollContentsBy(int dx, int dy) override; |
| 111 | |
| 112 | void initViewItemOption(QStyleOptionViewItem *option) const override; |
| 113 | void paintEvent(QPaintEvent *e) override; |
| 114 | |
| 115 | void timerEvent(QTimerEvent *event) override; |
| 116 | |
| 117 | #if QT_CONFIG(draganddrop) |
| 118 | void dropEvent(QDropEvent *event) override; |
| 119 | #endif |
| 120 | |
| 121 | int horizontalOffset() const override; |
| 122 | int verticalOffset() const override; |
| 123 | QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) override; |
| 124 | |
| 125 | void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command) override; |
| 126 | QRegion visualRegionForSelection(const QItemSelection &selection) const override; |
| 127 | QModelIndexList selectedIndexes() const override; |
| 128 | |
| 129 | void updateGeometries() override; |
| 130 | |
| 131 | QSize viewportSizeHint() const override; |
| 132 | |
| 133 | int sizeHintForRow(int row) const override; |
| 134 | int sizeHintForColumn(int column) const override; |
| 135 | |
| 136 | void verticalScrollbarAction(int action) override; |
| 137 | void horizontalScrollbarAction(int action) override; |
| 138 | |
| 139 | bool isIndexHidden(const QModelIndex &index) const override; |
| 140 | |
| 141 | void selectionChanged(const QItemSelection &selected, |
| 142 | const QItemSelection &deselected) override; |
| 143 | void currentChanged(const QModelIndex ¤t, |
| 144 | const QModelIndex &previous) override; |
| 145 | |
| 146 | private: |
| 147 | friend class QAccessibleItemView; |
| 148 | int visualIndex(const QModelIndex &index) const; |
| 149 | |
| 150 | Q_DECLARE_PRIVATE(QTableView) |
| 151 | Q_DISABLE_COPY(QTableView) |
| 152 | }; |
| 153 | |
| 154 | QT_END_NAMESPACE |
| 155 | |
| 156 | #endif // QTABLEVIEW_H |
| 157 | |