Skip to content

Wizard: remember zone placement values between runs - #659

Draft
AARP41298 wants to merge 1 commit into
psieg:masterfrom
AARP41298:wizar-load-previous-values
Draft

AARP41298 wants to merge 1 commit into
psieg:masterfrom
AARP41298:wizar-load-previous-values

Conversation

@AARP41298

Copy link
Copy Markdown

Rerunning the wizard rebuilt the zones from the saved positions but reset the zone placement form (LED counts, offset, thickness, stand width, margins, invert order, skip corners) to defaults. Save these per display in the profile when the wizard finishes and load them back when it is started from existing settings.

Not tested in real hardware yet.

Rerunning the wizard rebuilt the zones from the saved positions but reset
the zone placement form (LED counts, offset, thickness, stand width,
margins, invert order, skip corners) to defaults. Save these per display
in the profile when the wizard finishes and load them back when it is
started from existing settings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@psieg psieg left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for the PR! Left a few comments on BottomLeds handling, unapplied edits / existing profiles, profile resets, and INI value loading.

Made with AI

Comment on lines +530 to +531
load(QStringLiteral("TopLeds"), settings.topLeds);
load(QStringLiteral("SideLeds"), settings.sideLeds);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

BottomLeds (sbBottomLeds) is omitted from MonitorSettings, saveMonitorSettings(), loadStoredMonitorSettings(), and storeMonitorSettings(). Instead, onMonitor_currentIndexChanged() relies on sbTopLeds->setValue() / sbSideLeds->setValue() emitting valueChanged to recompute sbBottomLeds.

