qHexWalker 0.0.1
Hexagonal Grid Pathfinding & Maze Visualization on Interactive Maps
Loading...
Searching...
No Matches
H3Model Class Referencefinal

Qt model for H3 hexagonal cell visualization and management. More...

#include <h3Model.h>

+ Inheritance diagram for H3Model:
+ Collaboration diagram for H3Model:

Public Types

enum  Roles { ResRole = Qt::UserRole + 1 , IndexRole , CellColor , PathRole }
 Cell polygon coordinates for QML map display. More...
 

Public Member Functions

 H3Model (QObject *parent=nullptr)
 Constructs an H3Model.
 
 ~H3Model () override
 Destructor.
 
int rowCount (const QModelIndex &parent) const override
 Returns the number of cells in the model.
 
QVariant data (const QModelIndex &index, int role) const override
 Returns data for a cell at the given index.
 
QHash< int, QByteArray > roleNames () const override
 Returns the role names for QML access.
 
QVariantList coordinates () const noexcept
 Gets cell coordinates for map display.
 
QList< QVariantList > mazePolygons () const noexcept
 Gets maze wall polygons.
 
QString searchStatsText () const noexcept
 Gets search statistics as formatted text.
 
QGeoCoordinate mazeCenter () const noexcept
 Gets the geographic center of the maze.
 
double mazeRadius () const noexcept
 Gets the maze boundary radius.
 
void Init ()
 Initializes the model and starts worker thread.
 
void requestCells (const std::vector< H3Index > &indexes)
 Requests visualization of specific cells.
 
void clearAllCells ()
 Clears all cells from the model.
 
void clearingFinished ()
 Emitted when cell clearing completes.
 
void coordinatesChanged ()
 Emitted when coordinates property changes.
 
void mazePolygonsChanged ()
 Emitted when maze polygons change.
 
void searchStatsChanged ()
 Emitted when search statistics update.
 
void mazeWallsGenerated (const std::unordered_set< H3Index > &walls)
 Emitted when maze walls are generated.
 
void mazeCenterChanged ()
 Emitted when maze center changes.
 
void mazeRadiusChanged ()
 Emitted when maze radius changes.
 
void mazeBoundsGenerated (const QGeoCoordinate &center, double radiusMeters)
 Emitted with maze boundary information.
 

Public Attributes

 : void clearingStarted()
 

Private Member Functions

void onCellsComputed (const QVariantList &list)
 Handles batch cell computation results.
 
void onCellComputed (quint8 res, H3Index index, const QVariantList &polygon, bool isSearching)
 Handles individual cell computation during search.
 
void onPathCellsBatch (const std::vector< std::tuple< quint8, H3Index, QVariantList > > &cells)
 Handles batch cell computation for path visualization (optimized).
 
void onMazePolygonsComputed (const std::vector< QVariantList > &polygons)
 Handles maze polygon computation results.
 
void onSearchStats (int exploredCells, double timeMs, int pathLength)
 Handles search statistics update.
 
std::optional< H3Cell * > findCellByID (quint64 id) const
 Finds a cell by its H3 index.
 
std::optional< H3Cell * > findCellByRes (quint8 res) const
 Finds a cell by its resolution.
 
bool isCoordinateTargetValid (quint8 zoom, const QGeoCoordinate &coordinate) const
 Validates if a coordinate is a valid target.
 
QString getColorForResolution (quint8 resolution) const
 Gets the display color for a resolution level.
 
void addCell (quint8 res, H3Index index, const QVariantList &polygon, const QColor &color)
 Adds a new cell to the model.
 
void addPentagons ()
 Adds pentagon cells to the model.
 

Private Attributes

H3_VIEWER::H3Workerworker_ {}
 Worker for async operations.
 
QThread * thread_ {}
 Worker thread.
 
H3MazeAdaptermazeAdapter_ {}
 Maze generation adapter.
 
QList< H3Cell * > pathCells_
 Cells that are part of the current path.
 
QVariantList coordinates_
 Cell coordinates for display.
 
QList< QVariantList > mazePolygons_
 Maze wall polygons.
 
QString searchStatsText_
 Formatted search statistics.
 
QGeoCoordinate mazeCenter_
 Maze center coordinate.
 
double mazeRadius_ {0.0}
 Maze boundary radius in meters.
 
const uint8_t minZoom_c {3}
 Minimum supported zoom level.
 
const uint8_t maxZoom_c {15}
 Maximum supported zoom level.
 
std::unordered_map< uint8_t, uint8_t > zoomToRes_
 Zoom to resolution mapping.
 
const QHash< int, QString > resolutionColors_c
 Color palette for different resolutions.
 
std::atomic_bool isClearing_ {false}
 Flag indicating clearing in progress.
 

Detailed Description

Qt model for H3 hexagonal cell visualization and management.

H3Model serves as the central data model connecting the QML UI with the pathfinding algorithms and maze generation. It manages:

  • Hexagonal cell display data
  • Path visualization
  • Maze polygons for rendering
  • Search statistics
QML Properties
  • coordinates: List of cell coordinates for map display
  • mazePolygons: List of polygon coordinates for maze walls
  • searchStatsText: Human-readable search statistics
  • mazeCenter: Geographic center of the maze
  • mazeRadius: Radius of the maze boundary in meters
Example QML Usage
MapPolygon {
path: h3Model.coordinates
color: "blue"
}
Text {
text: h3Model.searchStatsText
}
See also
H3Cell for individual cell data
H3Worker for async pathfinding
H3MazeAdapter for maze generation

Definition at line 58 of file h3Model.h.

Member Enumeration Documentation

◆ Roles

Cell polygon coordinates for QML map display.

Maze wall polygons for QML rendering.

Human-readable search statistics text.

Geographic center of the generated maze.

Maze boundary radius in meters.

Custom roles for the list model.

Enumerator
ResRole 

Cell resolution (3-15).

IndexRole 

H3 cell index.

CellColor 

Cell display color.

PathRole 

Whether cell is part of path.

Definition at line 82 of file h3Model.h.

Constructor & Destructor Documentation

◆ H3Model()

H3Model::H3Model ( QObject *  parent = nullptr)
explicit

Constructs an H3Model.

Parameters
parentOptional parent QObject.

Definition at line 11 of file h3Model.cpp.

References maxZoom_c, minZoom_c, and zoomToRes_.

◆ ~H3Model()

H3Model::~H3Model ( )
override

Destructor.

Definition at line 20 of file h3Model.cpp.

References pathCells_, thread_, and worker_.

Member Function Documentation

◆ addCell()

void H3Model::addCell ( quint8  res,
H3Index  index,
const QVariantList &  polygon,
const QColor &  color 
)
private

Adds a new cell to the model.

Parameters
resCell resolution.
indexH3 cell index.
polygonCell polygon coordinates.
colorCell display color.

Definition at line 158 of file h3Model.cpp.

References findCellByID(), isClearing_, and pathCells_.

Referenced by onCellComputed().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addPentagons()

void H3Model::addPentagons ( )
private

Adds pentagon cells to the model.

Definition at line 178 of file h3Model.cpp.

References H3_VIEWER::Helper::indexToPolygon(), and onCellComputed().

+ Here is the call graph for this function:

◆ clearAllCells()

void H3Model::clearAllCells ( )

Clears all cells from the model.

Definition at line 271 of file h3Model.cpp.

References clearingFinished(), isClearing_, and pathCells_.

Referenced by requestCells().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clearingFinished()

void H3Model::clearingFinished ( )

Emitted when cell clearing completes.

Referenced by clearAllCells().

+ Here is the caller graph for this function:

◆ coordinates()

QVariantList H3Model::coordinates ( ) const
inlinenoexcept

Gets cell coordinates for map display.

Returns
List of coordinate pairs.

Definition at line 125 of file h3Model.h.

References coordinates_.

◆ coordinatesChanged()

void H3Model::coordinatesChanged ( )

