Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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 <QtQmlIntegration/qqmlintegration.h>
19#include <QtCore/qdebug.h>
20#include <QtCore/qvector.h>
21#include <QtQmlModels/private/qtqmlmodelsglobal_p.h>
22
24
25class Q_QMLMODELS_EXPORT QQmlChangeSet
26{
29public:
30 struct MoveKey
31 {
33 MoveKey(int moveId, int offset) : moveId(moveId), offset(offset) {}
34 int moveId = -1;
35 int offset = 0;
36 };
37
38 // The storrage for Change (below). This struct is trivial, which it has to be in order to store
39 // it in a QV4::Heap::Base object. The Change struct doesn't add any storage fields, so it is
40 // safe to cast ChangeData to/from Change.
42 {
43 int index;
44 int count;
45 int moveId;
46 int offset;
47 };
48
50 {
52 index = 0;
53 count = 0;
54 moveId = -1;
55 offset = 0;
56 }
57 Change(int index, int count, int moveId = -1, int offset = 0) {
58 this->index = index;
59 this->count = count;
60 this->moveId = moveId;
61 this->offset = offset;
62 }
63
64 bool isMove() const { return moveId >= 0; }
65
66 MoveKey moveKey(int index) const {
67 return MoveKey(moveId, index - Change::index + offset); }
68
69 int start() const { return index; }
70 int end() const { return index + count; }
71 };
72
74 QQmlChangeSet(const QQmlChangeSet &changeSet);
76
77 QQmlChangeSet &operator =(const QQmlChangeSet &changeSet);
78
79 const QVector<Change> &removes() const { return m_removes; }
80 const QVector<Change> &inserts() const { return m_inserts; }
81 const QVector<Change> &changes() const { return m_changes; }
82
83 void insert(int index, int count);
84 void remove(int index, int count);
85 void move(int from, int to, int count, int moveId);
86 void change(int index, int count);
87
88 void insert(const QVector<Change> &inserts);
89 void remove(const QVector<Change> &removes, QVector<Change> *inserts = nullptr);
90 void move(const QVector<Change> &removes, const QVector<Change> &inserts);
91 void change(const QVector<Change> &changes);
92 void apply(const QQmlChangeSet &changeSet);
93
94 bool isEmpty() const { return m_removes.empty() && m_inserts.empty() && m_changes.isEmpty(); }
95
96 void clear()
97 {
98 m_removes.clear();
99 m_inserts.clear();
100 m_changes.clear();
101 m_difference = 0;
102 }
103
104 int difference() const { return m_difference; }
105
106private:
107 void remove(QVector<Change> *removes, QVector<Change> *inserts);
108 void change(QVector<Change> *changes);
109
110 QVector<Change> m_removes;
111 QVector<Change> m_inserts;
112 QVector<Change> m_changes;
113 int m_difference;
114};
115
118
119inline size_t qHash(const QQmlChangeSet::MoveKey &key) { return qHash(qMakePair(key.moveId, key.offset)); }
121 return l.moveId == r.moveId && l.offset == r.offset; }
122
123Q_QMLMODELS_EXPORT QDebug operator <<(QDebug debug, const QQmlChangeSet::Change &change);
124Q_QMLMODELS_EXPORT QDebug operator <<(QDebug debug, const QQmlChangeSet &change);
125
127
128#endif
\inmodule QtCore
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
QT_BEGIN_NAMESPACE 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
size_t qHash(const QQmlChangeSet::MoveKey &key)
bool operator==(const QQmlChangeSet::MoveKey &l, const QQmlChangeSet::MoveKey &r)
Q_QMLMODELS_EXPORT QDebug operator<<(QDebug debug, const QQmlChangeSet::Change &change)
#define QML_ANONYMOUS
#define Q_GADGET
@ Q_PRIMITIVE_TYPE
Definition qtypeinfo.h:157
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)
Definition qtypeinfo.h:180
settings remove("monkey")
MoveKey moveKey(int index) const
Change(int index, int count, int moveId=-1, int offset=0)
MoveKey(int moveId, int offset)