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
qqmlchangeset_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
4
5#ifndef QQMLCHANGESET_P_H
6#define QQMLCHANGESET_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
19#include <QtQmlIntegration/qqmlintegration.h>
20#include <QtCore/qdebug.h>
21#include <QtCore/qvector.h>
22#include <QtQmlModels/private/qtqmlmodelsglobal_p.h>
23
24#include <QtCore/qhashfunctions.h>
25
27
29{
30 Q_GADGET
31 QML_ANONYMOUS
32public:
33 struct MoveKey
34 {
35 MoveKey() {}
36 MoveKey(int moveId, int offset) : moveId(moveId), offset(offset) {}
37 int moveId = -1;
38 int offset = 0;
39
40 private:
41 friend size_t qHash(MoveKey key, size_t seed = 0) noexcept
42 { return qHashMulti(seed, key.moveId, key.offset); }
43 };
44
45 // The storrage for Change (below). This struct is trivial, which it has to be in order to store
46 // it in a QV4::Heap::Base object. The Change struct doesn't add any storage fields, so it is
47 // safe to cast ChangeData to/from Change.
48 struct ChangeData
49 {
50 int index;
51 int count;
52 int moveId;
53 int offset;
54 };
55
56 struct Change: ChangeData
57 {
58 Change() {
59 index = 0;
60 count = 0;
61 moveId = -1;
62 offset = 0;
63 }
64 Change(int index, int count, int moveId = -1, int offset = 0) {
65 this->index = index;
66 this->count = count;
67 this->moveId = moveId;
68 this->offset = offset;
69 }
70
71 bool isMove() const { return moveId >= 0; }
72
73 MoveKey moveKey(int index) const {
74 return MoveKey(moveId, index - Change::index + offset); }
75
76 int start() const { return index; }
77 int end() const { return index + count; }
78 };
79
80 QQmlChangeSet();
81 QQmlChangeSet(const QQmlChangeSet &changeSet);
82 ~QQmlChangeSet();
83
84 QQmlChangeSet &operator =(const QQmlChangeSet &changeSet);
85
86 const QList<Change> &removes() const { return m_removes; }
87 const QList<Change> &inserts() const { return m_inserts; }
88 const QList<Change> &changes() const { return m_changes; }
89
90 void insert(int index, int count);
91 void remove(int index, int count);
92 void move(int from, int to, int count, int moveId);
93 void change(int index, int count);
94
95 void insert(const QList<Change> &inserts);
96 void remove(const QList<Change> &removes, QList<Change> *inserts = nullptr);
97 void move(const QList<Change> &removes, const QList<Change> &inserts);
98 void change(const QList<Change> &changes);
99 void apply(const QQmlChangeSet &changeSet);
100
101 bool isEmpty() const { return m_removes.empty() && m_inserts.empty() && m_changes.isEmpty(); }
102
103 void clear()
104 {
105 m_removes.clear();
106 m_inserts.clear();
107 m_changes.clear();
108 m_difference = 0;
109 }
110
111 int difference() const { return m_difference; }
112
113private:
114 void remove(QList<Change> *removes, QList<Change> *inserts);
115 void change(QList<Change> *changes);
116
117 QList<Change> m_removes;
118 QList<Change> m_inserts;
119 QList<Change> m_changes;
120 int m_difference;
121};
122
123Q_DECLARE_TYPEINFO(QQmlChangeSet::Change, Q_PRIMITIVE_TYPE);
124Q_DECLARE_TYPEINFO(QQmlChangeSet::MoveKey, Q_PRIMITIVE_TYPE);
125
126inline bool operator ==(const QQmlChangeSet::MoveKey &l, const QQmlChangeSet::MoveKey &r) {
127 return l.moveId == r.moveId && l.offset == r.offset; }
128
129Q_QMLMODELS_EXPORT QDebug operator <<(QDebug debug, const QQmlChangeSet::Change &change);
130Q_QMLMODELS_EXPORT QDebug operator <<(QDebug debug, const QQmlChangeSet &change);
131
132QT_END_NAMESPACE
133
134#endif
friend bool operator==(const QByteArray::FromBase64Result &lhs, const QByteArray::FromBase64Result &rhs) noexcept
Returns true if lhs and rhs are equal, otherwise returns false.
Definition qbytearray.h:803
The QQmlChangeSet class stores an ordered list of notifications about changes to a linear data set.
Combined button and popup list for selecting options.
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
Definition qdir.cpp:2582
QDebug operator<<(QDebug dbg, const QFileInfo &fi)