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// Qt-Security score:significant reason:default
4
5#ifndef QDECLARATIVESUPPORTEDCATEGORIESMODEL_H
6#define QDECLARATIVESUPPORTEDCATEGORIESMODEL_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtLocation/private/qlocationglobal_p.h>
20#include <QtLocation/private/qdeclarativegeoserviceprovider_p.h>
21
22#include <QObject>
23#include <QtCore/QStringList>
24#include <QtCore/QSharedPointer>
25#include <QAbstractListModel>
26#include <QQmlListProperty>
27#include <QtQml/QQmlParserStatus>
28
29#include <QtLocation/QPlaceCategory>
30
31#include <QtLocation/private/qdeclarativecategory_p.h>
32
33QT_BEGIN_NAMESPACE
34
35class QGeoServiceProvider;
36class QPlaceManager;
37class QPlaceReply;
38
39class Q_LOCATION_EXPORT QDeclarativeSupportedCategoriesModel : public QAbstractItemModel, public QQmlParserStatus
40{
41 Q_OBJECT
42 QML_NAMED_ELEMENT(CategoryModel)
43 QML_ADDED_IN_VERSION(5, 0)
44
45 Q_PROPERTY(QDeclarativeGeoServiceProvider *plugin READ plugin WRITE setPlugin NOTIFY pluginChanged)
46 Q_PROPERTY(bool hierarchical READ hierarchical WRITE setHierarchical NOTIFY hierarchicalChanged)
47 Q_PROPERTY(Status status READ status NOTIFY statusChanged)
48
49 Q_INTERFACES(QQmlParserStatus)
50
51public:
52 explicit QDeclarativeSupportedCategoriesModel(QObject *parent = nullptr);
53 virtual ~QDeclarativeSupportedCategoriesModel();
54
55 // From QQmlParserStatus
56 void classBegin() override {}
57 void componentComplete() override;
58
59 // From QAbstractItemModel
60 int rowCount(const QModelIndex &parent) const override;
61 int columnCount(const QModelIndex &parent) const override;
62
63 QModelIndex index(int row, int column, const QModelIndex &parent) const override;
64 QModelIndex parent(const QModelIndex &child) const override;
65
66 Q_INVOKABLE QVariant data(const QModelIndex &index, int role) const override;
67 QHash<int, QByteArray> roleNames() const override;
68
69 enum Roles {
70 CategoryRole = Qt::UserRole,
71 ParentCategoryRole
72 }; //for internal usage only
73 Q_ENUM(Roles)
74
75 enum Status {Null, Ready, Loading, Error};
76 Q_ENUM(Status)
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
89 using QAbstractItemModel::dataChanged;
90Q_SIGNALS:
91 void pluginChanged();
92 void hierarchicalChanged();
93 void statusChanged();
94 void dataChanged();
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;
111 QSharedPointer<QDeclarativeCategory> declCategory;
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
128 QHash<QString, PlaceCategoryNode *> m_categoriesTree;
129};
130
131QT_END_NAMESPACE
132
134
135#endif // QDECLARATIVESUPPORTEDCATEGORIESMODEL_H
Combined button and popup list for selecting options.