How merginmaps/mobile works
Purpose and Entry Points
Mergin Maps Mobile is a cross-platform field-survey GIS client. It opens QGIS-designed projects, renders/edit geospatial layers and forms, captures position/media, and synchronizes project data with Mergin Maps services. The primary executable starts in app/main.cpp; QML UI composition begins at app/qml/main.qml. Build targets are organized by CMakeLists.txt, app/CMakeLists.txt, and core/CMakeLists.txt.
Runtime Architecture
The native application is C++ on Qt/Qt Quick, using QGIS core libraries for projects, layers, map rendering, forms, geometry, and GIS data formats. QML provides the touch UI; C++ exposes stateful controllers and QAbstractItemModel-style models to it. Dependency and platform packaging are CMake/vcpkg based, including customized QGIS, Qt Positioning, Spatialite, and GeoDiff ports under vcpkg/ports/qgis, vcpkg/ports/qtpositioning, and vcpkg/ports/geodiff.
Project Lifecycle and Cloud Sync
core/project.cpp represents project-level state; core/localprojectsmanager.cpp manages local project discovery/storage. app/activeproject.cpp bridges the selected project into application/UI state. Network-facing Mergin Maps integration is centralized in core/merginapi.cpp, authentication in core/merginuserauth.cpp, and synchronization orchestration in app/synchronizationmanager.cpp. The control path is project selection/download → local QGIS project load/edit → status/change detection → upload/download/reconciliation with the Mergin Maps server. Credential persistence is bounded behind core/credentialstore.h with keychain and plaintext implementations.
Map, Layers, and Editing
The map runtime adapts QGIS rendering and coordinate state through app/map/inputmapcanvasmap.cpp, app/map/inputmapsettings.cpp, and app/map/inputmaptransform.cpp, surfaced by app/qml/map/MMMapCanvas.qml. Layer-tree and feature-list models translate QGIS layer state for QML in app/layer/layertreemodel.cpp, app/layersmodel.cpp, and app/layerfeaturesmodel.cpp. Interactive capture/editing is implemented as map-tool controllers, notably app/maptools/recordingmaptool.cpp, app/maptools/splittingmaptool.cpp, and app/mapsketchingcontroller.cpp.
Forms, Attributes, and Feature Queries
Feature form presentation is driven by app/attributes/attributecontroller.cpp, app/attributes/attributeformmodel.cpp, and app/qml/form/MMFormPage.qml. This boundary maps QGIS field/widget definitions and feature values to QML editors, validates changes, and commits them back to editable layers. Related/value-reference features have dedicated models (app/relationfeaturesmodel.cpp, app/valuerelationfeaturesmodel.cpp); filtering is separated into app/filter/filtercontroller.cpp and supporting filter models.
Positioning and Device Integration
app/position/positionkit.cpp coordinates position data consumed by map and survey flows. Providers abstract internal GPS, Android, Bluetooth/NMEA, network, and simulated sources via app/position/providers/abstractpositionprovider.cpp, app/position/providers/bluetoothpositionprovider.cpp, and app/position/providers/nmeaparser.cpp. Recording/tracking is a separate backend layer in app/position/tracking/positiontrackingmanager.cpp, with Android/iOS implementations. Native boundaries include Android Java services in app/android/src/uk/co/lutraconsulting/PositionTrackingService.java and Objective-C++ iOS integration in app/ios/iosinterface.mm.
Delivery and UI Development
Android, iOS, Linux, macOS, and Windows builds are automated under .github/workflows/android.yml, .github/workflows/ios.yml, and .github/workflows/win.yml; mobile-store delivery uses Fastlane (fastlane/Fastfile). Resources and translations are compiled into Qt resources, including app/i18n/input_i18n.qrc. The separate Gallery executable (gallery/main.cpp, gallery/qml/Main.qml) is a component-development sandbox for shared QML UI, not the production survey runtime.
Main entry points: main.qml QML application shell · positionkit.cpp Position kit · MMMapCanvas.qml Map canvas · main.cpp Native entry point
Components 23
Mobile application
- Native entry point
app/main.cpp - QML application shell
app/qml/main.qml - Active project bridge · Exposes the selected project to application and QML state.
app/activeproject.cpp
Projects and sync
- Local project manager
core/localprojectsmanager.cpp - Project state
core/project.cpp - Mergin API client
core/merginapi.cpp - User authentication
core/merginuserauth.cpp - Credential store · Bounds keychain and plaintext credential implementations.
core/credentialstore.h - Synchronization manager · Reconciles local project changes with Mergin Maps services.
app/synchronizationmanager.cpp
GIS interaction
- QGIS runtime · Provides projects, layers, rendering, forms, and geometry.
- Map canvas
app/qml/map/MMMapCanvas.qml - Map rendering adapter · Adapts QGIS rendering and coordinate state for QML.
app/map/inputmapcanvasmap.cpp - Layer and feature models · Translates QGIS layer trees and feature lists for QML.
app/layer/layertreemodel.cpp - Capture and editing tools · Supports recording, splitting, and sketching edits.
app/maptools/recordingmaptool.cpp - Feature form UI
app/qml/form/MMFormPage.qml - Attribute form controller · Maps QGIS fields and feature values to editors and commits changes.
app/attributes/attributecontroller.cpp
Position and device
- Position kit
app/position/positionkit.cpp - Position providers · Supports internal GPS, Bluetooth/NMEA, network, and simulation sources.
app/position/providers/abstractpositionprovider.cpp - Position tracking · Uses Android and iOS platform implementations.
app/position/tracking/positiontrackingmanager.cpp - Native platform services
app/android/src/uk/co/lutraconsulting/PositionTrackingService.java
Build and delivery
- CMake build targets · Builds native app, core library, and dependencies.
CMakeLists.txt - CI and store delivery · Builds platform packages and drives mobile-store delivery.
.github/workflows/android.yml - QML Gallery · Separate executable for shared QML component development.
gallery/main.cpp
Connections 27
- Native entry point → QML application shell: starts
- Native entry point → Active project bridge: initializes
- QML application shell → Active project bridge: binds state
- Active project bridge → Project state: selects and loads
- Local project manager → Project state: discovers and stores
- Project state → QGIS runtime: uses
- Synchronization manager → Local project manager: downloads and updates
- Synchronization manager → Mergin API client: orchestrates requests
- Mergin API client → User authentication: authenticates with
- User authentication → Credential store: persists credentials
- Map canvas → Map rendering adapter: renders through
- Map rendering adapter → QGIS runtime: adapts rendering
- QML application shell → Map canvas: composes
- Layer and feature models → QGIS runtime: adapts layers and features
- QML application shell → Layer and feature models: displays
- Capture and editing tools → QGIS runtime: edits layers
- Map canvas → Capture and editing tools: routes interaction
- Feature form UI → Attribute form controller: edits through
- Attribute form controller → QGIS runtime: reads and commits features
- QML application shell → Feature form UI: composes
- Position kit → Position providers: consumes fixes
- Position kit → Position tracking: coordinates recording
- Position tracking → Native platform services: uses
- Position kit → Map rendering adapter: supplies position
- CMake build targets → Native entry point: builds
- CI and store delivery → CMake build targets: runs platform builds
- QML Gallery → QML application shell: develops shared UI for