Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qdeclarativesupportedcategoriesmodel_p.h
Go to the documentation of this file.
1// Copyright (C) 2022 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 QDECLARATIVESUPPORTEDCATEGORIESMODEL_H
5#define QDECLARATIVESUPPORTEDCATEGORIESMODEL_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 <QtLocation/private/qlocationglobal_p.h>
19#include <QtLocation/private/qdeclarativegeoserviceprovider_p.h>
20
21#include <QObject>
22#include <QtCore/QStringList>
23#include <QtCore/QSharedPointer>
24#include <QAbstractListModel>
25#include <QQmlListProperty>
26#include <QtQml/QQmlParserStatus>
27
28#include <QtLocation/QPlaceCategory>
29
30#include <QtLocation/private/qdeclarativecategory_p.h>
31
33
35class QPlaceManager;
36class QPlaceReply;
37
38class Q_LOCATION_PRIVATE_EXPORT QDeclarativeSupportedCategoriesModel : public QAbstractItemModel, public QQmlParserStatus
39{
41 QML_NAMED_ELEMENT(CategoryModel)
43
45
46 Q_PROPERTY(QDeclarativeGeoServiceProvider *plugin READ plugin WRITE setPlugin NOTIFY pluginChanged)
47 Q_PROPERTY(bool hierarchical READ hierarchical WRITE setHierarchical NOTIFY hierarchicalChanged)
48 Q_PROPERTY(Status status READ status NOTIFY statusChanged)
49
51 Q_ENUMS(Roles) //The Roles enum is for internal usage only.
52
53public:
56
57 // From QQmlParserStatus
58 void classBegin() override {}
59 void componentComplete() override;
60
61 // From QAbstractItemModel
62 int rowCount(const QModelIndex &parent) const override;
63 int columnCount(const QModelIndex &parent) const override;
64
65 QModelIndex index(int row, int column, const QModelIndex &parent) const override;
66 QModelIndex parent(const QModelIndex &child) const override;
67
68 Q_INVOKABLE QVariant data(const QModelIndex &index, int role) const override;
69 QHash<int, QByteArray> roleNames() const override;
70
71 enum Roles {
72 CategoryRole = Qt::UserRole,
73 ParentCategoryRole
74 }; //for internal usage only
75
76 enum Status {Null, Ready, Loading, Error};
77
78 void setPlugin(QDeclarativeGeoServiceProvider *plugin);
79 QDeclarativeGeoServiceProvider *plugin() const;
80
81 void setHierarchical(bool hierarchical);
82 bool hierarchical() const;
83
84 Q_INVOKABLE QString errorString() const;
85
86 Status status() const;
87 void setStatus(Status status, const QString &errorString = QString());
88
95
96public Q_SLOTS:
97 void update();
98
99private Q_SLOTS:
100 void replyFinished();
101 void addedCategory(const QPlaceCategory &category, const QString &parentId);
102 void updatedCategory(const QPlaceCategory &category, const QString &parentId);
103 void removedCategory(const QString &categoryId, const QString &parentId);
104 void connectNotificationSignals();
105
106private:
107 struct PlaceCategoryNode
108 {
109 QString parentId;
110 QStringList childIds;
112 };
113
114 QStringList populateCategories(QPlaceManager *, const QPlaceCategory &parent);
115 QModelIndex index(const QString &categoryId) const;
116 int rowToAddChild(PlaceCategoryNode *, const QPlaceCategory &category);
117 void updateLayout();
118 void emitDataChanged() { Q_EMIT dataChanged(); }
119
120 QPlaceReply *m_response = nullptr;
121
122 QDeclarativeGeoServiceProvider *m_plugin = nullptr;
123 bool m_hierarchical = true;
124 bool m_complete = false;
125 Status m_status = Null;
126 QString m_errorString;
127
129};
130
132
134
135#endif // QDECLARATIVESUPPORTEDCATEGORIESMODEL_H
Q_INVOKABLE int const QModelIndex & parent
Returns the parent of the model item with the given index.
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList< int > &roles=QList< int >())
This signal is emitted whenever the data in an existing item changes.
virtual Q_INVOKABLE int rowCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of rows under the given parent.
virtual QHash< int, QByteArray > roleNames() const
virtual Q_INVOKABLE int columnCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of columns for the children of the given parent.
void classBegin() override
Invoked after class creation, but before any properties have been set.
\inmodule QtLocation
\inmodule QtCore
Definition qhash.h:818
\inmodule QtCore
\inmodule QtCore
Definition qobject.h:90
\inmodule QtLocation
\inmodule QtLocation
\inmodule QtLocation
Definition qplacereply.h:15
The QQmlParserStatus class provides updates on the QML parser state.
virtual void componentComplete()=0
Invoked after the root component that caused this instantiation has completed construction.
\inmodule QtCore
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
\inmodule QtCore
Definition qvariant.h:64
const QLoggingCategory & category()
[1]
void statusChanged(QDeclarativeComponent::Status status)
[1]
Definition qlogging.cpp:9
Combined button and popup list for selecting options.
@ UserRole
GLuint index
[2]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLenum GLsizei void GLsizei void * column
GLenum GLenum GLsizei void * row
#define QML_DECLARE_TYPE(TYPE)
Definition qqml.h:19
#define QML_NAMED_ELEMENT(NAME)
#define QML_ADDED_IN_VERSION(MAJOR, MINOR)
#define Q_PROPERTY(...)
#define Q_OBJECT
#define Q_EMIT
#define Q_INVOKABLE
#define Q_INTERFACES(x)
#define Q_SLOTS
#define Q_ENUMS(x)
#define Q_SIGNALS
QLayoutItem * child
[0]
void replyFinished(QNetworkReply *reply)
[1]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent