// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute // SPDX-License-Identifier: GPL-3.0-only #pragma once #include #include #include #include // A combo box whose items are refreshed by live updates. SetItems() leaves the items alone when // they are unchanged, and while the popup is open it holds the change back until the popup has // closed, so a live update never closes the dropdown or moves the selection under the user. // Replacing the items keeps the selection by item data (the first item when it is gone) and emits // no currentIndexChanged; a replacement held back over an open popup emits itemsReplaced() instead. class LiveComboBox : public QComboBox { Q_OBJECT public: struct Item { QString text; QVariant data; QString tooltip; QColor swatch; // shown as a small square icon when valid bool separator = false; bool operator==(const Item &other) const = default; }; explicit LiveComboBox(QWidget *parent = nullptr); // True if the items were replaced now; false if unchanged or held back for an open popup. bool SetItems(const QVector &items); signals: void itemsReplaced(); private: QVector items_; std::optional> pending_; void Replace(const QVector &items); void ApplyPending(); bool eventFilter(QObject *watched, QEvent *event) override; };