qHexWalker 0.0.1
Hexagonal Grid Pathfinding & Maze Visualization on Interactive Maps
Loading...
Searching...
No Matches
h3Model.h
Go to the documentation of this file.
1
12#ifndef Q_HEX_WALKER_H3MODEL_H
13#define Q_HEX_WALKER_H3MODEL_H
14
15#include <QAbstractListModel>
16
17class H3Cell;
18class H3MazeAdapter;
19
20namespace H3_VIEWER {
21class H3Worker;
22}
23
58class H3Model final : public QAbstractListModel {
59 Q_OBJECT
60 Q_DISABLE_COPY_MOVE(H3Model)
61
62
63 Q_PROPERTY(QVariantList coordinates READ coordinates NOTIFY coordinatesChanged)
64
65
66 Q_PROPERTY(QList<QVariantList> mazePolygons READ mazePolygons NOTIFY mazePolygonsChanged)
67
68
69 Q_PROPERTY(QString searchStatsText READ searchStatsText NOTIFY searchStatsChanged)
70
71
72 Q_PROPERTY(QGeoCoordinate mazeCenter READ mazeCenter NOTIFY mazeCenterChanged)
73
74
75 Q_PROPERTY(double mazeRadius READ mazeRadius NOTIFY mazeRadiusChanged)
76
77public:
82 enum Roles {
83 ResRole = Qt::UserRole + 1,
87 };
88
93 explicit H3Model(QObject *parent = nullptr);
94
98 ~H3Model() override;
99
105 [[nodiscard]] int rowCount(const QModelIndex &parent) const override;
106
113 [[nodiscard]] QVariant data(const QModelIndex &index, int role) const override;
114
119 [[nodiscard]] QHash<int, QByteArray> roleNames() const override;
120
125 [[nodiscard]] QVariantList coordinates() const noexcept { return coordinates_; }
126
131 [[nodiscard]] QList<QVariantList> mazePolygons() const noexcept { return mazePolygons_; }
132
137 [[nodiscard]] QString searchStatsText() const noexcept { return searchStatsText_; }
138
143 [[nodiscard]] QGeoCoordinate mazeCenter() const noexcept { return mazeCenter_; }
144
149 [[nodiscard]] double mazeRadius() const noexcept { return mazeRadius_; }
150
151private slots:
156 void onCellsComputed(const QVariantList &list);
157
165 void onCellComputed(quint8 res, H3Index index, const QVariantList &polygon, bool isSearching);
166
171 void onPathCellsBatch(const std::vector<std::tuple<quint8, H3Index, QVariantList>> &cells);
172
177 void onMazePolygonsComputed(const std::vector<QVariantList> &polygons);
178
185 void onSearchStats(int exploredCells, double timeMs, int pathLength);
186
187public:
194 void Init();
195
196public slots:
201 Q_INVOKABLE void requestCells(const std::vector<H3Index> &indexes);
202
206 Q_INVOKABLE void clearAllCells();
207
208signals:
210 void clearingStarted();
211
214
217
220
223
225 void mazeWallsGenerated(const std::unordered_set<H3Index> &walls);
226
229
232
234 void mazeBoundsGenerated(const QGeoCoordinate &center, double radiusMeters);
235
236private:
242 [[nodiscard]] std::optional<H3Cell *> findCellByID(quint64 id) const;
243
249 [[nodiscard]] std::optional<H3Cell *> findCellByRes(quint8 res) const;
250
257 [[nodiscard]] bool isCoordinateTargetValid(quint8 zoom, const QGeoCoordinate &coordinate) const;
258
264 [[nodiscard]] QString getColorForResolution(quint8 resolution) const;
265
273 void addCell(quint8 res, H3Index index, const QVariantList &polygon, const QColor &color);
274
278 void addPentagons();
279
281 QThread *thread_{};
283
284 QList<H3Cell *> pathCells_;
285 QVariantList coordinates_;
286 QList<QVariantList> mazePolygons_;
288 QGeoCoordinate mazeCenter_;
289 double mazeRadius_{0.0};
290
291 const uint8_t minZoom_c{3};
292 const uint8_t maxZoom_c{15};
293 std::unordered_map<uint8_t, uint8_t> zoomToRes_;
294
296 const QHash<int, QString> resolutionColors_c = {
297 {3, "limegreen"}, {4, "green"}, {5, "darkGreen"}, {6, "gold"}, {7, "yellow"},
298 {8, "greenyellow"}, {9, "limegreen"}, {10, "mediumseagreen"}, {11, "turquoise"}, {12, "deepskyblue"},
299 {13, "dodgerblue"}, {14, "mediumblue"}, {15, "darkviolet"}};
300
301 std::atomic_bool isClearing_{false};
302};
303
304#endif // Q_HEX_WALKER_H3MODEL_H
Definition h3Cell.h:6
Qt model for H3 hexagonal cell visualization and management.
Definition h3Model.h:58
~H3Model() override
Destructor.
Definition h3Model.cpp:20
QHash< int, QByteArray > roleNames() const override
Returns the role names for QML access.
Definition h3Model.cpp:56
void mazeRadiusChanged()
Emitted when maze radius changes.
QString searchStatsText_
Formatted search statistics.
Definition h3Model.h:287
void mazePolygonsChanged()
Emitted when maze polygons change.
void requestCells(const std::vector< H3Index > &indexes)
Requests visualization of specific cells.
Definition h3Model.cpp:255
void mazeWallsGenerated(const std::unordered_set< H3Index > &walls)
Emitted when maze walls are generated.
int rowCount(const QModelIndex &parent) const override
Returns the number of cells in the model.
Definition h3Model.cpp:31
QGeoCoordinate mazeCenter() const noexcept
Gets the geographic center of the maze.
Definition h3Model.h:143
bool isCoordinateTargetValid(quint8 zoom, const QGeoCoordinate &coordinate) const
Validates if a coordinate is a valid target.
Definition h3Model.cpp:127
void coordinatesChanged()
Emitted when coordinates property changes.
QGeoCoordinate mazeCenter_
Maze center coordinate.
Definition h3Model.h:288
void addCell(quint8 res, H3Index index, const QVariantList &polygon, const QColor &color)
Adds a new cell to the model.
Definition h3Model.cpp:158
void clearingFinished()
Emitted when cell clearing completes.
void mazeBoundsGenerated(const QGeoCoordinate &center, double radiusMeters)
Emitted with maze boundary information.
const uint8_t maxZoom_c
Maximum supported zoom level.
Definition h3Model.h:292
void onCellComputed(quint8 res, H3Index index, const QVariantList &polygon, bool isSearching)
Handles individual cell computation during search.
Definition h3Model.cpp:200
std::optional< H3Cell * > findCellByRes(quint8 res) const
Finds a cell by its resolution.
Definition h3Model.cpp:138
double mazeRadius() const noexcept
Gets the maze boundary radius.
Definition h3Model.h:149
void onSearchStats(int exploredCells, double timeMs, int pathLength)
Handles search statistics update.
Definition h3Model.cpp:311
void onMazePolygonsComputed(const std::vector< QVariantList > &polygons)
Handles maze polygon computation results.
Definition h3Model.cpp:295
void Init()
Initializes the model and starts worker thread.
Definition h3Model.cpp:64
QString searchStatsText() const noexcept
Gets search statistics as formatted text.
Definition h3Model.h:137
QString getColorForResolution(quint8 resolution) const
Gets the display color for a resolution level.
Definition h3Model.cpp:154
void onCellsComputed(const QVariantList &list)
Handles batch cell computation results.
Definition h3Model.cpp:195
QVariantList coordinates() const noexcept
Gets cell coordinates for map display.
Definition h3Model.h:125
double mazeRadius_
Maze boundary radius in meters.
Definition h3Model.h:289
Roles
Cell polygon coordinates for QML map display.
Definition h3Model.h:82
@ PathRole
Whether cell is part of path.
Definition h3Model.h:86
@ CellColor
Cell display color.
Definition h3Model.h:85
@ IndexRole
H3 cell index.
Definition h3Model.h:84
@ ResRole
Cell resolution (3-15).
Definition h3Model.h:83
QList< H3Cell * > pathCells_
Cells that are part of the current path.
Definition h3Model.h:284
const uint8_t minZoom_c
Minimum supported zoom level.
Definition h3Model.h:291
QVariantList coordinates_
Cell coordinates for display.
Definition h3Model.h:285
QThread * thread_
Worker thread.
Definition h3Model.h:281
QVariant data(const QModelIndex &index, int role) const override
Returns data for a cell at the given index.
Definition h3Model.cpp:36
H3_VIEWER::H3Worker * worker_
Worker for async operations.
Definition h3Model.h:280
std::optional< H3Cell * > findCellByID(quint64 id) const
Finds a cell by its H3 index.
Definition h3Model.cpp:146
std::atomic_bool isClearing_
Flag indicating clearing in progress.
Definition h3Model.h:301
void clearAllCells()
Clears all cells from the model.
Definition h3Model.cpp:271
std::unordered_map< uint8_t, uint8_t > zoomToRes_
Zoom to resolution mapping.
Definition h3Model.h:293
const QHash< int, QString > resolutionColors_c
Color palette for different resolutions.
Definition h3Model.h:296
void searchStatsChanged()
Emitted when search statistics update.
QList< QVariantList > mazePolygons() const noexcept
Gets maze wall polygons.
Definition h3Model.h:131
H3MazeAdapter * mazeAdapter_
Maze generation adapter.
Definition h3Model.h:282
void addPentagons()
Adds pentagon cells to the model.
Definition h3Model.cpp:178
void onPathCellsBatch(const std::vector< std::tuple< quint8, H3Index, QVariantList > > &cells)
Handles batch cell computation for path visualization (optimized).
Definition h3Model.cpp:215
QList< QVariantList > mazePolygons_
Maze wall polygons.
Definition h3Model.h:286
void mazeCenterChanged()
Emitted when maze center changes.
Worker thread for asynchronous H3 operations.
Definition h3Worker.h:54
Namespace containing H3 visualization components.
Definition h3Model.h:20