Files
Jungfraujoch/viewer/widgets/PowderCalibrationWidget.h
T
leonarski_fandClaude Opus 5.5 9cf987cd4e jfjoch_viewer: live updates no longer rebuild open combo boxes
During a collection every dataset tick ran JFJochViewerDatasetInfo::UpdateLabels(), which
clear()ed the plot-type combo and re-added every item, so an open dropdown lost its hovered
row and scroll position on each tick and picking a plot type was a race against the next
update. The same clear-and-refill ran per tick or per image in the calibration window's
calibration combo, the ROI list combo and the powder calibrant combo; the last two also
threw away the user's choice (the calibrant was reset to the first entry on every image).

New LiveComboBox::SetItems() takes the full item list and leaves the combo untouched when the
list is unchanged. When it does change while the popup is open, the change is held back and
applied (queued) once the popup window hides, so a click that closes the popup lands first.
A replacement keeps the selection by item data, blocks signals, and a held-back one emits
itemsReplaced() so the owner can re-plot.

The calibration window now re-shows the selected calibration on a dataset tick instead of
always reloading the pixel mask over it.

Tested offscreen: a timer fires datasetLoaded() every 25 ms while the dropdown is open; the
popup and hovered row survive, newly available indexing metrics are held back until the popup
closes, and the picked type sticks and is what the chart plots. The rc175 code fails the
hover checks of the same harness.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-12 19:46:48 +02:00

54 lines
2.2 KiB
C++

// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include <QWidget>
#include <gemmi/symmetry.hpp>
#include <QCheckBox>
#include <QComboBox>
#include <QVector>
#include "../../common/UnitCell.h"
#include "../../reader/JFJochReaderImage.h"
#include "../../image_analysis/geom_refinement/PowderCalibration.h" // CalibrationMethod
#include "LiveComboBox.h"
// What a whole-dataset calibration run is set to. The analysis library takes the calibrant as a ring
// list rather than a name (ice has no cell to enumerate rings from), so the name is resolved here.
struct CalibrationSelection {
QString name;
std::vector<float> ring_q; // q = 2*pi/d [1/A], ascending
CalibrationMethod method = CalibrationMethod::Rings;
bool refine_tilt = true; // false pins rot1/rot2 where they are (a calibration meant for XDS)
};
// Detector geometry from a powder standard: the calibrant, and how its rings are measured. The two
// buttons fit the image currently on screen; "Analyze dataset" reads Selection() and fits the whole
// dataset the same way rugnux --mode calibration does.
class PowderCalibrationWidget : public QWidget {
Q_OBJECT
std::optional<UnitCell> sample_cell;
// Taken with the cell, and used with it: the ring list a user-supplied cell produces has to carry
// the group's absences, or the fit pairs the innermost OBSERVED ring with a forbidden one.
std::optional<gemmi::SpaceGroup> sample_sg;
LiveComboBox* calibrantCombo{nullptr}; // stores current calibrant selection
QComboBox* methodCombo{nullptr}; // rings / spots, for the whole-dataset run
QCheckBox* refineTiltCheck{nullptr};// fit the detector tilt, or hold it where it is
std::vector<float> GetCalibrantRings() const;
void updateCalibrantList();
signals:
void ringsFromCalibration(QVector<float> v);
void findBeamCenter(QVector<float> ring_q, bool guess, bool refine_tilt);
public:
PowderCalibrationWidget(QWidget* parent);
CalibrationSelection Selection() const;
public slots:
void loadImage(std::shared_ptr<const JFJochReaderImage> image);
private slots:
void findBeamCenterClicked();
void optimizeBeamCenterClicked();
};