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 QITEMSELECTIONMODEL_P_H
5#define QITEMSELECTIONMODEL_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include "private/qobject_p.h"
19#include "private/qproperty_p.h"
20#include <array>
21
22QT_REQUIRE_CONFIG(itemmodel);
23
24QT_BEGIN_NAMESPACE
25
26class QItemSelectionModelPrivate: public QObjectPrivate
27{
28 Q_DECLARE_PUBLIC(QItemSelectionModel)
29public:
30 QItemSelectionModelPrivate()
31 : currentCommand(QItemSelectionModel::NoUpdate),
32 tableSelected(false), tableColCount(0), tableRowCount(0) {}
33
34 QItemSelection expandSelection(const QItemSelection &selection,
35 QItemSelectionModel::SelectionFlags command) const;
36
37 void initModel(QAbstractItemModel *model);
38
39 void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
40 void columnsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
41 void rowsAboutToBeInserted(const QModelIndex &parent, int start, int end);
42 void columnsAboutToBeInserted(const QModelIndex &parent, int start, int end);
43 void layoutAboutToBeChanged(const QList<QPersistentModelIndex> &parents, QAbstractItemModel::LayoutChangeHint hint);
44 void triggerLayoutToBeChanged()
45 {
46 layoutAboutToBeChanged(parents: QList<QPersistentModelIndex>(), hint: QAbstractItemModel::NoLayoutChangeHint);
47 }
48
49 void layoutChanged(const QList<QPersistentModelIndex> &parents, QAbstractItemModel::LayoutChangeHint hint);
50 void triggerLayoutChanged()
51 {
52 layoutChanged(parents: QList<QPersistentModelIndex>(), hint: QAbstractItemModel::NoLayoutChangeHint);
53 }
54
55 void modelDestroyed();
56
57 inline void remove(QList<QItemSelectionRange> &r)
58 {
59 QList<QItemSelectionRange>::const_iterator it = r.constBegin();
60 for (; it != r.constEnd(); ++it)
61 ranges.removeAll(t: *it);
62 }
63
64 inline void finalize()
65 {
66 ranges.merge(other: currentSelection, command: currentCommand);
67 if (!currentSelection.isEmpty()) // ### perhaps this should be in QList
68 currentSelection.clear();
69 }
70
71 void setModel(QAbstractItemModel *mod) { q_func()->setModel(mod); }
72 void disconnectModel();
73 void modelChanged(QAbstractItemModel *mod) { emit q_func()->modelChanged(model: mod); }
74 Q_OBJECT_COMPAT_PROPERTY_WITH_ARGS(QItemSelectionModelPrivate, QAbstractItemModel *, model,
75 &QItemSelectionModelPrivate::setModel,
76 &QItemSelectionModelPrivate::modelChanged, nullptr)
77
78 QItemSelection ranges;
79 QItemSelection currentSelection;
80 QPersistentModelIndex currentIndex;
81 QItemSelectionModel::SelectionFlags currentCommand;
82 QList<QPersistentModelIndex> savedPersistentIndexes;
83 QList<QPersistentModelIndex> savedPersistentCurrentIndexes;
84 QList<QPair<QPersistentModelIndex, uint>> savedPersistentRowLengths;
85 QList<QPair<QPersistentModelIndex, uint>> savedPersistentCurrentRowLengths;
86 // optimization when all indexes are selected
87 bool tableSelected;
88 QPersistentModelIndex tableParent;
89 int tableColCount, tableRowCount;
90 std::array<QMetaObject::Connection, 12> connections;
91};
92
93QT_END_NAMESPACE
94
95#endif // QITEMSELECTIONMODEL_P_H
96

source code of qtbase/src/corelib/itemmodels/qitemselectionmodel_p.h