Skip to content

Feature/feature drafts - #4652

Open
xkello wants to merge 11 commits into
masterfrom
feature/feature-drafts
Open

xkello wants to merge 11 commits into
masterfrom
feature/feature-drafts

Conversation

@xkello

@xkello xkello commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Description

Adds automatic recovery of in progress feature edits. If the app closes unexpectedly while you're editing a feature (a crash, an incoming call, a dead battery), your unsaved geometry and attribute changes are no longer lost. On the next launch you can resume exactly where you left off, or discard the changes.

Fixes: #4585

What changed

  • New FeatureDraftUtils (storage) and FeatureDraftController (app/drafts/) persist an in progress edit (geometry and attributes) as JSON in QSettings, one draft per project. Writes are debounced by about 1s, so they don't happen on every keystroke or vertex.
  • AttributeController and RecordingMapTool write the draft when attributes or geometry change, and clear it once the feature is saved, deleted, or the edit is cancelled.
  • A draft records the stage it was interrupted at: recording a new geometry, editing in the form, or editing geometry from an open form.
  • Before a draft is offered it's validated: not older than 10 days, the layer still exists, its fields and their types still match, and for existing features the feature still exists.
  • Drafts are checked when a project is opened and again after a sync, so a draft invalidated by sync (e.g. the feature was deleted on another device) is dropped instead of offered.
  • A new notification, plus resume and discard drawers, let the user act on a pending draft.
  • New banners on the Layers list and Features list screens show a draft on the affected layer, reusing the existing "active filters" banner styling.
  • ActiveProject exposes the draft controller to QML.

Behaviour

  • Editing a feature's attributes or geometry saves a draft in the background about a second after the last change.
  • If the app is reopened with a pending draft, a notification appears: "You have unsaved changes. Tap here to open them."
  • Tapping it, or starting a new "Add" or "Edit" while a draft exists, opens a drawer offering to Resume or Discard.
  • Resuming puts you back where you left off: in geometry capture, on the form with your attributes, or in geometry editing with the form (and its values) waiting behind it.
  • Saving, deleting or cancelling an edit clears its draft. An invalid draft (layer removed, field removed or type changed, feature deleted, older than 10 days) is discarded without being offered, and this is logged.

Videos:

Test crash in geometry, notification resume:

ScreenRecording_12-03-2026.18-49-59_1.MP4

Test crash in geometry, layers banner resume:

ScreenRecording_12-03-2026.18-50-26_1.MP4

Test crash in geometry, previous edits also in form, notification resume:

ScreenRecording_12-03-2026.18-51-25_1.MP4

Test crash in form, previous edits also in geometry, notification resume:

ScreenRecording_12-03-2026.18-52-21_1.MP4

Test relations, notification resume:
https://github.com/user-attachments/assets/92c69cfa-e3ec-4d6b-933d-f67f91e973b7

Known limitations (v2)

  • Invalid drafts are discarded silently, the user isn't told why. This is only logged for now.
  • Widget changes (e.g. text edit to checkbox) don't invalidate a draft, only removed fields and changed column types do.

@xkello
xkello requested a review from Withalion August 18, 2026 06:34
@github-actions

github-actions Bot commented Aug 18, 2026 •

Copy link
Copy Markdown

Coverage Report for CI Build 47170076133

Coverage increased (+0.09%) to 60.776%

Details

  • Coverage increased (+0.09%) from the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • 630 coverage regressions across 9 files.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

630 previously-covered lines in 9 files lost coverage.

File Lines Losing Coverage Coverage
mm/app/maptools/recordingmaptool.cpp 231 68.46%
mm/app/attributes/attributecontroller.cpp 209 76.42%
mm/app/main.cpp 88 36.11%
mm/app/activeproject.cpp 67 70.35%
mm/app/notificationmodel.cpp 21 48.45%
mm/core/merginapi.cpp 7 75.16%
mm/app/maptools/recordingmaptool.h 3 50.0%
mm/app/notificationmodel.h 3 50.0%
mm/app/position/providers/simulatedpositionprovider.cpp 1 91.67%