This breaks in several cases:

  • No-op setValue() when TopLeds == 3 and SideLeds == 2 (matching .ui defaults, e.g. 7-LED Cassiopeia 3/2/0, 9-LED Andromeda 3/2/2, custom 3/2/N, or legacy profiles without ZonePlacement/* keys yet): neither spinbox emits valueChanged, leaving sbBottomLeds stuck at 3. Clicking Apply after adjusting thickness or margins will then unexpectedly generate 3 bottom zones.
  • Switching displays in cbMonitorSelect when two displays share topLeds and sideLeds (e.g. Display 1 4/2/2 and Display 2 4/2/0): sbNumberOfLeds updates with signals blocked, neither topLeds nor sideLeds changes, and sbBottomLeds remains stale from the previous display.
  • Direct sbBottomLeds / sbNumberOfLeds edits don't round-trip, since sbBottomLeds is editable before clicking Apply and sbNumberOfLeds can add or remove zones independently.

Persisting BottomLeds explicitly and setting _ui->sbBottomLeds directly in onMonitor_currentIndexChanged() (with signals blocked on sbTopLeds/sbSideLeds while populating the form) avoids all of these cases.

Comment on lines +229 to +231
_transSettings->zonePlacementValues.clear();
for (QMap<int, MonitorSettings>::const_iterator it = _screens.constBegin(); it != _screens.constEnd(); ++it)
storeMonitorSettings(it.value(), it.key());

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Two subtleties around when values are captured and persisted:

  • Asymmetric handling of unapplied edits: saveMonitorSettings() only runs on preset buttons or Apply, except onTopLeds_valueChanged() and onSideLeds_valueChanged() mutate _screens[currentIndex].topLeds / .sideLeds immediately even if Apply is never clicked (whereas edits to Thickness, StandWidth, margins, Offset, InvertOrder, and SkipCorners without clicking Apply are discarded).
  • Existing pre-PR profiles: If a user with an existing profile (no ZonePlacement/* keys yet) steps through ZonePlacementPage untouched (e.g., only changing device settings or white balance), validatePage() still writes the .ui defaults (TopLeds=3, SideLeds=2, Thickness=15, StandWidth=33, ...) into the profile INI even though the existing zones weren't built with them.

Comment on lines +170 to +172
for (QVariantMap::const_iterator it = _transSettings->zonePlacementValues.constBegin();
it != _transSettings->zonePlacementValues.constEnd(); ++it)
Settings::setValue(it.key(), it.value());

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Clicking "Reset to default" on a profile calls Settings::resetDefaults() -> Settings::initCurrentProfile(true), which resets LED positions, sizes, coefficients, and other profile options. Because ZonePlacement/* is written directly via Settings::setValue() without Settings knowing about the [ZonePlacement] group, stale ZonePlacement/Display*/* keys will remain in the profile .ini file after a reset.

Comment on lines +525 to +529
auto load = [screenIdx](const QString& name, auto& field) {
const QVariant value = Settings::value(zonePlacementKey(screenIdx, name));
if (value.isValid())
field = value.value<std::remove_reference_t<decltype(field)>>();
};

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

A few edge cases when loading and applying stored values:

  • QVariant::isValid() vs. conversion failure: QSettings::IniFormat reads INI entries back as QVariant(QString). An empty or malformed value (e.g. Thickness= or Thickness=abc) still has value.isValid() == true, and value.value<int>() / value.value<double>() silently evaluates to 0 without checking conversion success (toInt(&ok) / toDouble(&ok)), clobbering non-zero defaults (Thickness = 15, StandWidth = 33).
  • Unclamped values: Loaded values aren't clamped to widget bounds (e.g., sbThickness is 1..50, margins are 0.0..40.0), so _screens[idx] can retain and re-save an out-of-range value like 0 while the spinbox clamps its display to 1%.
  • Minor ordering note: In onMonitor_currentIndexChanged() (now also called on init at line 120), resetNewAreaRect() runs before doubleSpinBox_*Margin are populated from settings, so screenRect() uses 0% on init or the previous monitor's margins when switching displays (and lines 108/117 in initializePage() are also duplicated when _isInitFromSettings is true).

@psieg psieg left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

One more note on multi-monitor screen enumeration order and reusing the screen-matching logic from the grabbing rework.

Made with AI

Comment on lines +517 to +520
static QString zonePlacementKey(const int screenIdx, const QString& name)
{
return QStringLiteral("ZonePlacement/Display%1/%2").arg(QString::number(screenIdx + 1), name);
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Multi-monitor screen enumeration order:

Keying ZonePlacement/Display%1/* by screenIdx (QGuiApplication::screens() enumeration order) decouples the saved form values from the [LED_i] zones on the same page, which are matched to screens geometrically via settings.screen->geometry().contains(areaGeometry.center()) (and screenRect() also re-queries QGuiApplication::screens().value(currentIndex) instead of using settings.screen->geometry()). If OS/driver display enumeration order changes across runs (e.g., primary monitor toggle, DisplayPort reconnect order, or connector scan order), Display1/Display2 form values swap monitors while the GrabWidget zones stay with their physical screen geometry.

How the grabbing rework solved this:
In commit 8ac5d0a4 / PR #644, GrabManager, GrabberBase::screenOfWidget(), GrabWidget::deviceFrameGeometry(), and Settings::migrateProfileCoordinates() dropped QGuiApplication::screens() list indices in favor of:

  • Keying in-memory per-screen state by const QScreen* rather than index.
  • Matching across runs/APIs by virtual-desktop QRect / center containment (geom.contains(center)) and display/output identity (QScreen::name(), etc.).

Applying that same pattern here:

  1. Treat Display1..N as saved screen records storing Geometry (plus fallback identity such as SerialNumber and Name), and match them 1-to-1 against QGuiApplication::screens() on load (saved.geometry == screen->geometry(), then screen->geometry().contains(saved.geometry.center()), then serialNumber() / name()). This guarantees whichever QScreen receives the saved GrabWidgets also receives the matching ZonePlacement values.
  2. In screenRect(), read _screens[_ui->cbMonitorSelect->currentIndex()].screen->geometry() directly instead of re-indexing QGuiApplication::screens().
  3. Clear the [ZonePlacement] group before writing current screens so stale entries from unplugged monitors don't linger and false-match by Name later.

Sharing & reuse:
It may be worth extracting a small shared screen-lookup helper (e.g., ScreenUtils in Software/src/) so ZonePlacementPage, GlobalColorCoefPage, GrabManager, GrabWidget, and Settings can share:

  • QScreen* matching by logical geometry/center + fallback identity (serialNumber() / name())
  • Deterministic spatial sorting of QGuiApplication::screens() for consistent Display 1 / Display 2 numbering across both wizard pages (ZonePlacementPage and GlobalColorCoefPage)
  • The Windows HMONITOR -> MONITORINFOEX::szDevice -> QScreen* lookup currently duplicated between GrabWidget::deviceFrameGeometry() and Settings::migrateProfileCoordinates()

(GrabberBase::screenOfWidget() can stay separate since it operates on ScreenInfo / native capture handles and physical rects, and [ZonePlacement] persistence belongs in Settings so resetDefaults() can clear it too.)

This branch has not been deployed

No deployments
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.

2 participants