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 "qitemselectionmodel.h"
19#include "private/qobject_p.h"
20#include "private/qproperty_p.h"
21#include <array>
22
23QT_REQUIRE_CONFIG(itemmodel);
24
25QT_BEGIN_NAMESPACE
26
27class QItemSelectionModelPrivate: public QObjectPrivate
28{
29 Q_DECLARE_PUBLIC(QItemSelectionModel)
30public:
31 QItemSelectionModelPrivate()
32 : currentCommand(QItemSelectionModel::NoUpdate),
33 tableSelected(false), tableColCount(0), tableRowCount(0) {}
34 ~QItemSelectionModelPrivate() override;
35
36 QItemSelection expandSelection(const QItemSelection &selection,
37 QItemSelectionModel::SelectionFlags command) const;
38
39 void initModel(QAbstractItemModel *model);
40
41 void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
42 void columnsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
43 void rowsAboutToBeInserted(const QModelIndex &parent, int start, int end);
44 void columnsAboutToBeInserted(const QModelIndex &parent, int start, int end);
45 void layoutAboutToBeChanged(const QList<QPersistentModelIndex> &parents, QAbstractItemModel::LayoutChangeHint hint);
46 void triggerLayoutToBeChanged()
47 {
48 layoutAboutToBeChanged(parents: QList<QPersistentModelIndex>(), hint: QAbstractItemModel::NoLayoutChangeHint);
49 }
50
51 void layoutChanged(const QList<QPersistentModelIndex> &parents, QAbstractItemModel::LayoutChangeHint hint);
52 void triggerLayoutChanged()
53 {
54 layoutChanged(parents: QList<QPersistentModelIndex>(), hint: QAbstractItemModel::NoLayoutChangeHint);
55 }
56
57 void modelDestroyed();
58
59 inline void remove(QList<QItemSelectionRange> &r)
60 {
61 QList<QItemSelectionRange>::const_iterator it = r.constBegin();
62 for (; it != r.constEnd(); ++it)
63 ranges.removeAll(t: *it);
64 }
65
66 inline void finalize()
67 {
68 ranges.merge(other: currentSelection, command: currentCommand);
69 if (!currentSelection.isEmpty()) // ### perhaps this should be in QList
70 currentSelection.clear();
71 }
72
73 void setModel(QAbstractItemModel *mod) { q_func()->setModel(mod); }
74 void disconnectModel();
75 void modelChanged(QAbstractItemModel *mod) { Q_EMIT q_func()->modelChanged(model: mod); }
76 Q_OBJECT_COMPAT_PROPERTY_WITH_ARGS(QItemSelectionModelPrivate, QAbstractItemModel *, model,
77 &QItemSelectionModelPrivate::setModel,
78 &QItemSelectionModelPrivate::modelChanged, nullptr)
79
80 QItemSelection ranges;
81 QItemSelection currentSelection;
82 QPersistentModelIndex currentIndex;
83 QItemSelectionModel::SelectionFlags currentCommand;
84 QList<QPersistentModelIndex> savedPersistentIndexes;
85 QList<QPersistentModelIndex> savedPersistentCurrentIndexes;
86 QList<std::pair<QPersistentModelIndex, uint>> savedPersistentRowLengths;
87 QList<std::pair<QPersistentModelIndex, uint>> savedPersistentCurrentRowLengths;
88 // optimization when all indexes are selected
89 bool tableSelected;
90 QPersistentModelIndex tableParent;
91 int tableColCount, tableRowCount;
92 std::array<QMetaObject::Connection, 12> connections;
93};
94
95QT_END_NAMESPACE
96
97#endif // QITEMSELECTIONMODEL_P_H
98

Provided by KDAB

Privacy Policy
Learn Advanced QML with KDAB
Find out more

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