[not ready for review] fix mirror settings modified in registry before user press accept button - #370
[not ready for review] fix mirror settings modified in registry before user press accept button#370atsju wants to merge 22 commits into
Conversation
…y mirror settings
|
🚀 New build available for commit |
|
🚀 New build available for commit |
|
🚀 New build available for commit |
|
🚀 New build available for commit |
atsju
left a comment
There was a problem hiding this comment.
Hi @gr5
while this PR is not ready for review, could you have a look at it and tell me honnestly what you think about it ?
It's quite large and indirectly does more than title says.
I added some comments in the review pane and in presentation to help out.
The build should be functionnal except for elipse related features.
I have a new personal project restoring an old lathe, so I would rather not spend hours finishing this if it doesn't pass initial smell test. I already spent quite some time to arrive here.
| { | ||
| QSettings set; | ||
| QString path = set.value("mirrorConfigFile").toString(); | ||
| QString path = SettingsFacade::instance().appStore().load().mirrorConfigFile; |
There was a problem hiding this comment.
all direct access to Qsettings have been repalced with settingsFacade
| cv::Scalar mean,std; | ||
| cv::meanStdDev(wf->workData,mean,std,wf->workMask); | ||
| double stdVal = std.val[0]* md->lambda/outputLambda; | ||
| double stdVal = std.val[0]* md->currentSettings().lambda/outputLambda; |
There was a problem hiding this comment.
all parameters like lambda, diameter and other are in a settings struc of the mirror for better access control and management when settings are modifed
| // Persistent mirror configuration copy (source of truth) | ||
| MirrorSettings m_current; | ||
|
|
||
| // Working copy for dialog edits (discarded on Cancel, committed to m_current on OK) | ||
| MirrorSettings m_draft; |
There was a problem hiding this comment.
mirror settings (draft during edition and current when accepted) are no private and managed with accessors.
| @@ -0,0 +1,53 @@ | |||
| #include "settingsfacade.h" | |||
There was a problem hiding this comment.
facade file is scalable and supposed to be the only entry point for every Qsettings (not in this PR, but in extremely long term it's doable if we want)
|
|
||
| #include <QSettings> | ||
|
|
||
| #define SETTINGS_STORE_LOAD_FIELD_FROM_QSETTINGS(type, name, defaultValue, key, converter) \ |
There was a problem hiding this comment.
the store is accessed by facade and uses some macro to read the settingsstores_fields.inc file
| @@ -0,0 +1,51 @@ | |||
| // Shared settings schema list. | |||
| // Entry format for callbacks: | |||
| // FIELD(type, memberName, defaultValue, key, converter) | |||
There was a problem hiding this comment.
this is the really neat part
FIELD(type, memberName, defaultValue, key, converter)
Everthing is typed here only once. It's the main source a truth.
I know Dale has been extremelly carefull to copy paste the same default aclues, key strings, converters but this solved programatically the risk of error.
It also centralises all the used keys in one knwoledge file. I did not change any key to not break compatibility.
fix #121
mentionning #224 #234
I'm really sorry this one is quite long. It was difficult to split and even now some ellipse related things are temporarly brocken.
short version
The mirror dialog's settings were exposed as public members, allowing user interactions to corrupt the persistent copy even on Cancel. This PR implements a draft pattern + settings facade to fix it:
m_current(persistent copy) is now protected; external code reads it viacurrentSettings()(read-only)m_draft(working copy) handles all user edits; discarded on Cancel, committed on OKSettingsFacadeprovides single atomic save/load point; eliminates duplicate QSettings callsm_draft; removed 13+ public data membersLong version explanation
Problem Fixed
The singleton mirror dialog's settings were exposed as public members scattered across the class, violating encapsulation and creating a critical flaw: the
Cancelbutton could not reliably discard edits because the persistent settings copy was unprotected and could be corrupted by user interactions.Solution Implemented: Draft Pattern + Settings Facade
1. Architectural Changes
New Infrastructure:
SettingsFacade (new singleton): Centralized access point for all application settings
MirrorSettingsStore & ApplicationSettingsStore (new): Private store classes with friend-only access to
mirrordlgand facadesettingsstores_fields.incsettingsstores_fields.inc (new): Single source of truth for all settings schema
diameter,roc,cc,flipH, etc.)projectPath,mirrorConfigFile,lastPath)Dual-Copy Pattern in
mirrorDlg:2. Transactional Edit Semantics
Before Dialog Shown:
loadDraftFromSettings()for safety (in case dialog used withoutshowEvent())m_currentandm_draftare initialized from persistent storageWhile User Edits:
m_draft(working copy)m_currentviacurrentSettings()(persistent copy)On Dialog Close:
OK/Accept: Commits
m_draft → m_current → QSettingsatomically via facadem_current = m_draft(merge working to persistent)SettingsFacade::instance().saveMirrorSettings(m_current)(atomic save)Cancel: Discards
m_draftentirelyloadDraftFromSettings()reloads from persistent storageshowEvent() Override:
loadDraftFromSettings()before dialog becomes visible3. Encapsulation Improvements
Removed Public Data Members:
diameter,roc,obs,cc,flipH,lambda,doNull,fringeSpacing,aperatureReduction,m_useAnnular,m_outlineShape,m_verticalAxis, etc. (13+ exposed members)MirrorSettings m_draftstructReplaced With Managed Access:
mirrorDlg::get_Instance()->currentSettings()returnsconst MirrorSettings&(read-only)Added Inline Getters for Computed Values:
Compile-Time Access Control:
→ No way for external code to call
save()directly; enforced at compile-time by linker4. Settings Persistence Flow
Old Design:
New Design:
Benefits
m_current) is now protected from Cancel operationscurrentSettings()(persistent), dialog editsm_draft(working)Changed Files
Core Architecture
Mirror Dialog Refactoring
m_draft, addedloadDraftFromSettings()andshowEvent(), simplifiedon_buttonBox_accepted()Build System
Future Work (Next PRs)
Critical TODOs from mirrordlg.h
1. Persist Unit Preference (mm vs. inches)
Current Behavior: Unit preference (
mm) is transient—resets to default on restart.Solution:
bool unitsMMfield tosettingsstores_fields.incshowEvent()andon_buttonBox_accepted()mm(true)initializationBenefit: Remembers user's preferred unit system across sessions.
2. Clarify & Consolidate Outline Shape API
Current Problem:
m_currentand QSettingssetMinorAxis(), sometimes direct member accessSolution:
adoptWavefrontSettings()to accept outline shape:setOutlineShape()separate methodsBenefit: Eliminates inconsistent state where shape is changed but not saved.
3. Clean allispe outline helper
Current Confusion:
setMinorAxisis called from outlining window and can modify mirror setting at each outline.Solution:
Benefit: Eliminates API confusion; clear roles for each method.
Technical Notes
Why X-Macros?
Reduces boilerplate and eliminates source-of-truth duplication. A single field definition in
settingsstores_fields.incautomatically generates:Adding a new mirror setting requires exactly one edit location.
Why Compile-Time Friend Enforcement?
Prevents accidental calls to
save()from unintended code locations. The linker will reject anysave()call outside the allowed friend scope—impossible to miss in code review or CI.Why Always Reload on showEvent()?
Ensures the dialog never operates on stale data if another dialog modified settings between invocations. Also handles programmatic dialog reuse without explicit reset calls.
References