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
25
27{
28 Q_GADGET
29 QML_ANONYMOUS
30public:
31 struct MoveKey
32 {
33 MoveKey() {}
34 MoveKey(int moveId, int offset) : moveId(moveId), offset(offset) {}
35 int moveId = -1;
36 int offset = 0;
37 };
38
39 // The storrage for Change (below). This struct is trivial, which it has to be in order to store
40 // it in a QV4::Heap::Base object. The Change struct doesn't add any storage fields, so it is
41 // safe to cast ChangeData to/from Change.
42 struct ChangeData
43 {
44 int index;
45 int count;
46 int moveId;
47 int offset;
48 };
49
50 struct Change: ChangeData
51 {
52 Change() {
53 index = 0;
54 count = 0;
55 moveId = -1;
56 offset = 0;
57 }
58 Change(int index, int count, int moveId = -1, int offset = 0) {
59 this->index = index;
60 this->count = count;
61 this->moveId = moveId;
62 this->offset = offset;
63 }
64
65 bool isMove() const { return moveId >= 0; }
66
67 MoveKey moveKey(int index) const {
68 return MoveKey(moveId, index - Change::index + offset); }
69
70 int start() const { return index; }
71 int end() const { return index + count; }
72 };
73
74 QQmlChangeSet();
75 QQmlChangeSet(const QQmlChangeSet &changeSet);
76 ~QQmlChangeSet();
77
78 QQmlChangeSet &operator =(const QQmlChangeSet &changeSet);
79
80 const QVector<Change> &removes() const { return m_removes; }
81 const QVector<Change> &inserts() const { return m_inserts; }
82 const QVector<Change> &changes() const { return m_changes; }
83
84 void insert(int index, int count);
85 void remove(int index, int count);
86 void move(int from, int to, int count, int moveId);
87 void change(int index, int count);
88
89 void insert(const QVector<Change> &inserts);
90 void remove(const QVector<Change> &removes, QVector<Change> *inserts = nullptr);
91 void move(const QVector<Change> &removes, const QVector<Change> &inserts);
92 void change(const QVector<Change> &changes);
93 void apply(const QQmlChangeSet &changeSet);
94
95 bool isEmpty() const { return m_removes.empty() && m_inserts.empty() && m_changes.isEmpty(); }
96
97 void clear()
98 {
99 m_removes.clear();
100 m_inserts.clear();
101 m_changes.clear();
102 m_difference = 0;
103 }
104
105 int difference() const { return m_difference; }
106
107private:
108 void remove(QVector<Change> *removes, QVector<Change> *inserts);
109 void change(QVector<Change> *changes);
110
111 QVector<Change> m_removes;
112 QVector<Change> m_inserts;
113 QVector<Change> m_changes;
114 int m_difference;
115};
116
117Q_DECLARE_TYPEINFO(QQmlChangeSet::Change, Q_PRIMITIVE_TYPE);
118Q_DECLARE_TYPEINFO(QQmlChangeSet::MoveKey, Q_PRIMITIVE_TYPE);
119
120inline size_t qHash(const QQmlChangeSet::MoveKey &key) { return qHash(std::make_pair(key.moveId, key.offset)); }
121inline bool operator ==(const QQmlChangeSet::MoveKey &l, const QQmlChangeSet::MoveKey &r) {
122 return l.moveId == r.moveId && l.offset == r.offset; }
123
124Q_QMLMODELS_EXPORT QDebug operator <<(QDebug debug, const QQmlChangeSet::Change &change);
125Q_QMLMODELS_EXPORT QDebug operator <<(QDebug debug, const QQmlChangeSet &change);
126
127QT_END_NAMESPACE
128
129#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:801
The QQmlChangeSet class stores an ordered list of notifications about changes to a linear data set.
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
Definition qdir.cpp:2568
QDebug operator<<(QDebug dbg, const QFileInfo &fi)
size_t qHash(const QHashedString &string)