41 QML_NAMED_ELEMENT(CategoryModel)
42 QML_ADDED_IN_VERSION(5, 0)
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)
50 Q_INTERFACES(QQmlParserStatus)
54 explicit QDeclarativeSupportedCategoriesModel(QObject *parent =
nullptr);
55 virtual ~QDeclarativeSupportedCategoriesModel();
58 void classBegin() override {}
59 void componentComplete() override;
62 int rowCount(
const QModelIndex &parent)
const override;
63 int columnCount(
const QModelIndex &parent)
const override;
65 QModelIndex index(
int row,
int column,
const QModelIndex &parent)
const override;
66 QModelIndex parent(
const QModelIndex &child)
const override;
68 Q_INVOKABLE QVariant data(
const QModelIndex &index,
int role)
const override;
69 QHash<
int, QByteArray> roleNames()
const override;
72 CategoryRole = Qt::UserRole,
76 enum Status {Null, Ready, Loading, Error};
78 void setPlugin(QDeclarativeGeoServiceProvider *plugin);
79 QDeclarativeGeoServiceProvider *plugin()
const;
81 void setHierarchical(
bool hierarchical);
82 bool hierarchical()
const;
84 Q_INVOKABLE QString errorString()
const;
86 Status status()
const;
87 void setStatus(Status status,
const QString &errorString = QString());
89 using QAbstractItemModel::dataChanged;
92 void hierarchicalChanged();
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();
107 struct PlaceCategoryNode
110 QStringList childIds;
111 QSharedPointer<QDeclarativeCategory> declCategory;
114 QStringList populateCategories(QPlaceManager *,
const QPlaceCategory &parent);
115 QModelIndex index(
const QString &categoryId)
const;
116 int rowToAddChild(PlaceCategoryNode *,
const QPlaceCategory &category);
118 void emitDataChanged() { Q_EMIT dataChanged(); }
120 QPlaceReply *m_response =
nullptr;
122 QDeclarativeGeoServiceProvider *m_plugin =
nullptr;
123 bool m_hierarchical =
true;
124 bool m_complete =
false;
125 Status m_status = Null;
126 QString m_errorString;
128 QHash<QString, PlaceCategoryNode *> m_categoriesTree;