[not ready for review] fix mirror settings modified in registry before user press accept button - #370
Draft
atsju wants to merge 21 commits into
Draft
[not ready for review] fix mirror settings modified in registry before user press accept button#370atsju wants to merge 21 commits into
atsju wants to merge 21 commits into
Conversation
…y mirror settings
|
🚀 New build available for commit |
|
🚀 New build available for commit |
|
🚀 New build available for commit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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