|
Aria 2.0.0
C++23 MVVM framework (C++20 minimum) — reactive, coroutine-first, ABI-layered
|
Classes | |
| class | ObservableListModel |
| class | QtAdapter |
| Qt6 implementation of IViewAdapter. More... | |
| class | QtDispatcher |
| class | QtView |
| Wraps any QWidget* (or QObject*) as an IView. More... | |
Functions | |
| template<typename Key, typename KeyFromData> | |
| Subscription | bind_combo_box_selection (Property< std::optional< Key > > &selected, QComboBox &combo, KeyFromData key_from_data, int role=Qt::UserRole) |
| Bind a ViewModel's stable selected ID to a QComboBox's existing model. | |
|
nodiscard |
Bind a ViewModel's stable selected ID to a QComboBox's existing model.
key_from_data(const QVariant&) returns Key from the given item-data role; it must be side-effect-free, with a unique ID for every option. Conversion failures during callbacks are reported through the callback failure sink; exceptions never escape into Qt's event loop. Initial synchronization errors propagate to the caller of this function. Labels may be duplicated. ObservableListModel can supply the options directly, including a FilteredList or another derived list source.
The Property is authoritative at bind time. nullopt displays no row; an unknown ID also displays no row but remains pending until its option arrives. Removing/replacing an option whose ID was selected clears the Property; reordering rows or replacing a row with the same ID keeps it.
Only user activation writes back to the Property. Programmatic changes must write the Property, rather than call setCurrentIndex on the widget. This prevents Qt's automatic row selection during model changes from writing an unintended ID back into the ViewModel.
Call and release on the widget/model's Qt owner thread, which must also be the Property's graph thread. Keep the Property and model/source alive until the binding is released (or the combo is destroyed). Set the model before binding; replacing the widget's model requires releasing and rebinding. Releasing the returned Subscription disconnects both directions; destroying the combo first is also safe.