Emitted when coordinates property changes.

Referenced by onCellsComputed().

+ Here is the caller graph for this function:

◆ data()

QVariant H3Model::data ( const QModelIndex &  index,
int  role 
) const
override

Returns data for a cell at the given index.

Parameters
indexModel index.
roleData role to retrieve.
Returns
Cell data as QVariant.

Definition at line 36 of file h3Model.cpp.

References CellColor, data(), IndexRole, pathCells_, PathRole, and ResRole.

Referenced by data().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ findCellByID()

std::optional< H3Cell * > H3Model::findCellByID ( quint64  id) const
private

Finds a cell by its H3 index.

Parameters
idH3 cell index.
Returns
Cell pointer if found, nullopt otherwise.

Definition at line 146 of file h3Model.cpp.

References pathCells_.

Referenced by addCell(), and onPathCellsBatch().

+ Here is the caller graph for this function:

◆ findCellByRes()

std::optional< H3Cell * > H3Model::findCellByRes ( quint8  res) const
private

Finds a cell by its resolution.

Parameters
resCell resolution.
Returns
Cell pointer if found, nullopt otherwise.

Definition at line 138 of file h3Model.cpp.

References pathCells_.

◆ getColorForResolution()

QString H3Model::getColorForResolution ( quint8  resolution) const
private

Gets the display color for a resolution level.

Parameters
resolutionCell resolution (3-15).
Returns
Color name string.

Definition at line 154 of file h3Model.cpp.

References resolutionColors_c.

Referenced by onCellComputed(), and onPathCellsBatch().

+ Here is the caller graph for this function:

◆ Init()

void H3Model::Init ( )

Initializes the model and starts worker thread.

Must be called after construction to set up the worker thread and maze adapter.

Definition at line 64 of file h3Model.cpp.

References H3_VIEWER::H3Worker::cellComputed(), H3_VIEWER::H3Worker::cellsComputed(), H3_VIEWER::H3Worker::doWork(), H3MazeAdapter::generateMazeAsync(), mazeAdapter_, mazeBoundsGenerated(), mazeCenter_, mazeCenterChanged(), H3_VIEWER::H3Worker::mazePolygonsComputed(), mazeRadius_, mazeRadiusChanged(), H3MazeAdapter::mazeRadiusComputed(), H3MazeAdapter::mazeWallsGenerated(), mazeWallsGenerated(), onCellComputed(), onCellsComputed(), onMazePolygonsComputed(), onSearchStats(), H3_VIEWER::H3Worker::searchStats(), H3_VIEWER::H3Worker::setWalls(), thread_, and worker_.

Referenced by EntryPoint::InitDataModels().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isCoordinateTargetValid()

bool H3Model::isCoordinateTargetValid ( quint8  zoom,
const QGeoCoordinate &  coordinate 
) const
private

Validates if a coordinate is a valid target.

Parameters
zoomCurrent zoom level.
coordinateTarget coordinate.
Returns
true if the coordinate is valid.

Definition at line 127 of file h3Model.cpp.

References maxZoom_c.

◆ mazeBoundsGenerated()

void H3Model::mazeBoundsGenerated ( const QGeoCoordinate &  center,
double  radiusMeters 
)

Emitted with maze boundary information.

Referenced by Init(), and EntryPoint::InitDataModels().

+ Here is the caller graph for this function:

◆ mazeCenter()

QGeoCoordinate H3Model::mazeCenter ( ) const
inlinenoexcept

Gets the geographic center of the maze.

Returns
Maze center coordinate.

Definition at line 143 of file h3Model.h.

References mazeCenter_.

◆ mazeCenterChanged()

void H3Model::mazeCenterChanged ( )

Emitted when maze center changes.

Referenced by Init().

+ Here is the caller graph for this function:

◆ mazePolygons()

QList< QVariantList > H3Model::mazePolygons ( ) const
inlinenoexcept

Gets maze wall polygons.

Returns
List of polygon coordinate lists.

Definition at line 131 of file h3Model.h.

