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>
This commit is contained in:
leonarski_fandClaude Opus 5.5 committed 2026-10-12 19:46:48 +02:00
1 parent 83b1d85400
commit 9cf987cd4e
11 files changed
+204 -72

No files matched your search

+45 -36
View File
@@ -40,7 +40,7 @@ namespace {
JFJochViewerDatasetInfo::JFJochViewerDatasetInfo(QWidget *parent) : QWidget(parent) {
auto layout = new QGridLayout(this);
combo_box = new QComboBox(this);
combo_box = new LiveComboBox(this);
layout->addWidget(combo_box, 0, 0);
@@ -117,6 +117,16 @@ JFJochViewerDatasetInfo::JFJochViewerDatasetInfo(QWidget *parent) : QWidget(pare
SaveFavourite();
});
// Items held back while the dropdown was open went in once it closed: re-apply the selection
// rules and re-plot, as after any other rebuild.
connect(combo_box, &LiveComboBox::itemsReplaced, this, [this] {
RestoreSelection();
if (combo_is_image_mode_)
comboBoxSelected(combo_box->currentIndex());
else
UpdatePlot();
});
connect(grid_scan_image, &JFJochGridScanImage::imageSelected,
this, &JFJochViewerDatasetInfo::imageSelectedInChart);
@@ -249,32 +259,32 @@ void JFJochViewerDatasetInfo::changeEvent(QEvent *event) {
}
void JFJochViewerDatasetInfo::UpdateLabels() {
QSignalBlocker bl(combo_box);
if (combo_box->count() > 0)
(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();
// Built in full and handed over as one list: the combo only changes when the list does, so the
// live updates that call this on every tick leave an open dropdown and the selection alone.
QVector<LiveComboBox::Item> items;
auto add = [&items](const QString &text, int code) { items.push_back({text, code}); };
auto separator = [&items] { items.push_back({.separator = true}); };
// In per-image mode the one combo selects which per-image profile to show (no second combo).
if (combo_is_image_mode_) {
for (const auto &pt : JFJochViewerSidePanelChart::PlotTypes())
combo_box->addItem(pt.first, pt.second);
return;
}
if (this->dataset) {
combo_box->addItem("Background estimate", 0);
add(pt.first, pt.second);
} else if (this->dataset) {
add("Background estimate", 0);
if (!dataset->experiment.GetGridScan().has_value())
combo_box->addItem("Spots + background", SPOTS_PLUS_BACKGROUND);
combo_box->addItem("Ice ring score", 14);
combo_box->addItem("Spindle blind fraction", 15);
combo_box->addItem("Resolution estimate", 7);
combo_box->addItem("Spot count", 1);
combo_box->addItem("Spot count (indexed)", 2);
combo_box->addItem("Spot count (ice rings)", 3);
combo_box->addItem("Spot count (low res.)", 4);
add("Spots + background", SPOTS_PLUS_BACKGROUND);
add("Ice ring score", 14);
add("Spindle blind fraction", 15);
add("Resolution estimate", 7);
add("Spot count", 1);
add("Spot count (indexed)", 2);
add("Spot count (ice rings)", 3);
add("Spot count (low res.)", 4);
// Offer indexing/scaling metrics if the active run, any overlay run, or the live run has them.
bool has_indexing = !dataset->indexing_result.empty();
@@ -290,31 +300,30 @@ void JFJochViewerDatasetInfo::UpdateLabels() {
}
if (has_indexing) {
combo_box->insertSeparator(1000);
combo_box->addItem("Indexing result", 5);
combo_box->addItem("Profile radius", 6);
combo_box->addItem("B-factor", 8);
combo_box->addItem("Mosaicity", 9);
combo_box->addItem("Integrated reflections", 12);
combo_box->addItem("Indexing lattice count", 13);
separator();
add("Indexing result", 5);
add("Profile radius", 6);
add("B-factor", 8);
add("Mosaicity", 9);
add("Integrated reflections", 12);
add("Indexing lattice count", 13);
}
if (has_scale) {
combo_box->insertSeparator(1000);
combo_box->addItem("Scale factor", 10);
combo_box->addItem("CC", 11);
separator();
add("Scale factor", 10);
add("CC", 11);
}
for (int i = 0; i < this->dataset->roi.size(); i++) {
std::string name = std::string("ROI ") + this->dataset->roi[i];
combo_box->insertSeparator(1000);
combo_box->addItem(QString::fromStdString(name + " mean"), 100 + i * 4);
combo_box->addItem(QString::fromStdString(name + " sum"), 100 + i * 4 + 1);
combo_box->addItem(QString::fromStdString(name + " weighted x"), 100 + i * 4 + 2);
combo_box->addItem(QString::fromStdString(name + " weighted y"), 100 + i * 4 + 3);
const QString name = QString::fromStdString("ROI " + this->dataset->roi[i]);
separator();
add(name + " mean", 100 + i * 4);
add(name + " sum", 100 + i * 4 + 1);
add(name + " weighted x", 100 + i * 4 + 2);
add(name + " weighted y", 100 + i * 4 + 3);
}
} else {
combo_box->clear();
}
combo_box->SetItems(items);
}