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
qqmlxmllistmodel_p.h
Go to the documentation of this file.
1// Copyright (C) 2021 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 QQMLXMLLISTMODEL_H
5#define QQMLXMLLISTMODEL_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 <private/qflatmap_p.h>
19#include <private/qtqmlxmllistmodelglobal_p.h>
20
21#include <QtQml/qqmllist.h>
22#include <QtQml/qqmlparserstatus.h>
23
24#include <QtQmlIntegration/qqmlintegration.h>
25
26#include <QtCore/qabstractitemmodel.h>
27#include <QtCore/qbytearray.h>
28#include <QtCore/qfuture.h>
29#include <QtCore/qhash.h>
30#include <QtCore/qstringlist.h>
31#include <QtCore/qurl.h>
32
34
35#if QT_CONFIG(qml_network)
36class QNetworkReply;
37#endif
38
39class QXmlStreamReader;
40class QQmlContext;
52{
55public:
57 QList<QFlatMap<int, QString>> data;
58 QList<QPair<void *, QString>> errors;
59};
60
61class Q_QMLXMLLISTMODEL_EXPORT QQmlXmlListModelRole : public QObject
62{
64 Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
65 Q_PROPERTY(QString elementName READ elementName WRITE setElementName NOTIFY elementNameChanged)
66 Q_PROPERTY(QString attributeName READ attributeName WRITE setAttributeName NOTIFY
67 attributeNameChanged)
68 QML_NAMED_ELEMENT(XmlListModelRole)
69
70public:
73
74 QString name() const;
75 void setName(const QString &name);
76 QString elementName() const;
77 void setElementName(const QString &name);
78 QString attributeName() const;
79 void setAttributeName(const QString &attributeName);
80 bool isValid() const;
81
83 void nameChanged();
84 void elementNameChanged();
85 void attributeNameChanged();
86
88 QString m_name;
89 QString m_elementName;
90 QString m_attributeName;
91};
92
93class QQmlXmlListModelQueryExecutor;
94
95class Q_QMLXMLLISTMODEL_EXPORT QQmlXmlListModel : public QAbstractListModel,
96 public QQmlParserStatus
97{
100
101 Q_PROPERTY(Status status READ status NOTIFY statusChanged)
102 Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged)
103 Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
104 Q_PROPERTY(QString query READ query WRITE setQuery NOTIFY queryChanged)
106 Q_PROPERTY(int count READ count NOTIFY countChanged)
107 QML_NAMED_ELEMENT(XmlListModel)
108 Q_CLASSINFO("DefaultProperty", "roles")
109
110public:
111 QQmlXmlListModel(QObject *parent = nullptr);
113
114 QModelIndex index(int row, int column, const QModelIndex &parent) const override;
115 int rowCount(const QModelIndex &parent) const override;
116 QVariant data(const QModelIndex &index, int role) const override;
117 QHash<int, QByteArray> roleNames() const override;
118
119 int count() const;
120
121 QUrl source() const;
122 void setSource(const QUrl &);
123
124 QString query() const;
125 void setQuery(const QString &);
126
128
129 void appendRole(QQmlXmlListModelRole *);
130 void clearRole();
131
132 enum Status { Null, Ready, Loading, Error };
133 Q_ENUM(Status)
134 Status status() const;
135 qreal progress() const;
136
137 Q_INVOKABLE QString errorString() const;
138
139 void classBegin() override;
140 void componentComplete() override;
141
144 void progressChanged(qreal progress);
148
149public Q_SLOTS:
150 void reload();
151
152private Q_SLOTS:
153#if QT_CONFIG(qml_network)
154 void requestFinished();
155#endif
156 void requestProgress(qint64, qint64);
157 void dataCleared();
158 void queryCompleted(const QQmlXmlListModelQueryResult &);
159 void queryError(void *object, const QString &error);
160
161private:
162 Q_DISABLE_COPY(QQmlXmlListModel)
163
164 void notifyQueryStarted(bool remoteSource);
165
166 static void appendRole(QQmlListProperty<QQmlXmlListModelRole> *, QQmlXmlListModelRole *);
167 static void clearRole(QQmlListProperty<QQmlXmlListModelRole> *);
168
169 void tryExecuteQuery(const QByteArray &data);
170
171 QQmlXmlListModelQueryJob createJob(const QByteArray &data);
172 int nextQueryId();
173
174#if QT_CONFIG(qml_network)
175 void deleteReply();
176
177 QNetworkReply *m_reply = nullptr;
178#endif
179
180 int m_size = 0;
181 QUrl m_source;
182 QString m_query;
183 QStringList m_roleNames;
184 QList<int> m_roles;
185 QList<QQmlXmlListModelRole *> m_roleObjects;
186 QList<QFlatMap<int, QString>> m_data;
187 bool m_isComponentComplete = true;
189 QString m_errorString;
190 qreal m_progress = 0;
191 int m_queryId = -1;
192 int m_nextQueryIdGenerator = -1;
193 int m_highestRole = Qt::UserRole;
194 using ResultFutureWatcher = QFutureWatcher<QQmlXmlListModelQueryResult>;
195 QFlatMap<int, ResultFutureWatcher *> m_watchers;
196};
197
199{
200public:
202 void run() override;
203
204 QFuture<QQmlXmlListModelQueryResult> future() const;
205
206private:
207 void doQueryJob(QQmlXmlListModelQueryResult *currentResult);
208 void processElement(QQmlXmlListModelQueryResult *currentResult, const QString &element,
209 QXmlStreamReader &reader);
210 void readSubTree(const QString &prefix, QXmlStreamReader &reader,
211 QFlatMap<int, QString> &results, QList<QPair<void *, QString>> *errors);
212
214 QPromise<QQmlXmlListModelQueryResult> m_promise;
215};
216
218
219#endif // QQMLXMLLISTMODEL_H
NSData * m_data
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore
Definition qhash.h:820
Definition qlist.h:75
\inmodule QtCore
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
\inmodule QtCore
Definition qobject.h:103
The QQmlContext class defines a context within a QML engine.
Definition qqmlcontext.h:25
The QQmlListProperty class allows applications to expose list-like properties of QObject-derived clas...
Definition qqmllist.h:24
The QQmlParserStatus class provides updates on the QML parser state.
void progressChanged(qreal progress)
void statusChanged(QQmlXmlListModel::Status)
\inmodule QtCore
Definition qrunnable.h:18
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qurl.h:94
\inmodule QtCore
Definition qvariant.h:65
void statusChanged(QQmlComponent::Status status)
[1]
Definition qlogging.cpp:11
employee setName("Richard Schmit")
Combined button and popup list for selecting options.
@ UserRole
DBusConnection const char DBusError * error
GLuint index
[2]
GLenum GLenum GLsizei count
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLuint * nextQueryId
GLuint name
GLsizei GLsizei GLchar * source
GLenum GLenum GLsizei void GLsizei void * column
GLenum query
GLenum GLenum GLsizei void * row
#define QML_ANONYMOUS
#define QML_NAMED_ELEMENT(NAME)
#define Q_ENUM(x)
#define Q_PROPERTY(...)
#define Q_OBJECT
#define Q_CLASSINFO(name, value)
#define Q_INVOKABLE
#define Q_INTERFACES(x)
#define Q_SLOTS
#define Q_GADGET
#define Q_SIGNALS
long long qint64
Definition qtypes.h:60
double qreal
Definition qtypes.h:187
QFuture< void > future
[5]
qDebug()<< QUrl("file copy setQuery(copy.query(QUrl::FullyDecoded), QUrl::DecodedMode)
QList< QPair< void *, QString > > errors
QList< QFlatMap< int, QString > > data