mobile icon indicating copy to clipboard operation
mobile copied to clipboard

Fix Reuse last entered value tool and QGIS's reuseLastValue support

Open VitorVieiraZ opened this issue 9 months ago • 4 comments

Support for QGIS's native reuseLastValue option and refactoring of RememberAttributesController to store attribute values persistently in QSettings instead of in-memory, making them survive reinstantiation on each new form open. This adds project-specific storage with ActiveProject integration. On project deletion, stored settings from RememberAttributesController are cleared.

Fix #3784

VitorVieiraZ avatar Mar 27 '25 11:03 VitorVieiraZ

Pull Request Test Coverage Report for Build 16373656904

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 188 unchanged lines in 5 files lost coverage.
  • Overall coverage increased (+0.1%) to 59.69%

Files with Coverage Reduction New Missed Lines %
input/core/merginapi.cpp 7 75.31%
input/app/attributes/rememberattributescontroller.cpp 13 80.3%
input/core/localprojectsmanager.cpp 17 76.34%
input/core/coreutils.cpp 19 86.29%
input/app/attributes/attributecontroller.cpp 132 76.62%
<!-- Total: 188
Totals Coverage Status
Change from base Build 16364671362: 0.1%
Covered Lines: 8267
Relevant Lines: 13850

💛 - Coveralls

github-actions[bot] avatar Mar 27 '25 14:03 github-actions[bot]

Testing looks good to me. The only scenario to confirm, that is set this way now: if we have a project with QGIS's reuseLastValue set for a field and our tool on in Settings, then open the form, we encounter the checkbox for that field unchecked, although this field with QGIS's reuseLastValue set works just fine when our tool is off. If this behavior is intentional, then everything is okay from my side.

VitorVieiraZ avatar Apr 17 '25 17:04 VitorVieiraZ

Untitled-2023-10-31-1527

uclaros avatar Apr 23 '25 08:04 uclaros

Hi @uclaros - is this one ready for review please?

tomasMizera avatar Apr 28 '25 09:04 tomasMizera

Should be ready for review.

The remember last value feature can be enabled in QGIS and in Mergin Maps independently:

  • QGIS off, MM off : Don't show checkboxes, don't store/recall values
  • QGIS on, MM off: Don't show checkboxes, store/recall values based on QGIS setting
  • QGIS on, MM on: Show checkboxes, initial check state based on QGIS setting until overwritten, store/recall values of checked fields
  • QGIS off, MM on: Show checkboxes, initially unchecked, store/recall values of checked fields

The idea is that we store last used values in QSettings per project, per layer, per field. The value stored for a field signifies the following states:

  • No entry in QSettings: remember last value is disabled in both Mergin Maps and QGIS. We won't store nor recall values
  • invalid QVariant(): remember last value is enabled in Mergin Maps, but checkbox is unchecked for this field. We won't store nor recall values
  • valid value: checkbox for this field is checked or enabled in QGIS. This is the previously used value. We will recall this value on next feature and replace it with the new value
  • empty QString(): checkbox for this field is checked or enabled in QGIS, but we don't have a last value yet (no feature saved yet, or empty value in last feature). We will store next value

This is the updated logic diagram. Relevant methods:

  • shouldRememberValue() is used to set the check state of the checkbox in the gui
  • setShouldRememberValue() is called when checkbox is checked/unchecked
  • rememberedValue() reads the previously used value. Returns true if value was stored
  • storeFeature() is called when the feature is stored and potentially saves the last value to the settings
Untitled-2023-10-31-1527(1)

Tests should be extended to cover the QGIS on/off - MM on/off combos

uclaros avatar Jul 18 '25 14:07 uclaros

Let's consider this as a starting point for the next development

tomasMizera avatar Oct 01 '25 12:10 tomasMizera