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
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
32QT_BEGIN_NAMESPACE
33
34class QGeoServiceProvider;
35class QPlaceManager;
36class QPlaceReply;
37
38class Q_LOCATION_EXPORT QDeclarativeSupportedCategoriesModel : public QAbstractItemModel, public QQmlParserStatus
39{
40 Q_OBJECT
41 QML_NAMED_ELEMENT(CategoryModel)
42 QML_ADDED_IN_VERSION(5, 0)
43
44 Q_PROPERTY(QDeclarativeGeoServiceProvider *plugin READ plugin WRITE setPlugin NOTIFY pluginChanged)
45 Q_PROPERTY(bool hierarchical READ hierarchical WRITE setHierarchical NOTIFY hierarchicalChanged)
46 Q_PROPERTY(Status status READ status NOTIFY statusChanged)
47
48 Q_INTERFACES(QQmlParserStatus)
49
50public:
51 explicit QDeclarativeSupportedCategoriesModel(QObject *parent = nullptr);
52 virtual ~QDeclarativeSupportedCategoriesModel();
53
54 // From QQmlParserStatus
55 void classBegin() override {}
56 void componentComplete() override;
57
58 // From QAbstractItemModel
59 int rowCount(const QModelIndex &parent) const override;
60 int columnCount(const QModelIndex &parent) const override;
61
62 QModelIndex index(int row, int column, const QModelIndex &parent) const override;
63 QModelIndex parent(const QModelIndex &child) const override;
64
65 Q_INVOKABLE QVariant data(const QModelIndex &index, int role) const override;
66 QHash<int, QByteArray> roleNames() const override;
67
68 enum Roles {
69 CategoryRole = Qt::UserRole,
70 ParentCategoryRole
71 }; //for internal usage only
72 Q_ENUM(Roles)
73
74 enum Status {Null, Ready, Loading, Error};
75 Q_ENUM(Status)
76
77 void setPlugin(QDeclarativeGeoServiceProvider *plugin);
78 QDeclarativeGeoServiceProvider *plugin() const;
79
80 void setHierarchical(bool hierarchical);
81 bool hierarchical() const;
82
83 Q_INVOKABLE QString errorString() const;
84
85 Status status() const;
86 void setStatus(Status status, const QString &errorString = QString());
87
88 using QAbstractItemModel::dataChanged;
89Q_SIGNALS:
90 void pluginChanged();
91 void hierarchicalChanged();
92 void statusChanged();
93 void dataChanged();
94
95public Q_SLOTS:
96 void update();
97
98private Q_SLOTS:
99 void replyFinished();
100 void addedCategory(const QPlaceCategory &category, const QString &parentId);
101 void updatedCategory(const QPlaceCategory &category, const QString &parentId);
102 void removedCategory(const QString &categoryId, const QString &parentId);
103 void connectNotificationSignals();
104
105private:
106 struct PlaceCategoryNode
107 {
108 QString parentId;
109 QStringList childIds;
110 QSharedPointer<QDeclarativeCategory> declCategory;
111 };
112
113 QStringList populateCategories(QPlaceManager *, const QPlaceCategory &parent);
114 QModelIndex index(const QString &categoryId) const;
115 int rowToAddChild(PlaceCategoryNode *, const QPlaceCategory &category);
116 void updateLayout();
117 void emitDataChanged() { Q_EMIT dataChanged(); }
118
119 QPlaceReply *m_response = nullptr;
120
121 QDeclarativeGeoServiceProvider *m_plugin = nullptr;
122 bool m_hierarchical = true;
123 bool m_complete = false;
124 Status m_status = Null;
125 QString m_errorString;
126
127 QHash<QString, PlaceCategoryNode *> m_categoriesTree;
128};
129
130QT_END_NAMESPACE
131
133
134#endif // QDECLARATIVESUPPORTEDCATEGORIESMODEL_H
Combined button and popup list for selecting options.