Qt 6.x
The Qt SDK
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
4#ifndef QQMLCHANGESET_P_H
5#define QQMLCHANGESET_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 <QtCore/qdebug.h>
19#include <QtCore/qvector.h>
20#include <QtQmlModels/private/qtqmlmodelsglobal_p.h>
21
23
24class Q_QMLMODELS_PRIVATE_EXPORT QQmlChangeSet
25{
26public:
27 struct MoveKey
28 {
30 MoveKey(int moveId, int offset) : moveId(moveId), offset(offset) {}
31 int moveId = -1;
32 int offset = 0;
33 };
34
35 // The storrage for Change (below). This struct is trivial, which it has to be in order to store
36 // it in a QV4::Heap::Base object. The Change struct doesn't add any storage fields, so it is
37 // safe to cast ChangeData to/from Change.
39 {
40 int index;
41 int count;
42 int moveId;
43 int offset;
44 };
45
47 {
49 index = 0;
50 count = 0;
51 moveId = -1;
52 offset = 0;
53 }
54 Change(int index, int count, int moveId = -1, int offset = 0) {
55 this->index = index;
56 this->count = count;
57 this->moveId = moveId;
58 this->offset = offset;
59 }
60
61 bool isMove() const { return moveId >= 0; }
62
63 MoveKey moveKey(int index) const {
64 return MoveKey(moveId, index - Change::index + offset); }
65
66 int start() const { return index; }
67 int end() const { return index + count; }
68 };
69
71 QQmlChangeSet(const QQmlChangeSet &changeSet);
73
74 QQmlChangeSet &operator =(const QQmlChangeSet &changeSet);
75
76 const QVector<Change> &removes() const { return m_removes; }
77 const QVector<Change> &inserts() const { return m_inserts; }
78 const QVector<Change> &changes() const { return m_changes; }
79
80 void insert(int index, int count);
81 void remove(int index, int count);
82 void move(int from, int to, int count, int moveId);
83 void change(int index, int count);
84
85 void insert(const QVector<Change> &inserts);
86 void remove(const QVector<Change> &removes, QVector<Change> *inserts = nullptr);
87 void move(const QVector<Change> &removes, const QVector<Change> &inserts);
88 void change(const QVector<Change> &changes);
89 void apply(const QQmlChangeSet &changeSet);
90
91 bool isEmpty() const { return m_removes.empty() && m_inserts.empty() && m_changes.isEmpty(); }
92
93 void clear()
94 {
95 m_removes.clear();
96 m_inserts.clear();
97 m_changes.clear();
98 m_difference = 0;
99 }
100
101 int difference() const { return m_difference; }
102
103private:
104 void remove(QVector<Change> *removes, QVector<Change> *inserts);
105 void change(QVector<Change> *changes);
106
107 QVector<Change> m_removes;
108 QVector<Change> m_inserts;
109 QVector<Change> m_changes;
110 int m_difference;
111};
112
115
116inline size_t qHash(const QQmlChangeSet::MoveKey &key) { return qHash(qMakePair(key.moveId, key.offset)); }
118 return l.moveId == r.moveId && l.offset == r.offset; }
119
120Q_QMLMODELS_PRIVATE_EXPORT QDebug operator <<(QDebug debug, const QQmlChangeSet::Change &change);
121Q_QMLMODELS_PRIVATE_EXPORT QDebug operator <<(QDebug debug, const QQmlChangeSet &change);
122
124
125#endif
\inmodule QtCore
Definition qlist.h:74
The QQmlChangeSet class stores an ordered list of notifications about changes to a linear data set.
const QVector< Change > & removes() const
int difference() const
const QVector< Change > & changes() const
const QVector< Change > & inserts() const
bool isEmpty() const
cache insert(employee->id(), employee)
Combined button and popup list for selecting options.
GLuint64 key
GLuint index
[2]
GLboolean r
[2]
GLenum GLenum GLsizei count
GLenum GLuint GLintptr offset
constexpr decltype(auto) qMakePair(T1 &&value1, T2 &&value2) noexcept(noexcept(std::make_pair(std::forward< T1 >(value1), std::forward< T2 >(value2))))
Definition qpair.h:19
Q_QMLMODELS_PRIVATE_EXPORT QDebug operator<<(QDebug debug, const QQmlChangeSet::Change &change)
size_t qHash(const QQmlChangeSet::MoveKey &key)
bool operator==(const QQmlChangeSet::MoveKey &l, const QQmlChangeSet::MoveKey &r)
@ Q_PRIMITIVE_TYPE
Definition qtypeinfo.h:144
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)
Definition qtypeinfo.h:163
settings remove("monkey")
MoveKey moveKey(int index) const
Change(int index, int count, int moveId=-1, int offset=0)
MoveKey(int moveId, int offset)