41 QML_NAMED_ELEMENT(CategoryModel)
42 QML_ADDED_IN_VERSION(5, 0)
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)
48 Q_INTERFACES(QQmlParserStatus)
51 explicit QDeclarativeSupportedCategoriesModel(QObject *parent =
nullptr);
52 virtual ~QDeclarativeSupportedCategoriesModel();
55 void classBegin() override {}
56 void componentComplete() override;
59 int rowCount(
const QModelIndex &parent)
const override;
60 int columnCount(
const QModelIndex &parent)
const override;
62 QModelIndex index(
int row,
int column,
const QModelIndex &parent)
const override;
63 QModelIndex parent(
const QModelIndex &child)
const override;
65 Q_INVOKABLE QVariant data(
const QModelIndex &index,
int role)
const override;
66 QHash<
int, QByteArray> roleNames()
const override;
69 CategoryRole = Qt::UserRole,
74 enum Status {Null, Ready, Loading, Error};
77 void setPlugin(QDeclarativeGeoServiceProvider *plugin);
78 QDeclarativeGeoServiceProvider *plugin()
const;
80 void setHierarchical(
bool hierarchical);
81 bool hierarchical()
const;
83 Q_INVOKABLE QString errorString()
const;
85 Status status()
const;
86 void setStatus(Status status,
const QString &errorString = QString());
88 using QAbstractItemModel::dataChanged;
91 void hierarchicalChanged();
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();
106 struct PlaceCategoryNode
109 QStringList childIds;
110 QSharedPointer<QDeclarativeCategory> declCategory;
113 QStringList populateCategories(QPlaceManager *,
const QPlaceCategory &parent);
114 QModelIndex index(
const QString &categoryId)
const;
115 int rowToAddChild(PlaceCategoryNode *,
const QPlaceCategory &category);
117 void emitDataChanged() { Q_EMIT dataChanged(); }
119 QPlaceReply *m_response =
nullptr;
121 QDeclarativeGeoServiceProvider *m_plugin =
nullptr;
122 bool m_hierarchical =
true;
123 bool m_complete =
false;
124 Status m_status = Null;
125 QString m_errorString;
127 QHash<QString, PlaceCategoryNode *> m_categoriesTree;