Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-17 09:27:19

0001 // Copyright (C) 2016 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 // Qt-Security score:significant reason:default
0004 
0005 #ifndef QTREEVIEW_H
0006 #define QTREEVIEW_H
0007 
0008 #include <QtWidgets/qtwidgetsglobal.h>
0009 #include <QtWidgets/qabstractitemview.h>
0010 
0011 class tst_QTreeView;
0012 
0013 QT_REQUIRE_CONFIG(treeview);
0014 
0015 QT_BEGIN_NAMESPACE
0016 
0017 class QTreeViewPrivate;
0018 class QHeaderView;
0019 
0020 class Q_WIDGETS_EXPORT QTreeView : public QAbstractItemView
0021 {
0022     Q_OBJECT
0023     Q_PROPERTY(int autoExpandDelay READ autoExpandDelay WRITE setAutoExpandDelay)
0024     Q_PROPERTY(int indentation READ indentation WRITE setIndentation RESET resetIndentation)
0025     Q_PROPERTY(bool rootIsDecorated READ rootIsDecorated WRITE setRootIsDecorated)
0026     Q_PROPERTY(bool uniformRowHeights READ uniformRowHeights WRITE setUniformRowHeights)
0027     Q_PROPERTY(bool itemsExpandable READ itemsExpandable WRITE setItemsExpandable)
0028     Q_PROPERTY(bool sortingEnabled READ isSortingEnabled WRITE setSortingEnabled)
0029     Q_PROPERTY(bool animated READ isAnimated WRITE setAnimated)
0030     Q_PROPERTY(bool allColumnsShowFocus READ allColumnsShowFocus WRITE setAllColumnsShowFocus)
0031     Q_PROPERTY(bool wordWrap READ wordWrap WRITE setWordWrap)
0032     Q_PROPERTY(bool headerHidden READ isHeaderHidden WRITE setHeaderHidden)
0033     Q_PROPERTY(bool expandsOnDoubleClick READ expandsOnDoubleClick WRITE setExpandsOnDoubleClick)
0034 
0035 public:
0036     explicit QTreeView(QWidget *parent = nullptr);
0037     ~QTreeView();
0038 
0039     void setModel(QAbstractItemModel *model) override;
0040     void setRootIndex(const QModelIndex &index) override;
0041     void setSelectionModel(QItemSelectionModel *selectionModel) override;
0042 
0043     QHeaderView *header() const;
0044     void setHeader(QHeaderView *header);
0045 
0046     int autoExpandDelay() const;
0047     void setAutoExpandDelay(int delay);
0048 
0049     int indentation() const;
0050     void setIndentation(int i);
0051     void resetIndentation();
0052 
0053     bool rootIsDecorated() const;
0054     void setRootIsDecorated(bool show);
0055 
0056     bool uniformRowHeights() const;
0057     void setUniformRowHeights(bool uniform);
0058 
0059     bool itemsExpandable() const;
0060     void setItemsExpandable(bool enable);
0061 
0062     bool expandsOnDoubleClick() const;
0063     void setExpandsOnDoubleClick(bool enable);
0064 
0065     int columnViewportPosition(int column) const;
0066     int columnWidth(int column) const;
0067     void setColumnWidth(int column, int width);
0068     int columnAt(int x) const;
0069 
0070     bool isColumnHidden(int column) const;
0071     void setColumnHidden(int column, bool hide);
0072 
0073     bool isHeaderHidden() const;
0074     void setHeaderHidden(bool hide);
0075 
0076     bool isRowHidden(int row, const QModelIndex &parent) const;
0077     void setRowHidden(int row, const QModelIndex &parent, bool hide);
0078 
0079     bool isFirstColumnSpanned(int row, const QModelIndex &parent) const;
0080     void setFirstColumnSpanned(int row, const QModelIndex &parent, bool span);
0081 
0082     bool isExpanded(const QModelIndex &index) const;
0083     void setExpanded(const QModelIndex &index, bool expand);
0084 
0085     void setSortingEnabled(bool enable);
0086     bool isSortingEnabled() const;
0087 
0088     void setAnimated(bool enable);
0089     bool isAnimated() const;
0090 
0091     void setAllColumnsShowFocus(bool enable);
0092     bool allColumnsShowFocus() const;
0093 
0094     void setWordWrap(bool on);
0095     bool wordWrap() const;
0096 
0097     void setTreePosition(int logicalIndex);
0098     int treePosition() const;
0099 
0100     void keyboardSearch(const QString &search) override;
0101 
0102     QRect visualRect(const QModelIndex &index) const override;
0103     void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible) override;
0104     QModelIndex indexAt(const QPoint &p) const override;
0105     QModelIndex indexAbove(const QModelIndex &index) const;
0106     QModelIndex indexBelow(const QModelIndex &index) const;
0107 
0108     void doItemsLayout() override;
0109     void reset() override;
0110 
0111     void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
0112                      const QList<int> &roles = QList<int>()) override;
0113     void selectAll() override;
0114 
0115 Q_SIGNALS:
0116     void expanded(const QModelIndex &index);
0117     void collapsed(const QModelIndex &index);
0118 
0119 public Q_SLOTS:
0120     void hideColumn(int column);
0121     void showColumn(int column);
0122     void expand(const QModelIndex &index);
0123     void collapse(const QModelIndex &index);
0124     void resizeColumnToContents(int column);
0125     void sortByColumn(int column, Qt::SortOrder order);
0126     void expandAll();
0127     void expandRecursively(const QModelIndex &index, int depth = -1);
0128     void collapseAll();
0129     void expandToDepth(int depth);
0130 
0131 protected Q_SLOTS:
0132     void columnResized(int column, int oldSize, int newSize);
0133     void columnCountChanged(int oldCount, int newCount);
0134     void columnMoved();
0135     void reexpand();
0136     void rowsRemoved(const QModelIndex &parent, int first, int last);
0137     void verticalScrollbarValueChanged(int value) override;
0138 
0139 protected:
0140     QTreeView(QTreeViewPrivate &dd, QWidget *parent = nullptr);
0141     void scrollContentsBy(int dx, int dy) override;
0142     void rowsInserted(const QModelIndex &parent, int start, int end) override;
0143     void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) override;
0144 
0145     QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) override;
0146     int horizontalOffset() const override;
0147     int verticalOffset() const override;
0148 
0149     void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command) override;
0150     QRegion visualRegionForSelection(const QItemSelection &selection) const override;
0151     QModelIndexList selectedIndexes() const override;
0152 
0153     void changeEvent(QEvent *event) override;
0154     void timerEvent(QTimerEvent *event) override;
0155     void paintEvent(QPaintEvent *event) override;
0156 
0157     void drawTree(QPainter *painter, const QRegion &region) const;
0158     virtual void drawRow(QPainter *painter,
0159                          const QStyleOptionViewItem &options,
0160                          const QModelIndex &index) const;
0161     virtual void drawBranches(QPainter *painter,
0162                               const QRect &rect,
0163                               const QModelIndex &index) const;
0164 
0165     void mousePressEvent(QMouseEvent *event) override;
0166     void mouseReleaseEvent(QMouseEvent *event) override;
0167     void mouseDoubleClickEvent(QMouseEvent *event) override;
0168     void mouseMoveEvent(QMouseEvent *event) override;
0169     void keyPressEvent(QKeyEvent *event) override;
0170 #if QT_CONFIG(draganddrop)
0171     void dragMoveEvent(QDragMoveEvent *event) override;
0172 #endif
0173     bool viewportEvent(QEvent *event) override;
0174 
0175     void updateGeometries() override;
0176 
0177     QSize viewportSizeHint() const override;
0178 
0179     int sizeHintForColumn(int column) const override;
0180     int indexRowSizeHint(const QModelIndex &index) const;
0181     int rowHeight(const QModelIndex &index) const;
0182 
0183     void horizontalScrollbarAction(int action) override;
0184 
0185     bool isIndexHidden(const QModelIndex &index) const override;
0186     void selectionChanged(const QItemSelection &selected,
0187                           const QItemSelection &deselected) override;
0188     void currentChanged(const QModelIndex &current, const QModelIndex &previous) override;
0189 
0190 private:
0191     friend class ::tst_QTreeView;
0192     friend class QAccessibleTable;
0193     friend class QAccessibleTree;
0194     friend class QAccessibleTableCell;
0195     int visualIndex(const QModelIndex &index) const;
0196 
0197     Q_DECLARE_PRIVATE(QTreeView)
0198     Q_DISABLE_COPY(QTreeView)
0199 };
0200 
0201 QT_END_NAMESPACE
0202 
0203 #endif // QTREEVIEW_H