Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qtreewidget_p.h
Go to the documentation of this file.
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 QTREEWIDGET_P_H
5#define QTREEWIDGET_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. This header file may change
12// from version to version without notice, or even be removed.
13//
14// We mean it.
15//
16
17#include <QtWidgets/private/qtwidgetsglobal_p.h>
18#include <QtCore/qabstractitemmodel.h>
19#include <private/qabstractitemmodel_p.h>
20#include <QtCore/qpair.h>
21#include <QtCore/qbasictimer.h>
22#include <QtWidgets/qtreewidget.h>
23#include <private/qtreeview_p.h>
24#include <QtWidgets/qheaderview.h>
25
26#include <array>
27
29
31
32class QTreeWidgetItem;
35
37{
39 friend class QTreeWidget;
40 friend class QTreeWidgetPrivate;
41 friend class QTreeWidgetItem;
45
46public:
47 explicit QTreeModel(int columns = 0, QTreeWidget *parent = nullptr);
49
50 inline QTreeWidget *view() const
51 { return qobject_cast<QTreeWidget*>(QObject::parent()); }
52
53 void clear();
54 void setColumnCount(int columns);
55
58
59 QModelIndex index(const QTreeWidgetItem *item, int column) const;
60 QModelIndex index(int row, int column, const QModelIndex &parent) const override;
61 QModelIndex parent(const QModelIndex &child) const override;
62 int rowCount(const QModelIndex &parent) const override;
63 int columnCount(const QModelIndex &parent = QModelIndex()) const override;
64 bool hasChildren(const QModelIndex &parent) const override;
65
66 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
67 bool setData(const QModelIndex &index, const QVariant &value, int role) override;
68 bool clearItemData(const QModelIndex &index) override;
69 QMap<int, QVariant> itemData(const QModelIndex &index) const override;
70
71 QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
72 bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value,
73 int role) override;
74
75 Qt::ItemFlags flags(const QModelIndex &index) const override;
76
77 void sort(int column, Qt::SortOrder order) override;
79 int start, int end, const QModelIndex &parent);
80 static bool itemLessThan(const QPair<QTreeWidgetItem*,int> &left,
81 const QPair<QTreeWidgetItem*,int> &right);
82 static bool itemGreaterThan(const QPair<QTreeWidgetItem*,int> &left,
83 const QPair<QTreeWidgetItem*,int> &right);
88
89 bool insertRows(int row, int count, const QModelIndex &) override;
90 bool insertColumns(int column, int count, const QModelIndex &) override;
91
92 bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
93
94 // dnd
95 QStringList mimeTypes() const override;
96 QMimeData *mimeData(const QModelIndexList &indexes) const override;
97 bool dropMimeData(const QMimeData *data, Qt::DropAction action,
98 int row, int column, const QModelIndex &parent) override;
99 Qt::DropActions supportedDropActions() const override;
100
102
104 { return createIndex(row, col, item); }
105
106protected:
108 void emitDataChanged(QTreeWidgetItem *item, int column, const QList<int> &roles);
110 void endInsertItems();
112 void endRemoveItems();
113 void sortItems(QList<QTreeWidgetItem*> *items, int column, Qt::SortOrder order);
114 void timerEvent(QTimerEvent *) override;
115
116private:
118 QTreeWidgetItem *headerItem;
119
120 mutable QModelIndexList cachedIndexes;
121 QList<QTreeWidgetItemIterator*> iterators;
122
123 mutable QBasicTimer sortPendingTimer;
124 mutable bool skipPendingSort = false; // no sorting during internal operations
125 bool inline executePendingSort() const;
126
127 bool isChanging() const;
128
129private:
130 Q_DECLARE_PRIVATE(QTreeModel)
131public:
133 {
134 const QTreeModel * const model;
135 const bool previous;
136 SkipSorting(const QTreeModel *m) : model(m), previous(model ? model->skipPendingSort : false)
137 { if (model) model->skipPendingSort = true; }
138 ~SkipSorting() { if (model) model->skipPendingSort = previous; }
139 };
140 friend struct SkipSorting;
141};
142
144#include "private/qabstractitemmodel_p.h"
146
148{
149 Q_DECLARE_PUBLIC(QTreeModel)
150 void executePendingOperations() const override;
151};
152
170
171
172inline bool QTreeModel::executePendingSort() const
173{
174 if (!skipPendingSort && sortPendingTimer.isActive() && !isChanging()) {
175 sortPendingTimer.stop();
178 QTreeModel *that = const_cast<QTreeModel*>(this);
179 that->sort(column, order);
180 return true;
181 }
182 return false;
183}
184
186{
187 friend class QTreeModel;
188 Q_DECLARE_PUBLIC(QTreeWidget)
189public:
191 void clearConnections();
192 inline QTreeModel *treeModel() const { return qobject_cast<QTreeModel*>(model); }
193 inline QModelIndex index(const QTreeWidgetItem *item, int column = 0) const
194 { return treeModel()->index(item, column); }
195 inline QTreeWidgetItem *item(const QModelIndex &index) const
196 { return treeModel()->item(index); }
197 void emitItemPressed(const QModelIndex &index);
198 void emitItemClicked(const QModelIndex &index);
201 void emitItemEntered(const QModelIndex &index);
202 void emitItemChanged(const QModelIndex &index);
205 void emitCurrentItemChanged(const QModelIndex &previous, const QModelIndex &index);
206 void sort();
207 void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
208 void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
209
210 // used by QTreeWidgetItem::sortChildren to make sure the column argument is used
212
213 std::array<QMetaObject::Connection, 12> connections;
214};
215
217
218#endif // QTREEWIDGET_P_H
Q_INVOKABLE int const QModelIndex & parent
Returns the parent of the model item with the given index.
QModelIndex createIndex(int row, int column, const void *data=nullptr) const
Creates a model index for the given row and column with the internal pointer ptr.
\inmodule QtCore
Definition qbasictimer.h:18
void stop()
Stops the timer.
bool isActive() const noexcept
Returns true if the timer is running and has not been stopped; otherwise returns false.
Definition qbasictimer.h:34
Qt::SortOrder sortIndicatorOrder() const
Returns the order for the sort indicator.
int sortIndicatorSection() const
Returns the logical index of the section that has a sort indicator.
\inmodule QtCore
\inmodule QtCore
Definition qmimedata.h:16
\inmodule QtCore
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
\inmodule QtCore
\inmodule QtCore
Definition qcoreevent.h:366
void executePendingOperations() const override
see QTBUG-94546
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role) override
void ensureSorted(int column, Qt::SortOrder order, int start, int end, const QModelIndex &parent)
int rowCount(const QModelIndex &parent) const override
bool setData(const QModelIndex &index, const QVariant &value, int role) override
bool insertColumns(int column, int count, const QModelIndex &) override
QTreeWidget * view() const
void emitDataChanged(QTreeWidgetItem *item, int column, const QList< int > &roles)
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
void endInsertItems()
void itemChanged(QTreeWidgetItem *item)
void setColumnCount(int columns)
bool insertRows(int row, int count, const QModelIndex &) override
void sortItems(QList< QTreeWidgetItem * > *items, int column, Qt::SortOrder order)
QMimeData * internalMimeData() const
QTreeWidgetItem * item(const QModelIndex &index) const
Qt::DropActions supportedDropActions() const override
QTreeModel(int columns=0, QTreeWidget *parent=nullptr)
int columnCount(const QModelIndex &parent=QModelIndex()) const override
void sort(int column, Qt::SortOrder order) override
static bool itemLessThan(const QPair< QTreeWidgetItem *, int > &left, const QPair< QTreeWidgetItem *, int > &right)
QModelIndex createIndexFromItem(int row, int col, QTreeWidgetItem *item) const
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
bool clearItemData(const QModelIndex &index) override
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
Handles the data supplied by a drag and drop operation that ended with the given action.
static QList< QTreeWidgetItem * >::iterator sortedInsertionIterator(const QList< QTreeWidgetItem * >::iterator &begin, const QList< QTreeWidgetItem * >::iterator &end, Qt::SortOrder order, QTreeWidgetItem *item)
QStringList mimeTypes() const override
Returns the list of allowed MIME types.
QMap< int, QVariant > itemData(const QModelIndex &index) const override
Returns a map with values for all predefined roles in the model for the item at the given index.
QModelIndex index(const QTreeWidgetItem *item, int column) const
bool hasChildren(const QModelIndex &parent) const override
Returns {true} if parent has any children; otherwise returns {false}.
void timerEvent(QTimerEvent *) override
This event handler can be reimplemented in a subclass to receive timer events for the object.
friend class QTreeWidgetItemIteratorPrivate
void beginRemoveItems(QTreeWidgetItem *parent, int row, int count)
void beginInsertItems(QTreeWidgetItem *parent, int row, int count)
void endRemoveItems()
static bool itemGreaterThan(const QPair< QTreeWidgetItem *, int > &left, const QPair< QTreeWidgetItem *, int > &right)
QHeaderView * header() const
Returns the header for the tree view.
QTreeWidgetItemPrivate(QTreeWidgetItem *item)
void sortChildren(int column, Qt::SortOrder order, bool climb)
void updateHiddenStatus(QTreeWidgetItem *item, bool inserting)
QTreeWidgetItem::ChildIndicatorPolicy policy
QTreeWidgetItem * q
void propagateDisabled(QTreeWidgetItem *item)
The QTreeWidgetItem class provides an item for use with the QTreeWidget convenience class.
Definition qtreewidget.h:23
QModelIndex index(const QTreeWidgetItem *item, int column=0) const
void emitItemPressed(const QModelIndex &index)
QTreeModel * treeModel() const
void emitItemChanged(const QModelIndex &index)
std::array< QMetaObject::Connection, 12 > connections
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
void emitCurrentItemChanged(const QModelIndex &previous, const QModelIndex &index)
void emitItemEntered(const QModelIndex &index)
void emitItemExpanded(const QModelIndex &index)
void emitItemActivated(const QModelIndex &index)
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
void emitItemClicked(const QModelIndex &index)
QTreeWidgetItem * item(const QModelIndex &index) const
void emitItemCollapsed(const QModelIndex &index)
void emitItemDoubleClicked(const QModelIndex &index)
The QTreeWidget class provides a tree view that uses a predefined tree model.
\inmodule QtCore
Definition qvariant.h:65
Combined button and popup list for selecting options.
Orientation
Definition qnamespace.h:98
@ DisplayRole
SortOrder
Definition qnamespace.h:121
DropAction
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
const GLfloat * m
GLuint index
[2]
GLuint GLuint end
GLenum GLenum GLsizei count
GLdouble GLdouble right
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint left
GLbitfield flags
GLuint start
GLenum GLenum GLsizei void GLsizei void * column
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLenum GLenum GLsizei void * row
GLfixed GLfixed GLint GLint order
const QQuickItem * rootItem(const I &item)
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
#define QT_BEGIN_INCLUDE_NAMESPACE
#define QT_END_INCLUDE_NAMESPACE
#define QT_REQUIRE_CONFIG(feature)
#define Q_OBJECT
unsigned int uint
Definition qtypes.h:34
QMimeData * mimeData
QGraphicsItem * item
QList< QTreeWidgetItem * > items
QLayoutItem * child
[0]
SkipSorting(const QTreeModel *m)
const QTreeModel *const model