From 337ea76fda78a8794a7cb6a07aff7720b8c338a5 Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Sun, 13 Sep 2026 09:33:38 +0200 Subject: [PATCH 1/3] viewer: the composite plot reads on two coloured axes, and fluorescence goes The "Spots + background" dataset plot now scales each quantity on its own axis - background on the left, spot count on the right - with each axis's labels and line coloured like its curve, so which axis reads which quantity is visible at a glance. Each axis is ranged from its own series alone, so live growth of one quantity never rescales the other; on top of that the background's range is inflated upward and the spot count's downward, each by its own span, so the two curves occupy separate halves of the plot instead of crossing. The spot count stays the primary series (current-image marker, hover, click-to-load, overlays). Trade-off accepted: the spots axis shows ticks below zero in its empty lower band. The per-image plot selector no longer offers the X-ray fluorescence spectrum; the reader-side fluorescence plumbing is untouched. Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01WbjnQhutnboy4qbxwmgDAX --- docs/CHANGELOG.md | 2 ++ viewer/JFJochViewerDatasetInfo.cpp | 3 +- viewer/charts/JFJochDatasetInfoChartView.cpp | 35 +++++++++++++------ viewer/charts/JFJochDatasetInfoChartView.h | 5 +-- viewer/widgets/JFJochViewerSidePanelChart.cpp | 8 ----- viewer/widgets/JFJochViewerSidePanelChart.h | 2 +- 6 files changed, 32 insertions(+), 23 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 7b7cbbdf9..26f766366 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -13,6 +13,8 @@ * The viewer's file manager lists CBF frames beside HDF5 datasets. * The viewer's image statistics state the collection time, detector distance, beam centre and wavelength as entries of their own rather than in a tooltip, and no longer report a B-factor. * The viewer plots spot count and background together on one plot, which is what a connection to a live source now shows by default. +* The viewer's combined spots + background plot scales each quantity on its own axis - background on the left, spot count on the right, each axis coloured like its curve - and keeps the two curves in separate halves of the plot. +* The viewer's per-image plot selector no longer offers the X-ray fluorescence spectrum. * The viewer's reprocessing panel is called Processing, and the jobs panel it shared that name with is called Jobs. * Expanding the viewer's powder-calibration section no longer widens the left-hand panel past the space it has, which used to push half of it out of sight. * No section of the viewer's processing panel asks for more width than the panel has: geometry, unit cell, goniometer, spot finding and indexing all used to widen it when opened. diff --git a/viewer/JFJochViewerDatasetInfo.cpp b/viewer/JFJochViewerDatasetInfo.cpp index 4cf0e3150..03f1722ce 100644 --- a/viewer/JFJochViewerDatasetInfo.cpp +++ b/viewer/JFJochViewerDatasetInfo.cpp @@ -329,7 +329,8 @@ void JFJochViewerDatasetInfo::UpdatePlot() { RunColor(static_cast(runs_.size())), XForRun(*live_run_)}); } - // "Spots + background": one plot, two quantities, the background on its own right-hand axis. + // "Spots + background": one plot, two quantities — the background on its own left-hand axis, + // the spot count on the right. std::optional secondary; if (val == SPOTS_PLUS_BACKGROUND) { secondary = JFJochDatasetInfoChartView::NamedSeries{ diff --git a/viewer/charts/JFJochDatasetInfoChartView.cpp b/viewer/charts/JFJochDatasetInfoChartView.cpp index ad7eee442..7f35229b6 100644 --- a/viewer/charts/JFJochDatasetInfoChartView.cpp +++ b/viewer/charts/JFJochDatasetInfoChartView.cpp @@ -431,9 +431,10 @@ void JFJochDatasetInfoChartView::buildTimeDomainChart() { chart()->setMargins(m); } } else { - // Normal numeric labels, axis on the LEFT + // Normal numeric labels, axis on the LEFT — unless a secondary quantity takes the + // left side, in which case the primary reads on the RIGHT. chart()->removeAxis(axisY); - chart()->addAxis(axisY, Qt::AlignLeft); + chart()->addAxis(axisY, secondary_.has_value() ? Qt::AlignRight : Qt::AlignLeft); series->attachAxis(axisY); currentSeries->attachAxis(axisY); @@ -450,9 +451,12 @@ void JFJochDatasetInfoChartView::buildTimeDomainChart() { line->attachAxis(ax); } - // Secondary quantity: same x, its own Y axis on the right, so a small background value is - // not flattened by a spot count three orders of magnitude larger. The 1/d^2 layout already - // owns the right-hand side, so the two never combine. + // Secondary quantity: same x, its own Y axis on the LEFT (the primary then reads on the + // RIGHT), so a small background value is not flattened by a spot count three orders of + // magnitude larger. Each axis is ranged from its own series alone; on top of that the + // secondary's max and the primary's min are each inflated by that series' own span, so the + // secondary curve occupies the lower half of the plot and the primary the upper half. A + // secondary never combines with the 1/d^2 layout. if (secondary_.has_value() && !m_yOneOverD) { auto *line = new QLineSeries(this); line->setName(secondary_->name); @@ -466,18 +470,27 @@ void JFJochDatasetInfoChartView::buildTimeDomainChart() { auto *axisY2 = new QValueAxis(); if (std::isfinite(secMin) && std::isfinite(secMax)) { const double lo = m_minYZeroEnabled ? 0.0 : secMin; - axisY2->setRange(lo, (secMax > lo) ? secMax : (lo + 1.0)); + const double hi = (secMax > lo) ? secMax : (lo + 1.0); + axisY2->setRange(lo, lo + 2.0 * (hi - lo)); // lower half } - if (secondary_->color.isValid()) - axisY2->setLabelsColor(secondary_->color); - chart()->addAxis(axisY2, Qt::AlignRight); + chart()->addAxis(axisY2, Qt::AlignLeft); line->attachAxis(axisY2); for (auto *ax: finalAxes) if (ax->orientation() == Qt::Horizontal) line->attachAxis(ax); - // Colour the left labels to match the primary, so it is clear which axis reads which. - if (axisY && primary_color_.isValid()) + if (axisY) + axisY->setRange(axisY->max() - 2.0 * (axisY->max() - axisY->min()), + axisY->max()); // upper half + // Each axis carries its series' colour on labels and axis line, so it is clear at a + // glance which axis reads which curve. + if (secondary_->color.isValid()) { + axisY2->setLabelsColor(secondary_->color); + axisY2->setLinePenColor(secondary_->color); + } + if (axisY && primary_color_.isValid()) { axisY->setLabelsColor(primary_color_); + axisY->setLinePenColor(primary_color_); + } } // The current-image marker is not a run - keep it out of the legend. diff --git a/viewer/charts/JFJochDatasetInfoChartView.h b/viewer/charts/JFJochDatasetInfoChartView.h index 403aa0cf8..26a6bba06 100644 --- a/viewer/charts/JFJochDatasetInfoChartView.h +++ b/viewer/charts/JFJochDatasetInfoChartView.h @@ -53,8 +53,9 @@ public: struct NamedSeries { QString name; std::vector values; QColor color; std::vector x; }; private: std::vector overlays_; - // A second quantity plotted against the same x but on its own right-hand Y axis, for a metric - // pair whose units are unrelated (spot count vs background per pixel). Never 1/d^2-transformed. + // A second quantity plotted against the same x but on its own left-hand Y axis (the primary + // then moves to the right), for a metric pair whose units are unrelated (spot count vs + // background per pixel). Never 1/d^2-transformed. std::optional secondary_; QColor primary_color_; // colour of the active (primary) run, if assigned std::vector primary_x_; // x (image numbers) for the primary series; empty => index diff --git a/viewer/widgets/JFJochViewerSidePanelChart.cpp b/viewer/widgets/JFJochViewerSidePanelChart.cpp index a4cb3c795..e7ace480f 100644 --- a/viewer/widgets/JFJochViewerSidePanelChart.cpp +++ b/viewer/widgets/JFJochViewerSidePanelChart.cpp @@ -23,7 +23,6 @@ QList> JFJochViewerSidePanelChart::PlotTypes() { {"I/sigma", 2}, {"Spots (count)", 5}, {"Spots (intensity)", 6}, - {"X-ray fluorescence spectrum", 4}, }; } @@ -53,13 +52,6 @@ void JFJochViewerSidePanelChart::redrawPlot() { y = image->ImageData().integration_Isigma; azint_plot->UpdateData(x, y, "d [Å]", "I/sigma", true); break; - case 4: - x = image->Dataset().experiment.GetFluorescenceSpectrum().GetEnergy_eV(); - y = image->Dataset().experiment.GetFluorescenceSpectrum().GetData(); - for (auto &iter: x) - iter /= 1000.0; // Convert eV to keV - azint_plot->UpdateData(x, y, "E [keV]", "", false); - break; case 5: x = image->ImageData().spot_plot_one_over_d_square; y = image->ImageData().spot_plot_count; diff --git a/viewer/widgets/JFJochViewerSidePanelChart.h b/viewer/widgets/JFJochViewerSidePanelChart.h index 74141bd29..61d736b62 100644 --- a/viewer/widgets/JFJochViewerSidePanelChart.h +++ b/viewer/widgets/JFJochViewerSidePanelChart.h @@ -11,7 +11,7 @@ #include "../../reader/JFJochReaderImage.h" #include "../charts/JFJochSimpleChartView.h" -// Per-image profile plot (azimuthal 1D, Wilson, I/sigma, spots, fluorescence). It has no selector +// Per-image profile plot (azimuthal 1D, Wilson, I/sigma, spots). It has no selector // of its own — the host (dataset-info dock) drives the plot type via setPlotType, reusing its one // combo box. class JFJochViewerSidePanelChart : public QWidget { From 7d872fd76280db0e451a10d8009232cbb0f3f03b Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Sun, 13 Sep 2026 10:16:55 +0200 Subject: [PATCH 2/3] viewer: plot choices persist per dataset kind, and settings reset live The dataset-info plot remembers the selected quantity and the Grid/Per-image toggle states across restarts, with grid scans and standard scans each keeping their own favourite (QSettings groups datasetInfoPlot/gridScan and /standard). Choices are stored as the combo item's data code, not its index, so a saved choice survives the plot list changing and a code no longer offered falls back to the first item. Favourites are saved on every explicit user action and applied whenever a dataset of the other kind loads; loads of the same kind keep the in-session state, and the live-source default still wins until the user picks. The unconditional Grid auto-check on grid scans moved into the favourite's default, so unchecking Grid on a grid dataset now sticks. View > "Reset all settings to defaults" clears the whole settings store after confirmation and brings the running session to a first-start state in place: default layout, window size, display settings (Indigo, Auto off, HDR off), plot choices, and the file manager root. Because the live state then equals the defaults, saving on close stays enabled and later changes persist as usual. File > Quit now closes the main window instead of calling QApplication::quit(), so closeEvent runs and the persistent settings are saved on that path too - previously they were saved only when the window was closed by the window manager. The file manager root persistence was audited and left unchanged: saved on every successful change, restored behind JUNGFRAUJOCH_DATA_ROOT, and a vanished directory falls back to the home directory. Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01WbjnQhutnboy4qbxwmgDAX --- docs/CHANGELOG.md | 3 + viewer/JFJochViewerDatasetInfo.cpp | 83 +++++++++++++++++++--- viewer/JFJochViewerDatasetInfo.h | 13 +++- viewer/JFJochViewerMenu.cpp | 6 +- viewer/JFJochViewerMenu.h | 1 + viewer/JFJochViewerWindow.cpp | 35 ++++++++- viewer/JFJochViewerWindow.h | 4 ++ viewer/widgets/JFJochViewerFileBrowser.cpp | 4 ++ viewer/widgets/JFJochViewerFileBrowser.h | 4 ++ 9 files changed, 139 insertions(+), 14 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 26f766366..72ef7db66 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -21,6 +21,9 @@ * The viewer states the angle of a rotation axis that does not turn as a single number, instead of adding a zero wedge to it. * The viewer's image statistics show the sample-head chi and phi angles of a dataset that records them (an SLS Smargon), and nothing for one that does not. * Switching the viewer's plot between per-dataset and per-image no longer leaves the other mode's quantities in the selector, and each mode remembers what was last shown in it. +* The viewer's dataset-info plot remembers its choice - the selected quantity and the Grid and Per-image toggles - across restarts, with grid scans and standard scans each keeping their own. +* The viewer's View menu gains "Reset all settings to defaults", which clears every saved viewer setting after confirmation and returns the running viewer - layout, window size, display settings, plot choices, file manager root - to its defaults. +* Quitting the viewer through the File menu now saves the persistent settings, as closing the window always did. * Re-initialising the broker after a DECTRIS run that never started no longer freezes it with no way to cancel. * Re-initialising the broker disconnects the previous run's stream reader, so a DECTRIS collection no longer starts and then stays empty because half its stream - the start message included - went to a reader nobody was listening to. * Cancelling a dark-mask calibration abandons it instead of adopting the partial mask and reporting the calibration as done. diff --git a/viewer/JFJochViewerDatasetInfo.cpp b/viewer/JFJochViewerDatasetInfo.cpp index 03f1722ce..d42352f1e 100644 --- a/viewer/JFJochViewerDatasetInfo.cpp +++ b/viewer/JFJochViewerDatasetInfo.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "JFJochViewerDatasetInfo.h" @@ -11,6 +12,12 @@ namespace { // Combo data value of the combined spots + background plot. constexpr int SPOTS_PLUS_BACKGROUND = 16; + // Grid scans and standard scans keep separate saved favourites. + QString FavouriteGroup(bool grid_scan) { + return grid_scan ? QStringLiteral("datasetInfoPlot/gridScan") + : QStringLiteral("datasetInfoPlot/standard"); + } + // Stable colour per run by its position in the run list (Original is index 0 -> blue), so a // run keeps its colour whether it is the active (primary) line or an overlay. QColor RunColor(int index) { @@ -81,8 +88,12 @@ JFJochViewerDatasetInfo::JFJochViewerDatasetInfo(QWidget *parent) : QWidget(pare connect(combo_box, &QComboBox::currentIndexChanged, this, &JFJochViewerDatasetInfo::comboBoxSelected); // activated (not currentIndexChanged) fires only on a user pick, which is exactly when the - // live default must stop overriding the selection. - connect(combo_box, &QComboBox::activated, this, [this](int) { user_picked_ = true; }); + // live default must stop overriding the selection - and when the saved favourite follows it. + connect(combo_box, &QComboBox::activated, this, [this](int) { + user_picked_ = true; + (combo_is_image_mode_ ? last_image_selection : last_selection) = combo_box->currentData().toInt(); + SaveFavourite(); + }); connect(grid_scan_image, &JFJochGridScanImage::imageSelected, this, &JFJochViewerDatasetInfo::imageSelectedInChart); @@ -102,12 +113,14 @@ JFJochViewerDatasetInfo::JFJochViewerDatasetInfo(QWidget *parent) : QWidget(pare if (grid_button->isChecked()) image_button->setChecked(false); // leaves per-image mode: the combo must follow ModeChanged(); + SaveFavourite(); }); connect(image_button, &QPushButton::clicked, [this]() { if (image_button->isChecked()) grid_button->setChecked(false); ModeChanged(); + SaveFavourite(); }); connect(image_chart, &JFJochViewerSidePanelChart::writeStatusBar, [this](QString s, int t) { emit writeStatusBar(s, t); }); @@ -123,10 +136,54 @@ void JFJochViewerDatasetInfo::RestoreSelection() { combo_box->setCurrentIndex(live_default); return; } - // Each mode remembers its own selection: the two lists are unrelated, so carrying an index - // across would land on whatever metric happens to sit at that position in the other list. - const int sel = combo_is_image_mode_ ? last_image_selection : last_selection; - combo_box->setCurrentIndex(sel < combo_box->count() ? sel : 0); + // Each mode remembers its own selection by the item's data code: the two lists are unrelated, + // and a code survives the combo being rebuilt with a different item set - one that is no + // longer offered simply isn't found and the first item applies. + const int index = combo_box->findData(combo_is_image_mode_ ? last_image_selection : last_selection); + combo_box->setCurrentIndex(index >= 0 ? index : 0); +} + +void JFJochViewerDatasetInfo::SaveFavourite() { + if (!dataset) + return; + QSettings settings("PSI", "jfjoch_viewer"); + settings.beginGroup(FavouriteGroup(dataset->experiment.GetGridScan().has_value())); + settings.setValue("metric", last_selection); + settings.setValue("imagePlot", last_image_selection); + settings.setValue("perImage", image_button->isChecked()); + settings.setValue("grid", grid_button->isChecked()); +} + +void JFJochViewerDatasetInfo::resetPlotDefaults() { + user_picked_ = false; + image_button->setChecked(false); + // A grid scan starts on its 2D map, like a first load with nothing saved. + grid_button->setChecked(dataset && dataset->experiment.GetGridScan().has_value()); + UpdateLabels(); // rebuild the combo for per-dataset mode + last_selection = 0; // default selections, after UpdateLabels captured the old ones + last_image_selection = 0; + RestoreSelection(); + UpdatePlot(); + UpdateView(); +} + +void JFJochViewerDatasetInfo::ApplyFavourite(bool grid_scan) { + QSettings settings("PSI", "jfjoch_viewer"); + settings.beginGroup(FavouriteGroup(grid_scan)); + image_button->setChecked(settings.value("perImage", false).toBool()); + // With nothing saved, a grid scan starts on its 2D map. + grid_button->setChecked(settings.value("grid", grid_scan).toBool()); + // ModeChanged's sequence, with the saved codes injected after UpdateLabels has captured the + // outgoing selection - the other way round the capture would overwrite them. + UpdateLabels(); + last_selection = settings.value("metric", last_selection).toInt(); + last_image_selection = settings.value("imagePlot", last_image_selection).toInt(); + RestoreSelection(); + if (combo_is_image_mode_) + comboBoxSelected(combo_box->currentIndex()); + else + UpdatePlot(); + UpdateView(); } void JFJochViewerDatasetInfo::ModeChanged() { @@ -151,7 +208,7 @@ void JFJochViewerDatasetInfo::UpdateLabels() { QSignalBlocker bl(combo_box); if (combo_box->count() > 0) - (combo_is_image_mode_ ? last_image_selection : last_selection) = combo_box->currentIndex(); + (combo_is_image_mode_ ? last_image_selection : last_selection) = combo_box->currentData().toInt(); combo_box->clear(); combo_is_image_mode_ = image_button && image_button->isChecked(); @@ -218,6 +275,16 @@ void JFJochViewerDatasetInfo::UpdateLabels() { void JFJochViewerDatasetInfo::datasetLoaded(std::shared_ptr dataset) { this->dataset = dataset; + // The first dataset of a kind (grid scan / standard) starts from the saved favourite for that + // kind - the user's last explicit plot choice and toggle states on such a dataset. + if (dataset) { + const bool grid_scan = dataset->experiment.GetGridScan().has_value(); + if (favourite_kind_ != grid_scan) { + favourite_kind_ = grid_scan; + ApplyFavourite(grid_scan); // rebuilds the combo for the favourite's mode and re-plots + return; + } + } // Per-image mode: the combo holds plot types and the chart follows the displayed image, so a // new dataset must not repopulate the combo or run the per-dataset plot. if (image_button && image_button->isChecked()) { @@ -355,8 +422,6 @@ void JFJochViewerDatasetInfo::UpdatePlot() { if (dataset->experiment.GetGridScan()) { grid_scan_image->loadData(data, dataset->experiment.GetGridScan().value(), one_over_d2); grid_button->setEnabled(true); - if (!image_button->isChecked()) - grid_button->setChecked(true); } else { grid_scan_image->clear(); grid_button->setEnabled(false); diff --git a/viewer/JFJochViewerDatasetInfo.h b/viewer/JFJochViewerDatasetInfo.h index 81c9bd433..f966b79d2 100644 --- a/viewer/JFJochViewerDatasetInfo.h +++ b/viewer/JFJochViewerDatasetInfo.h @@ -7,6 +7,8 @@ #include #include +#include + #include "charts/JFJochDatasetInfoChartView.h" #include "../reader/JFJochReader.h" #include "image_viewer/JFJochGridScanImage.h" @@ -34,9 +36,14 @@ class JFJochViewerDatasetInfo : public QWidget { QPushButton *grid_button = nullptr; QPushButton *image_button = nullptr; // toggle: show per-image profiles instead of the metric - int last_selection = 0; // last per-dataset metric, by combo index - int last_image_selection = 0; // last per-image plot type, by combo index + int last_selection = 0; // last per-dataset metric, by combo data code + int last_image_selection = 0; // last per-image plot type, by combo data code bool combo_is_image_mode_ = false; // which of the two the combo currently lists + // Dataset kind (grid scan or not) whose saved favourite is applied; grid scans and standard + // scans each remember their own plot choice and toggle states across viewer restarts. + std::optional favourite_kind_; + void SaveFavourite(); // persist the current choice for the loaded dataset's kind + void ApplyFavourite(bool grid_scan); // apply the saved choice for that kind and re-plot void UpdatePlot(); // Rebuild the combo for whichever mode the toggles now select and re-plot. Every mode switch // must go through this. @@ -70,6 +77,8 @@ public slots: void liveRunUpdated(std::shared_ptr dataset); // Connected to / disconnected from a live (HTTP) source. void setHttpConnection(bool connected, QString addr = QString()); + // "Reset all settings to defaults": back to the state a first load of this dataset would show. + void resetPlotDefaults(); }; diff --git a/viewer/JFJochViewerMenu.cpp b/viewer/JFJochViewerMenu.cpp index 603341f41..9991ba8b6 100644 --- a/viewer/JFJochViewerMenu.cpp +++ b/viewer/JFJochViewerMenu.cpp @@ -78,6 +78,8 @@ JFJochViewerMenu::JFJochViewerMenu(QWidget *parent) : QMenuBar(parent) { viewMenu->addSeparator(); const QAction *resetLayout = viewMenu->addAction("Reset layout"); connect(resetLayout, &QAction::triggered, this, &JFJochViewerMenu::resetLayoutSelected); + const QAction *resetSettings = viewMenu->addAction("Reset all settings to defaults"); + connect(resetSettings, &QAction::triggered, this, &JFJochViewerMenu::resetSettingsSelected); viewMenu->addSeparator(); // Auto-detected from the session (ssh -X and the like); this toggle is the manual override. QAction *remoteMode = viewMenu->addAction("Remote display mode (limit repaints)"); @@ -202,7 +204,9 @@ void JFJochViewerMenu::closeSelected() { } void JFJochViewerMenu::quitSelected() { - QApplication::quit(); + // Through close(), not QApplication::quit(): closeEvent is where the persistent settings + // are saved, and quit() would bypass it. + window()->close(); } diff --git a/viewer/JFJochViewerMenu.h b/viewer/JFJochViewerMenu.h index 82b926716..d8952bc76 100644 --- a/viewer/JFJochViewerMenu.h +++ b/viewer/JFJochViewerMenu.h @@ -50,6 +50,7 @@ signals: void imageLayoutSelected(); void processingLayoutSelected(); void resetLayoutSelected(); + void resetSettingsSelected(); private slots: void aboutSelected(); diff --git a/viewer/JFJochViewerWindow.cpp b/viewer/JFJochViewerWindow.cpp index 03610b8ed..1c5fb8861 100644 --- a/viewer/JFJochViewerWindow.cpp +++ b/viewer/JFJochViewerWindow.cpp @@ -120,7 +120,7 @@ JFJochViewerWindow::JFJochViewerWindow(QWidget *parent, bool dbus, const QString // Central area: the diffraction image. Everything else (inspector, plots, processing) is a // dock, so the layout can be rearranged, saved, and switched between perspectives. - auto viewer = new JFJochDiffractionImage(this); + viewer = new JFJochDiffractionImage(this); viewer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); setCentralWidget(viewer); @@ -406,7 +406,7 @@ JFJochViewerWindow::JFJochViewerWindow(QWidget *parent, bool dbus, const QString // --- Magnifier --- // The magnifier shows the frame the main view has already rendered - the same pixels with // its own zoom and centre - so it neither converts nor colours anything itself. - connect(viewer, &JFJochImage::frameRendered, magnifierWindow, [viewer, magnifierWindow] { + connect(viewer, &JFJochImage::frameRendered, magnifierWindow, [this, magnifierWindow] { magnifierWindow->setFrame(viewer->Frame()); }); @@ -569,6 +569,7 @@ JFJochViewerWindow::JFJochViewerWindow(QWidget *parent, bool dbus, const QString [this] { ApplyPerspective(Perspective::Processing); }); connect(menuBar, &JFJochViewerMenu::resetLayoutSelected, this, [this] { if (!defaultLayoutState.isEmpty()) restoreState(defaultLayoutState, kLayoutVersion); }); + connect(menuBar, &JFJochViewerMenu::resetSettingsSelected, this, &JFJochViewerWindow::ResetAllSettings); // Tear-off floating is disabled for all docks: a floated QDockWidget is unreliable across platforms // (on WSLg it becomes an off-screen, override-redirect window that can't be focused or recovered, so @@ -621,6 +622,36 @@ void JFJochViewerWindow::ApplyPerspective(Perspective p) { d->setVisible(processing); } +void JFJochViewerWindow::ResetAllSettings() { + const auto reply = QMessageBox::question( + this, "Reset all settings", + "Reset all viewer settings to defaults - window layout, display settings, plot choices " + "and the file manager root?", + QMessageBox::Yes | QMessageBox::No, QMessageBox::No); + if (reply != QMessageBox::Yes) + return; + QSettings("PSI", "jfjoch_viewer").clear(); + + // Bring the running session to the state a first start builds, so normal saving on close is + // correct again afterwards. Same calls as the constructor, in the same order. + if (!defaultLayoutState.isEmpty()) + restoreState(defaultLayoutState, kLayoutVersion); + showNormal(); + const QRect avail = QGuiApplication::primaryScreen()->availableGeometry(); + resize(qMin(1200, avail.width() - 100), qMin(1100, avail.height() - 100)); + + viewer->setColorMap(static_cast(ColorScaleEnum::Indigo)); + toolBarDisplay->updateColorMap(static_cast(ColorScaleEnum::Indigo)); + viewer->setAutoForeground(false); // emits autoForegroundChanged -> toolbar button state + viewer->setHDRMode(false); + toolBarDisplay->updateHDRMode(false); + + for (auto *info : findChildren()) + info->resetPlotDefaults(); + for (auto *browser : findChildren()) + browser->ResetToDefaultRoot(); +} + void JFJochViewerWindow::closeEvent(QCloseEvent *event) { // Persist the dock/toolbar arrangement and window geometry so the next launch resumes it. QSettings settings("PSI", "jfjoch_viewer"); diff --git a/viewer/JFJochViewerWindow.h b/viewer/JFJochViewerWindow.h index b54b02bde..71dc4dac0 100644 --- a/viewer/JFJochViewerWindow.h +++ b/viewer/JFJochViewerWindow.h @@ -16,6 +16,7 @@ #include "toolbar/JFJochViewerToolbarDisplay.h" class JFJochProcessingJobsWindow; +class JFJochDiffractionImage; class QDockWidget; class JFJochViewerWindow : public QMainWindow { @@ -29,6 +30,7 @@ public: private: JFJochViewerMenu *menuBar; JFJochImageReadingWorker *reading_worker; + JFJochDiffractionImage *viewer; // central diffraction image JFJochViewerToolbarDisplay *toolBarDisplay; JFJochViewerStatusBar *statusbar; JFJochProcessingJobsWindow *processingJobsWindow; @@ -55,6 +57,8 @@ private: QByteArray defaultLayoutState; // captured after construction, for "Reset layout" int datasetInfoCounter = 0; // gives each dataset-info dock a unique objectName + void ResetAllSettings(); + QThread *reading_thread; // Named layouts. Image = just the image + inspector; Processing = also the plots + jobs panel. diff --git a/viewer/widgets/JFJochViewerFileBrowser.cpp b/viewer/widgets/JFJochViewerFileBrowser.cpp index 574140eaa..8c9660159 100644 --- a/viewer/widgets/JFJochViewerFileBrowser.cpp +++ b/viewer/widgets/JFJochViewerFileBrowser.cpp @@ -113,6 +113,10 @@ void JFJochViewerFileBrowser::SetRoot(const QString &path) { QSettings("PSI", "jfjoch_viewer").setValue(kSettingsKey, canonical); } +void JFJochViewerFileBrowser::ResetToDefaultRoot() { + SetRoot(DefaultRoot()); +} + void JFJochViewerFileBrowser::onBrowseClicked() { const QString dir = QFileDialog::getExistingDirectory(this, "Select data root", root_edit_->text()); if (!dir.isEmpty()) diff --git a/viewer/widgets/JFJochViewerFileBrowser.h b/viewer/widgets/JFJochViewerFileBrowser.h index e1348597b..90630b065 100644 --- a/viewer/widgets/JFJochViewerFileBrowser.h +++ b/viewer/widgets/JFJochViewerFileBrowser.h @@ -29,6 +29,10 @@ class JFJochViewerFileBrowser : public QWidget { void SetRoot(const QString &path); [[nodiscard]] static QString DefaultRoot(); +public slots: + // "Reset all settings to defaults": back to the root a fresh start would pick. + void ResetToDefaultRoot(); + private slots: void onBrowseClicked(); void onRootEditingFinished(); From 8c4d9914470895b49fd4e37159479f4885e92098 Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Sun, 13 Sep 2026 10:24:36 +0200 Subject: [PATCH 3/3] viewer: the spot count takes the lower band of the composite plot Swapped which curve occupies which half of the spots + background plot: the spot count now sits in the lower band with its axis floor at its natural minimum (zero), and the background in the upper band with its axis floor pushed down instead. A spot count below zero is nonsense and its axis never shows one now; a background below zero is at least conceivable on an integrating detector, so that is the axis that carries the inflated range. Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01WbjnQhutnboy4qbxwmgDAX --- viewer/charts/JFJochDatasetInfoChartView.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/viewer/charts/JFJochDatasetInfoChartView.cpp b/viewer/charts/JFJochDatasetInfoChartView.cpp index 7f35229b6..eb1e0876f 100644 --- a/viewer/charts/JFJochDatasetInfoChartView.cpp +++ b/viewer/charts/JFJochDatasetInfoChartView.cpp @@ -454,8 +454,10 @@ void JFJochDatasetInfoChartView::buildTimeDomainChart() { // Secondary quantity: same x, its own Y axis on the LEFT (the primary then reads on the // RIGHT), so a small background value is not flattened by a spot count three orders of // magnitude larger. Each axis is ranged from its own series alone; on top of that the - // secondary's max and the primary's min are each inflated by that series' own span, so the - // secondary curve occupies the lower half of the plot and the primary the upper half. A + // primary's max and the secondary's min are each inflated by that series' own span, so the + // primary (spot count) curve occupies the lower half of the plot and the secondary the + // upper half. That way it is the background axis whose floor gets pushed down - a spot + // count below zero is nonsense, a background below zero is at least conceivable. A // secondary never combines with the 1/d^2 layout. if (secondary_.has_value() && !m_yOneOverD) { auto *line = new QLineSeries(this); @@ -471,7 +473,7 @@ void JFJochDatasetInfoChartView::buildTimeDomainChart() { if (std::isfinite(secMin) && std::isfinite(secMax)) { const double lo = m_minYZeroEnabled ? 0.0 : secMin; const double hi = (secMax > lo) ? secMax : (lo + 1.0); - axisY2->setRange(lo, lo + 2.0 * (hi - lo)); // lower half + axisY2->setRange(hi - 2.0 * (hi - lo), hi); // upper half } chart()->addAxis(axisY2, Qt::AlignLeft); line->attachAxis(axisY2); @@ -479,8 +481,8 @@ void JFJochDatasetInfoChartView::buildTimeDomainChart() { if (ax->orientation() == Qt::Horizontal) line->attachAxis(ax); if (axisY) - axisY->setRange(axisY->max() - 2.0 * (axisY->max() - axisY->min()), - axisY->max()); // upper half + axisY->setRange(axisY->min(), + axisY->min() + 2.0 * (axisY->max() - axisY->min())); // lower half // Each axis carries its series' colour on labels and axis line, so it is clear at a // glance which axis reads which curve. if (secondary_->color.isValid()) {