presentation/MapMarkerModel.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <QAbstractListModel> | ||
| 4 | #include <QVariantList> | ||
| 5 | |||
| 6 | // The map's markers for QML (Sprint 103 F103-14): one row per cluster id. | ||
| 7 | // setMarkers() updates rows in place, removes the clusters that left and | ||
| 8 | // appends the new ones, so a pan or zoom moves the same delegates instead | ||
| 9 | // of rebuilding them (rebuilt avatars reloaded their photos and the | ||
| 10 | // bubbles jumped). Row order carries no meaning: markers are positioned. | ||
| 11 | // F103-23: the map's tile layers use the same model (role "tile"). | ||
| 12 | class MapMarkerModel final : public QAbstractListModel { | ||
| 13 | Q_OBJECT | ||
| 14 | Q_PROPERTY(int count READ rowCount NOTIFY countChanged) | ||
| 15 | |||
| 16 | public: | ||
| 17 | enum Role { MarkerRole = Qt::UserRole + 1 }; | ||
| 18 | // `roleName`: the delegates' required property ("cluster", "tile"). | ||
| 19 | 2436 | MapMarkerModel(QByteArray roleName, QObject *parent) : QAbstractListModel(parent), m_roleName(std::move(roleName)) {} | |
| 20 | |||
| 21 | int rowCount(const QModelIndex &parent = {}) const override; | ||
| 22 | QVariant data(const QModelIndex &index, int role) const override; | ||
| 23 | QHash<int, QByteArray> roleNames() const override; | ||
| 24 | |||
| 25 | // `markers`: the maps of QuickContactMap::markers (each with an "id"). | ||
| 26 | void setMarkers(const QVariantList &markers); | ||
| 27 | |||
| 28 | signals: | ||
| 29 | void countChanged(); | ||
| 30 | |||
| 31 | private: | ||
| 32 | QByteArray m_roleName; | ||
| 33 | QVariantList m_rows; | ||
| 34 | }; | ||
| 35 |