References mazePolygons_.

◆ mazePolygonsChanged()

void H3Model::mazePolygonsChanged ( )

Emitted when maze polygons change.

Referenced by onMazePolygonsComputed().

+ Here is the caller graph for this function:

◆ mazeRadius()

double H3Model::mazeRadius ( ) const
inlinenoexcept

Gets the maze boundary radius.

Returns
Radius in meters.

Definition at line 149 of file h3Model.h.

References mazeRadius_.

◆ mazeRadiusChanged()

void H3Model::mazeRadiusChanged ( )

Emitted when maze radius changes.

Referenced by Init().

+ Here is the caller graph for this function:

◆ mazeWallsGenerated()

void H3Model::mazeWallsGenerated ( const std::unordered_set< H3Index > &  walls)

Emitted when maze walls are generated.

Referenced by Init(), and EntryPoint::InitDataModels().

+ Here is the caller graph for this function:

◆ onCellComputed()

void H3Model::onCellComputed ( quint8  res,
H3Index  index,
const QVariantList &  polygon,
bool  isSearching 
)
private

Handles individual cell computation during search.

Parameters
resCell resolution.
indexH3 cell index.
polygonCell polygon coordinates.
isSearchingWhether this is during active search.

Definition at line 200 of file h3Model.cpp.

References addCell(), getColorForResolution(), and isClearing_.

Referenced by addPentagons(), and Init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ onCellsComputed()

void H3Model::onCellsComputed ( const QVariantList &  list)
private

Handles batch cell computation results.

Parameters
listList of computed cell data.

Definition at line 195 of file h3Model.cpp.

References coordinates_, and coordinatesChanged().

Referenced by Init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ onMazePolygonsComputed()

void H3Model::onMazePolygonsComputed ( const std::vector< QVariantList > &  polygons)
private

Handles maze polygon computation results.

Parameters
polygonsVector of polygon coordinate lists.

Definition at line 295 of file h3Model.cpp.

References isClearing_, mazePolygons_, and mazePolygonsChanged().

Referenced by Init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ onPathCellsBatch()

void H3Model::onPathCellsBatch ( const std::vector< std::tuple< quint8, H3Index, QVariantList > > &  cells)
private

Handles batch cell computation for path visualization (optimized).

Parameters
cellsVector of cell data tuples (res, index, polygon).

Definition at line 215 of file h3Model.cpp.

References findCellByID(), getColorForResolution(), isClearing_, and pathCells_.

+ Here is the call graph for this function:

◆ onSearchStats()

void H3Model::onSearchStats ( int  exploredCells,
double  timeMs,
int  pathLength 
)
private

Handles search statistics update.

Parameters
exploredCellsNumber of cells explored.
timeMsSearch time in milliseconds.
pathLengthLength of found path.

Definition at line 311 of file h3Model.cpp.

References searchStatsChanged(), and searchStatsText_.

Referenced by Init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ requestCells()

void H3Model::requestCells ( const std::vector< H3Index > &  indexes)

Requests visualization of specific cells.

Parameters
indexesVector of H3 cell indices to display.

Definition at line 255 of file h3Model.cpp.

References clearAllCells(), isClearing_, pathCells_, H3_VIEWER::H3Worker::requestCell(), and worker_.

Referenced by EntryPoint::InitDataModels().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ roleNames()

QHash< int, QByteArray > H3Model::roleNames ( ) const
override

Returns the role names for QML access.

Returns
Hash mapping role IDs to role names.

Definition at line 56 of file h3Model.cpp.

References CellColor, IndexRole, PathRole, and ResRole.

◆ rowCount()

int H3Model::rowCount ( const QModelIndex &  parent) const
override

Returns the number of cells in the model.

Parameters
parentParent index (unused for list models).
Returns
Number of cells.

Definition at line 31 of file h3Model.cpp.

References pathCells_.

◆ searchStatsChanged()

void H3Model::searchStatsChanged ( )

Emitted when search statistics update.

Referenced by onSearchStats().

