Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qitemselectionmodel_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// Qt-Security score:significant reason:default
4
5#ifndef QITEMSELECTIONMODEL_P_H
6#define QITEMSELECTIONMODEL_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
20#include "private/qobject_p.h"
21#include "private/qproperty_p.h"
22#include <array>
23
25
26QT_BEGIN_NAMESPACE
27
28class QItemSelectionModelPrivate: public QObjectPrivate
29{
30 Q_DECLARE_PUBLIC(QItemSelectionModel)
31public:
32 QItemSelectionModelPrivate()
33 : currentCommand(QItemSelectionModel::NoUpdate),
34 tableSelected(false), tableColCount(0), tableRowCount(0) {}
35 ~QItemSelectionModelPrivate() override;
36
37 QItemSelection expandSelection(const QItemSelection &selection,
38 QItemSelectionModel::SelectionFlags command) const;
39
40 void initModel(QAbstractItemModel *model);
41
42 void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
43 void columnsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
44 void rowsAboutToBeInserted(const QModelIndex &parent, int start, int end);
45 void columnsAboutToBeInserted(const QModelIndex &parent, int start, int end);
46 void layoutAboutToBeChanged(const QList<QPersistentModelIndex> &parents, QAbstractItemModel::LayoutChangeHint hint);
47 void triggerLayoutToBeChanged()
48 {
49 layoutAboutToBeChanged(QList<QPersistentModelIndex>(), QAbstractItemModel::NoLayoutChangeHint);
50 }
51
52 void layoutChanged(const QList<QPersistentModelIndex> &parents, QAbstractItemModel::LayoutChangeHint hint);
53 void triggerLayoutChanged()
54 {
55 layoutChanged(QList<QPersistentModelIndex>(), QAbstractItemModel::NoLayoutChangeHint);
56 }
57
58 void modelDestroyed();
59
60 inline void remove(QList<QItemSelectionRange> &r)
61 {
62 QList<QItemSelectionRange>::const_iterator it = r.constBegin();
63 for (; it != r.constEnd(); ++it)
64 ranges.removeAll(*it);
65 }
66
67 inline void finalize()
68 {
69 ranges.merge(currentSelection, currentCommand);
70 if (!currentSelection.isEmpty()) // ### perhaps this should be in QList
71 currentSelection.clear();
72 }
73
74 void setModel(QAbstractItemModel *mod) { q_func()->setModel(mod); }
75 void disconnectModel();
76 void modelChanged(QAbstractItemModel *mod) { Q_EMIT q_func()->modelChanged(mod); }
77 Q_OBJECT_COMPAT_PROPERTY_WITH_ARGS(QItemSelectionModelPrivate, QAbstractItemModel *, model,
78 &QItemSelectionModelPrivate::setModel,
79 &QItemSelectionModelPrivate::modelChanged, nullptr)
80
81 QItemSelection ranges;
82 QItemSelection currentSelection;
83 QPersistentModelIndex currentIndex;
84 QItemSelectionModel::SelectionFlags currentCommand;
85 QList<QPersistentModelIndex> savedPersistentIndexes;
86 QList<QPersistentModelIndex> savedPersistentCurrentIndexes;
87 QList<std::pair<QPersistentModelIndex, uint>> savedPersistentRowLengths;
88 QList<std::pair<QPersistentModelIndex, uint>> savedPersistentCurrentRowLengths;
89 // optimization when all indexes are selected
90 bool tableSelected;
91 QPersistentModelIndex tableParent;
92 int tableColCount, tableRowCount;
93 std::array<QMetaObject::Connection, 12> connections;
94};
95
96QT_END_NAMESPACE
97
98#endif // QITEMSELECTIONMODEL_P_H
QT_REQUIRE_CONFIG(itemmodel)
QDebug operator<<(QDebug dbg, const QFileInfo &fi)
static bool selectionIsEmpty(const QItemSelection &selection)
static QItemSelection mergeIndexes(const QList< QPersistentModelIndex > &indexes)
static bool qt_PersistentModelIndexLessThan(const QPersistentModelIndex &i1, const QPersistentModelIndex &i2)
static ModelIndexContainer qSelectionIndexes(const QItemSelection &selection)
static void indexesFromRange(const QItemSelectionRange &range, ModelIndexContainer &result)
static QList< std::pair< QPersistentModelIndex, uint > > qSelectionPersistentRowLengths(const QItemSelection &sel)
static bool isSelectableAndEnabled(Qt::ItemFlags flags)
static void rowLengthsFromRange(const QItemSelectionRange &range, QList< std::pair< QPersistentModelIndex, uint > > &result)
static QItemSelection mergeRowLengths(const QList< std::pair< QPersistentModelIndex, uint > > &rowLengths)
size_t qHash(const RowOrColumnDefinition &key, size_t seed=0) noexcept
friend bool operator==(const RowOrColumnDefinition &lhs, const RowOrColumnDefinition &rhs) noexcept
friend bool operator!=(const RowOrColumnDefinition &lhs, const RowOrColumnDefinition &rhs) noexcept