Coverage Stats

Coverage Status
Relevant Lines: 16337
Covered Lines: 9929
Line Coverage: 60.78%
Coverage Strength: 103.47 hits per line

💛 - Coveralls

@github-actions

Copy link
Copy Markdown

📦 Build Artifacts Ready

OS Status Build Info Workflow run
macOS Build ❌ Build failed or not found. #7166
linux Build 📬 Mergin Maps 71921 x86_64 Expires: 16/11/2026 #7192
win64 Build 📬 Mergin Maps 63681 win64 Expires: 16/11/2026 #6368
Android Build 📬 Mergin Maps 847751 APK [arm64-v8a] Expires: 16/11/2026 #8477
📬 Mergin Maps 847751 APK [arm64-v8a] Google Play Store #8477
Android Build 📬 Mergin Maps 847711 APK [armeabi-v7a] Expires: 16/11/2026 #8477
📬 Mergin Maps 847711 APK [armeabi-v7a] Google Play Store #8477
iOS Build 📬 Build number: 26.08.941811 #9418

@Withalion Withalion left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job, it looks very promising! There are some trivial things, a bit more refactoring is needed, but mainly unit tests.

UI/UX

  • It would be nice to navigate to the geometry you will be recording further after you open the draft
  • After user is done recording geometry and doesn't fill out anything in the form yet, application crashes. We should open the form right away and not the geometry recording
  • When a draft is available and an existing feature is clicked to edit the warning drawer opens and closes right away
  • When a draft is available and "add" button is clicked, the drawer opens correctly, but discarding draft doesn't start recording mode, but stays in "view" mode of map

Comment thread app/notificationmodel.h Resolved
Comment thread app/qml/dialogs/MMResumeDraftDialog.qml Resolved
Comment thread app/drafts/featuredraftcontroller.cpp Resolved
Comment thread app/drafts/featuredraftstorage.h Resolved
Comment thread app/drafts/featuredraftstorage.cpp Resolved
Comment thread app/drafts/featuredraftstorage.cpp Resolved
Comment thread app/drafts/featuredraftutils.h Resolved

@Withalion Withalion left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job, it looks very promising! There are some trivial things, a bit more refactoring is needed, but mainly unit tests.

UI/UX

  • It would be nice to navigate to the geometry you will be recording further after you open the draft
  • After user is done recording geometry and doesn't fill out anything in the form yet, application crashes. We should open the form right away and not the geometry recording
  • When a draft is available and an existing feature is clicked to edit the warning drawer opens and closes right away
  • When a draft is available and "add" button is clicked, the drawer opens correctly, but discarding draft doesn't start recording mode, but stays in "view" mode of map

@xkello
xkello force-pushed the feature/feature-drafts branch from b242e2a to d02dcfb Compare September 23, 2026 16:00
@xkello
xkello requested a review from Withalion September 23, 2026 16:05
@github-actions

Copy link
Copy Markdown

📦 Build Artifacts Ready

OS Status Build Info Workflow run
macOS Build 📬 Mergin Maps 73291 dmg Expires: 22/12/2026 #7329
linux Build 📬 Mergin Maps 73551 x86_64 Expires: 22/12/2026 #7355
win64 Build 📬 Mergin Maps 65311 win64 Expires: 22/12/2026 #6531
Android Build 📬 Mergin Maps 864151 APK [arm64-v8a] Expires: 22/12/2026 #8641
📬 QR code Google Play Store #8641
Android Build 📬 Mergin Maps 864111 APK [armeabi-v7a] Expires: 22/12/2026 #8641
📬 QR code Google Play Store #8641
iOS Build 📬 Build number: 26.09.958111 #9581

@tomasMizera tomasMizera left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! :)

When testing, let's try it out on some low-end devices to see if the 1 second interval is not causing too much slowness in UI. If so, we might need to move the saving part to another thread.

In general, this is going in a very good direction, I believe we will have this ready for testing soon.

Comment thread app/attributes/attributecontroller.cpp Resolved
Comment thread app/attributes/attributecontroller.cpp Resolved
Comment thread app/attributes/attributecontroller.cpp Resolved
Comment thread app/maptools/recordingmaptool.cpp Resolved
Comment thread app/maptools/recordingmaptool.cpp Resolved
Comment thread app/attributes/attributecontroller.h Resolved
Comment thread app/drafts/featuredraftcontroller.cpp Resolved
Comment thread app/drafts/featuredraftcontroller.cpp Resolved
Comment thread app/drafts/featuredraftcontroller.cpp Resolved
Comment thread app/qml/form/MMFormController.qml Resolved
@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown

📦 Build Artifacts Ready

OS Status Build Info Workflow run
macOS Build 📬 Mergin Maps 73811 dmg Expires: 02/01/2027 #7381
linux Build 📬 Mergin Maps 74071 x86_64 Expires: 02/01/2027 #7407
win64 Build 📬 Mergin Maps 65831 win64 Expires: 02/01/2027 #6583
Android Build 📬 Mergin Maps 869351 APK [arm64-v8a] Expires: 02/01/2027 #8693
📬 QR code Google Play Store #8693
Android Build 📬 Mergin Maps 869311 APK [armeabi-v7a] Expires: 02/01/2027 #8693
📬 QR code Google Play Store #8693
iOS Build 📬 Build number: 26.10.963311 #9633

@xkello

xkello commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

@Withalion everything should be resolved.

@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown

📦 Build Artifacts Ready

OS Status Build Info Workflow run
macOS Build ❌ Build failed or not found. #7386
linux Build 📬 Mergin Maps 74121 x86_64 Expires: 04/01/2027 #7412
win64 Build 📬 Mergin Maps 65881 win64 Expires: 04/01/2027 #6588
Android Build 📬 Mergin Maps 869811 APK [armeabi-v7a] Expires: 04/01/2027 #8698
📬 QR code Google Play Store #8698
Android Build 📬 Mergin Maps 869851 APK [arm64-v8a] Expires: 04/01/2027 #8698
📬 QR code Google Play Store #8698
iOS Build 📬 Build number: 26.10.963811 #9638

@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown

📦 Build Artifacts Ready

OS Status Build Info Workflow run
macOS Build 📬 Mergin Maps 73862 dmg Expires: 06/01/2027 #7386
linux Build 📬 Mergin Maps 74121 x86_64 Expires: 04/01/2027 #7412
win64 Build 📬 Mergin Maps 65881 win64 Expires: 04/01/2027 #6588
Android Build 📬 Mergin Maps 869811 APK [armeabi-v7a] Expires: 04/01/2027 #8698
📬 QR code Google Play Store #8698
Android Build 📬 Mergin Maps 869851 APK [arm64-v8a] Expires: 04/01/2027 #8698
📬 QR code Google Play Store #8698
iOS Build 📬 Build number: 26.10.963811 #9638

@Withalion Withalion left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few more comments after your changes. I'll let @tomasMizera have the final review

Comment thread app/drafts/featuredraft.h Resolved
Comment thread app/drafts/featuredraftcontroller.h Resolved
Comment thread app/drafts/featuredraftcontroller.h Resolved
Comment thread app/drafts/featuredraftcontroller.h Resolved
Comment thread app/drafts/featuredraftcontroller.cpp Resolved
Comment thread app/qml/components/MMListBanner.qml Resolved
Comment thread app/qml/form/MMFormController.qml Resolved
Comment thread app/qml/main.qml Resolved
Comment thread app/qml/main.qml Resolved
Comment thread app/main.cpp Resolved
@xkello
xkello requested a review from tomasMizera October 15, 2026 09:04
@github-actions

Copy link
Copy Markdown

📦 Build Artifacts Ready

OS Status Build Info Workflow run
macOS Build 📬 Mergin Maps 74611 dmg Expires: 28/01/2027 #7461
linux Build 📬 Mergin Maps 74861 x86_64 Expires: 28/01/2027 #7486
win64 Build 📬 Mergin Maps 66611 win64 Expires: 28/01/2027 #6661
Android Build 📬 Mergin Maps 877111 APK [armeabi-v7a] Expires: 28/01/2027 #8771
📬 QR code Google Play Store #8771
Android Build 📬 Mergin Maps 877151 APK [arm64-v8a] Expires: 28/01/2027 #8771
📬 QR code Google Play Store #8771
iOS Build 📬 Build number: 26.10.971211 #9712

@Withalion Withalion left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more concers from the quick review

Comment thread app/qml/main.qml Resolved
Comment thread app/drafts/featuredraftcontroller.h Resolved
Comment thread app/drafts/featuredraftcontroller.h Resolved
@xkello
xkello requested a review from Withalion November 23, 2026 15:23
@github-actions

Copy link
Copy Markdown

📦 Build Artifacts Ready

OS Status Build Info Workflow run
macOS Build 📬 Mergin Maps 75631 dmg Expires: 21/02/2027 #7563
linux Build ❌ Build failed or not found. #7587
win64 Build ❌ Build failed or not found. #6764
Android Build 📬 Mergin Maps 887311 APK [armeabi-v7a] Expires: 21/02/2027 #8873
📬 QR code Google Play Store #8873
Android Build 📬 Mergin Maps 887351 APK [arm64-v8a] Expires: 21/02/2027 #8873
📬 QR code Google Play Store #8873
iOS Build 📬 Build number: 26.11.981511 #9815

@Withalion Withalion left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR needs to be rebased on master to fix merge conflicts

@xkello
xkello force-pushed the feature/feature-drafts branch from c46dbf5 to fa98f0f Compare November 25, 2026 07:36

@tomasMizera tomasMizera left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need #4773 merged first before finalizing this one.

Comment thread app/activeproject.h Resolved
Comment thread app/drafts/featuredraftstorage.h Resolved
Comment thread app/maptools/recordingmaptool.cpp Resolved
Comment thread app/attributes/attributecontroller.cpp Resolved
Comment thread app/maptools/recordingmaptool.cpp Resolved
{
return false; // field removed or renamed since the draft was written
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw. this is prone to the same problem that #4773 fixes. Let's merge and release the two together.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We then also need to verify that remapping scenario is handled properly.

* The actual notification UI is handled elsewhere - this class only detects a draft
* and performs the resume/discard action once the user has decided.
*/
class FeatureDraftController : public QObject

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class must listen to #4773 remapped feature. This is to handle scenario when the drafted feature's fid has been remapped during sync.

  1. Iterate over remapped features
  2. If there is a saved draft for a remapped feature, update its feature ID to the new ID

@xkello
xkello requested a review from tomasMizera December 2, 2026 11:25
@xkello
xkello force-pushed the feature/feature-drafts branch from 7b00060 to 9c5daa3 Compare December 3, 2026 15:59
@xkello

xkello commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

@tomasMizera @gabriel-bolbotina
Known limitations. Can go into this PR or a v2:

  1. Drafts are discarded silently. If a draft becomes invalid (the feature was deleted by sync, a field or layer was removed, or it expired), it's dropped without telling the user.
  2. Widget changes don't invalidate a draft. Only removed fields and changed column types do. If a field's widget changes from text edit to checkbox for example, the draft still resumes with its old value.

@tomasMizera

Copy link
Copy Markdown
Collaborator

@tomasMizera @gabriel-bolbotina Known limitations. Can go into this PR or a v2:

  1. Drafts are discarded silently. If a draft becomes invalid (the feature was deleted by sync, a field or layer was removed, or it expired), it's dropped without telling the user.
  2. Widget changes don't invalidate a draft. Only removed fields and changed column types do. If a field's widget changes from text edit to checkbox for example, the draft still resumes with its old value.

I am happy to keep this for v2. Can you just log a note (CoreUtils::log) when the 1. occurs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resume unsaved feature edits after unexpected app closure

4 participants