+ Here is the caller graph for this function:

◆ searchStatsText()

QString H3Model::searchStatsText ( ) const
inlinenoexcept

Gets search statistics as formatted text.

Returns
Statistics string (e.g., "Cells: 847 | Time: 23ms | Path: 156").

Definition at line 137 of file h3Model.h.

References searchStatsText_.

Member Data Documentation

◆ __pad0__

H3Model::__pad0__

Definition at line 206 of file h3Model.h.

◆ coordinates_

QVariantList H3Model::coordinates_
private

Cell coordinates for display.

Definition at line 285 of file h3Model.h.

Referenced by coordinates(), and onCellsComputed().

◆ isClearing_

std::atomic_bool H3Model::isClearing_ {false}
private

Flag indicating clearing in progress.

Definition at line 301 of file h3Model.h.

Referenced by addCell(), clearAllCells(), onCellComputed(), onMazePolygonsComputed(), onPathCellsBatch(), and requestCells().

◆ maxZoom_c

const uint8_t H3Model::maxZoom_c {15}
private

Maximum supported zoom level.

Definition at line 292 of file h3Model.h.

Referenced by H3Model(), and isCoordinateTargetValid().

◆ mazeAdapter_

H3MazeAdapter* H3Model::mazeAdapter_ {}
private

Maze generation adapter.

Definition at line 282 of file h3Model.h.

Referenced by Init().

◆ mazeCenter_

QGeoCoordinate H3Model::mazeCenter_
private

Maze center coordinate.

Definition at line 288 of file h3Model.h.

Referenced by Init(), and mazeCenter().

◆ mazePolygons_

QList<QVariantList> H3Model::mazePolygons_
private

Maze wall polygons.

Definition at line 286 of file h3Model.h.

Referenced by mazePolygons(), and onMazePolygonsComputed().

◆ mazeRadius_

double H3Model::mazeRadius_ {0.0}
private

Maze boundary radius in meters.

Definition at line 289 of file h3Model.h.

Referenced by Init(), and mazeRadius().

◆ minZoom_c

const uint8_t H3Model::minZoom_c {3}
private

Minimum supported zoom level.

Definition at line 291 of file h3Model.h.

Referenced by H3Model().

◆ pathCells_

QList<H3Cell *> H3Model::pathCells_
private

Cells that are part of the current path.

Definition at line 284 of file h3Model.h.

Referenced by ~H3Model(), addCell(), clearAllCells(), data(), findCellByID(), findCellByRes(), onPathCellsBatch(), requestCells(), and rowCount().

◆ resolutionColors_c

const QHash<int, QString> H3Model::resolutionColors_c
private
Initial value:
= {
{3, "limegreen"}, {4, "green"}, {5, "darkGreen"}, {6, "gold"}, {7, "yellow"},
{8, "greenyellow"}, {9, "limegreen"}, {10, "mediumseagreen"}, {11, "turquoise"}, {12, "deepskyblue"},
{13, "dodgerblue"}, {14, "mediumblue"}, {15, "darkviolet"}}

Color palette for different resolutions.

Definition at line 296 of file h3Model.h.

Referenced by getColorForResolution().

◆ searchStatsText_

QString H3Model::searchStatsText_
private

Formatted search statistics.

Definition at line 287 of file h3Model.h.

Referenced by onSearchStats(), and searchStatsText().

◆ thread_

QThread* H3Model::thread_ {}
private

Worker thread.

Definition at line 281 of file h3Model.h.

Referenced by ~H3Model(), and Init().

◆ worker_

H3_VIEWER::H3Worker* H3Model::worker_ {}
private

Worker for async operations.

Definition at line 280 of file h3Model.h.

Referenced by ~H3Model(), Init(), and requestCells().

◆ zoomToRes_

std::unordered_map<uint8_t, uint8_t> H3Model::zoomToRes_
private

Zoom to resolution mapping.

Definition at line 293 of file h3Model.h.

Referenced by H3Model().


The documentation for this class was generated from the following files: