Skip to content

Bugfix/fix reuse last entered value - #4668

Merged
Withalion merged 7 commits into
masterfrom
bugfix/fix-reuse-last-entered-value
Oct 21, 2026
Merged

Withalion merged 7 commits into
masterfrom
bugfix/fix-reuse-last-entered-value

Conversation

@xkello

@xkello xkello commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes a bug where enabling "Use last entered value" on a photo/file field causes the previous feature's photo file to be corrupted, renamed, or orphaned when reused by a new feature - most visibly when a custom filename expression is set in QGIS, where the previous feature's file gets physically renamed and reassigned to the new feature, leaving the previous feature with a broken/missing image.

Fixes: #4487

What changed

  • AttributeController::updateOnFeatureChange() now clones the underlying file when a photo/file field's value is reused, instead of just copying the path string. Each feature gets its own independent file from the moment the drawer opens, so it's never possible for two features to end up sharing (and therefore corrupting) the same photo.
  • The clone is tracked on the FormItem (isReusedValue(), reusedCopyPath()) so it can be cleaned up if it's never actually needed: AttributeController::discardReusedPhotoCopies() deletes it if the draft feature is discarded (cancel/rollback), or if the photo is deleted or replaced before the feature is saved.
  • renamePhotos() now evaluates the project's custom filename expression fresh against the clone (instead of skipping reused fields entirely), so a reused photo gets a correctly computed, per-feature filename rather than a generic incremented name. A static expression that collides with an existing file still gets a proper incremental suffix.
  • recalculateDefaultValues() no longer lets a QGIS field-level Default Value expression overwrite a value that was just populated by "reuse last entered value" while the form is open.
  • InputUtils::resolveTargetDir() now resolves a relative root path expression/Default Path against the project home path. Previously a relative path (e.g. 'photos/' + @layer_name) was used as-is, which could resolve to the wrong location on disk and produce a broken/missing image.
  • Android (MMActivity.importImage) and iOS (IOSGalleryPickerDelegate) gallery import now create the destination directory before copying the picked image, matching what capture-from-camera already did.

Behaviour

  • Reusing a photo value for a new feature clones the file, so previously saved features keep their original, valid photo path - no more orphaned attachments or broken image icons after sync.
  • Deleting or unlinking a reused photo from one feature no longer affects any other feature that reused it.
  • Cancelling a draft feature, or deleting/replacing a reused photo before saving, cleans up the clone instead of leaving it behind.
  • Custom filename expressions are evaluated fresh for each feature's cloned photo, with correct incremental suffixing when the expression is static.
  • No impact on fields without a custom filename expression, and no impact on the "unsaved changes" dialog.

TLDR @Withalion

"Use last entered value" on a photo field now clones the file per feature instead of sharing/renaming the original, so reused photos never corrupt or orphan another feature's image, on save or on cancel.

@xkello
xkello requested a review from Withalion August 25, 2026 12:43
@github-actions

Copy link
Copy Markdown

📦 Build Artifacts Ready

OS Status Build Info Workflow run
macOS Build ❌ Build failed or not found. #7212
linux Build ❌ Build failed or not found. #7238
win64 Build 📬 Mergin Maps 64141 win64 Expires: 23/11/2026 #6414
Android Build 📬 Mergin Maps 852351 APK [arm64-v8a] Expires: 23/11/2026 #8523
📬 Mergin Maps 852351 APK [arm64-v8a] Google Play Store #8523
Android Build 📬 Mergin Maps 852311 APK [armeabi-v7a] Expires: 23/11/2026 #8523
📬 Mergin Maps 852311 APK [armeabi-v7a] Google Play Store #8523
iOS Build 📬 Build number: 26.08.946411 #9464

@github-actions

github-actions Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

Coverage Report for CI Build 39578388508

Coverage increased (+0.3%) to 60.082%

Details

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

Uncovered Changes

No uncovered changes found.

Coverage Regressions

337 previously-covered lines in 2 files lost coverage.

File Lines Losing Coverage Coverage
mm/app/inpututils.cpp 179 56.22%
mm/app/attributes/attributecontroller.cpp 158 78.82%

Coverage Stats

Coverage Status
Relevant Lines: 15900
Covered Lines: 9553
Line Coverage: 60.08%
Coverage Strength: 98.03 hits per line

💛 - Coveralls

@github-actions

Copy link
Copy Markdown

📦 Build Artifacts Ready

OS Status Build Info Workflow run
macOS Build 📬 Mergin Maps 72131 dmg Expires: 23/11/2026 #7213
linux Build 📬 Mergin Maps 72391 x86_64 Expires: 23/11/2026 #7239
win64 Build 📬 Mergin Maps 64151 win64 Expires: 23/11/2026 #6415
Android Build 📬 Mergin Maps 852451 APK [arm64-v8a] Expires: 23/11/2026 #8524
📬 Mergin Maps 852451 APK [arm64-v8a] Google Play Store #8524
Android Build 📬 Mergin Maps 852411 APK [armeabi-v7a] Expires: 23/11/2026 #8524
📬 Mergin Maps 852411 APK [armeabi-v7a] Google Play Store #8524
iOS Build 📬 Build number: 26.08.946511 #9465

@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.

Looks like in some cases the photo renaming doesn't work correctly. Either it get's renamed again, when using now() or the name somehow gets mixed with previous value as well. Have a look at this project Matej-test/photo-naming-expr and POI layer.

Renaming gets triggered on empty photo fields with reuse last entered value turned on.

My comment on the issue about unlinking/deleting is addressed by #4685?

Add some unit tests for using default value on photos in testattributecontroller.h

Comment thread app/attributes/attributecontroller.cpp Outdated
Comment thread app/attributes/attributecontroller.cpp Outdated
Comment thread app/attributes/attributecontroller.cpp Outdated
Comment thread app/attributes/attributecontroller.cpp Outdated
Comment thread app/attributes/attributedata.h Outdated
@xkello
xkello requested a review from Withalion September 9, 2026 13:30
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

📦 Build Artifacts Ready

OS Status Build Info Workflow run
macOS Build 📬 Mergin Maps 72781 dmg Expires: 08/12/2026 #7278
linux Build 📬 Mergin Maps 73041 x86_64 Expires: 08/12/2026 #7304
win64 Build 📬 Mergin Maps 64801 win64 Expires: 08/12/2026 #6480
Android Build 📬 Mergin Maps 858851 APK [arm64-v8a] Expires: 08/12/2026 #8588
📬 QR code Google Play Store #8588
Android Build 📬 Mergin Maps 858811 APK [armeabi-v7a] Expires: 08/12/2026 #8588
📬 QR code Google Play Store #8588
iOS Build ❌ Build failed or not found. #9530

Comment thread app/attributes/attributecontroller.cpp
Comment thread app/attributes/attributecontroller.cpp Outdated
Comment thread app/attributes/attributecontroller.cpp
Comment thread app/attributes/attributedata.h Outdated
Comment thread app/ios/iosviewdelegate.mm Outdated
Comment thread app/android/src/uk/co/lutraconsulting/MMActivity.java Outdated
Comment thread core/coreutils.cpp Outdated
Comment thread app/attributes/attributecontroller.h Outdated
Comment thread app/attributes/attributecontroller.cpp Outdated
Comment thread app/attributes/attributecontroller.cpp Outdated
@xkello
xkello requested a review from tomasMizera September 18, 2026 11:42
@github-actions

Copy link
Copy Markdown

📦 Build Artifacts Ready

OS Status Build Info Workflow run
macOS Build 📬 Mergin Maps 73001 dmg Expires: 17/12/2026 #7300
linux Build 📬 Mergin Maps 73261 x86_64 Expires: 17/12/2026 #7326
win64 Build 📬 Mergin Maps 65021 win64 Expires: 17/12/2026 #6502
Android Build ❌ Build failed or not found. #8610
iOS Build ❌ Build failed or not found. #9552

@xkello
xkello force-pushed the bugfix/fix-reuse-last-entered-value branch from efee4cb to 99a76d6 Compare September 23, 2026 13:12
@github-actions

Copy link
Copy Markdown

📦 Build Artifacts Ready

OS Status Build Info Workflow run
macOS Build 📬 Mergin Maps 73211 dmg Expires: 22/12/2026 #7321
linux Build 📬 Mergin Maps 73471 x86_64 Expires: 22/12/2026 #7347
win64 Build 📬 Mergin Maps 65231 win64 Expires: 22/12/2026 #6523
Android Build 📬 Mergin Maps 863351 APK [arm64-v8a] Expires: 22/12/2026 #8633
📬 QR code Google Play Store #8633
Android Build 📬 Mergin Maps 863311 APK [armeabi-v7a] Expires: 22/12/2026 #8633
📬 QR code Google Play Store #8633
iOS Build 📬 Build number: 26.09.957311 #9573

@Withalion
Withalion requested review from tomasMizera and removed request for Withalion and tomasMizera September 23, 2026 21:37

@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.

Looks good! Please adjust these minor comments and we can go testing. We will need extensive photo testing here @IvaKuklica

Comment thread app/attributes/attributecontroller.cpp Outdated
Comment thread app/attributes/attributecontroller.cpp
Comment thread app/attributes/attributecontroller.cpp
@xkello
xkello requested a review from Withalion October 1, 2026 11:01
@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown

📦 Build Artifacts Ready

OS Status Build Info Workflow run
macOS Build 📬 Mergin Maps 73661 dmg Expires: 30/12/2026 #7366
linux Build 📬 Mergin Maps 73921 x86_64 Expires: 30/12/2026 #7392
win64 Build 📬 Mergin Maps 65681 win64 Expires: 30/12/2026 #6568
Android Build 📬 Mergin Maps 867851 APK [arm64-v8a] Expires: 30/12/2026 #8678
📬 QR code Google Play Store #8678
Android Build 📬 Mergin Maps 867811 APK [armeabi-v7a] Expires: 30/12/2026 #8678
📬 QR code Google Play Store #8678
iOS Build 📬 Build number: 26.10.961811 #9618

@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.

Rebase and move to testing

@xkello
xkello force-pushed the bugfix/fix-reuse-last-entered-value branch from 8a9edcf to 36307a9 Compare October 7, 2026 06:59
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown

📦 Build Artifacts Ready

OS Status Build Info Workflow run
macOS Build 📬 Mergin Maps 73901 dmg Expires: 05/01/2027 #7390
linux Build ❌ Build failed or not found. #7416
win64 Build 📬 Mergin Maps 65921 win64 Expires: 05/01/2027 #6592
Android Build 📬 Mergin Maps 870211 APK [armeabi-v7a] Expires: 05/01/2027 #8702
📬 QR code Google Play Store #8702
Android Build 📬 Mergin Maps 870251 APK [arm64-v8a] Expires: 05/01/2027 #8702
📬 QR code Google Play Store #8702
iOS Build 📬 Build number: 26.10.964211 #9642

@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 73901 dmg Expires: 05/01/2027 #7390
linux Build 📬 Mergin Maps 74162 x86_64 Expires: 06/01/2027 #7416
win64 Build 📬 Mergin Maps 65921 win64 Expires: 05/01/2027 #6592
Android Build 📬 Mergin Maps 870211 APK [armeabi-v7a] Expires: 05/01/2027 #8702
📬 QR code Google Play Store #8702
Android Build 📬 Mergin Maps 870251 APK [arm64-v8a] Expires: 05/01/2027 #8702
📬 QR code Google Play Store #8702
iOS Build 📬 Build number: 26.10.964211 #9642

@IvaKuklica

IvaKuklica commented Oct 13, 2026 •

Copy link
Copy Markdown

Testing results:

Tested on:
iOS: [IPhone 15 / iOS 26 / 2026.4.1- 26.10.964211
Android: [Samsung Galaxy,A53 / Andorid 16 / 2026.4.1 - 870251
Windows: HP / Windows 11 Pro /2026.4.1 - win (65921)

All acceptance criteria passed:
✅ - photos are cloned rather than referenced,
✅- multiple photo fields work,
✅- custom and static expressions work (static ones get an incremental suffix),
✅- deleting and sketching are independent per feature, and
✅- all files and references are valid after sync.
❌ - photo path that uses a value map field - see details below

⚠️ Issue: Issue found: photo isn’t reused when the path depends on a value map field

Description:
The project stores photos in subfolders based on the value of the status field, which uses a Value Map widget (Open / Pending / Done). The photo default path is @project_folder + '/Photos/' + "status", so photos are saved to Photos/Open/, Photos/Pending/ or Photos/Done/.
When “Reuse last entered value” is used for the photo field, the photo isn’t added to the next feature and the photo field stays empty. This happens with photos taken with the camera and with photos chosen from the gallery. After sync, these photos aren’t available in QGIS either.

image

Setup:

  • field status uses a value map (Open / Pending / Done),
  • the photo path is @project_folder + '/Photos/' + "status", and
  • “Reuse last entered value” is on.

Steps:

  1. Add feature 1 with a status (Open) and a photo (saved correctly to Photos//).
  2. Add feature 2.
  3. Add feature 3 and 4.

Actual: The photo field for feature 3 and 4 is empty and no photo is added.
Expected: Feature 3 and 4 gets a cloned photo, saved in the subfolder that matches its status.

Sreenrecord:

ScreenRecording_10-13-2026.13-05-49_1.MP4

@xkello
xkello force-pushed the bugfix/fix-reuse-last-entered-value branch from f3170d8 to 0162801 Compare October 14, 2026 14:55
@github-actions

Copy link
Copy Markdown

📦 Build Artifacts Ready

OS Status Build Info Workflow run
macOS Build 📬 Mergin Maps 74121 dmg Expires: 12/01/2027 #7412
linux Build 📬 Mergin Maps 74381 x86_64 Expires: 12/01/2027 #7438
win64 Build 📬 Mergin Maps 66141 win64 Expires: 12/01/2027 #6614
Android Build 📬 Mergin Maps 872451 APK [arm64-v8a] Expires: 12/01/2027 #8724
📬 QR code Google Play Store #8724
Android Build 📬 Mergin Maps 872411 APK [armeabi-v7a] Expires: 12/01/2027 #8724
📬 QR code Google Play Store #8724
iOS Build 📬 Build number: 26.10.966411 #9664

@IvaKuklica

Copy link
Copy Markdown

Testing Result:

After fix the application behaves as expected ✅

@Withalion
Withalion force-pushed the bugfix/fix-reuse-last-entered-value branch from 0162801 to ff9ea9b Compare October 21, 2026 09:37
@github-actions

Copy link
Copy Markdown

📦 Build Artifacts Ready

OS Status Build Info Workflow run
macOS Build 📬 Mergin Maps 74251 dmg Expires: 19/01/2027 #7425
linux Build 📬 Mergin Maps 74511 x86_64 Expires: 19/01/2027 #7451
win64 Build 📬 Mergin Maps 66271 win64 Expires: 19/01/2027 #6627
Android Build 📬 Mergin Maps 873711 APK [armeabi-v7a] Expires: 19/01/2027 #8737
📬 QR code Google Play Store #8737
Android Build 📬 Mergin Maps 873751 APK [arm64-v8a] Expires: 19/01/2027 #8737
📬 QR code Google Play Store #8737
iOS Build 📬 Build number: 26.10.967711 #9677

@Withalion
Withalion merged commit c461256 into master Oct 21, 2026
13 checks passed
@Withalion
Withalion deleted the bugfix/fix-reuse-last-entered-value branch October 21, 2026 11:30
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.

"reuse last entered value" not working for attachment/photos fields

4 participants