--- a/ui/qt/model.h Sat Apr 05 17:57:04 2025 +0200 +++ b/ui/qt/model.h Sun Jul 20 22:04:39 2025 +0200 @@ -40,5 +40,80 @@ #include <QItemSelectionModel> + +class ListModel : public QAbstractListModel { + Q_OBJECT + + ui_getvaluefunc2 getvalue; + void *getvaluedata; + ui_callback onactivate; + void *onactivatedata; + ui_callback onselection; + void *onselectiondata; + +public: + UiObject *obj; + UiVar *var; + QListView *view; + + ListModel(UiObject *obj, QListView *view, UiVar *var, ui_getvaluefunc2 getvalue, void *getvaluedata); + + void setActivationCallback(ui_callback f, void *userdata); + void setSelectionCallback(ui_callback f, void *userdata); + + void update(int row); + + int rowCount(const QModelIndex &parent = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + +public slots: + void selectionChanged( + const QItemSelection & selected, + const QItemSelection & deselected); +}; + +class TableModel : public QAbstractListModel { + Q_OBJECT + + UiModel *model; + ui_callback onactivate; + void *onactivatedata; + ui_callback onselection; + void *onselectiondata; + +public: + UiObject *obj; + UiVar *var; + QTreeView *view; + + TableModel(UiObject *obj, QTreeView *view, UiVar *var, UiModel *model); + + void setActivationCallback(ui_callback f, void *userdata); + void setSelectionCallback(ui_callback f, void *userdata); + + void update(int row); + + int rowCount(const QModelIndex &parent = QModelIndex()) const; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + QVariant headerData(int section, Qt::Orientation orientation, int role) const; + +public slots: + void selectionChanged( + const QItemSelection & selected, + const QItemSelection & deselected); +}; + + +UiListSelection ui_selection_model_to_selection(QItemSelectionModel *model); + +extern "C" { + + void ui_listmodel_update(UiList *list, int row); + void ui_listmodel_setselection(UiList *list, UiListSelection sel); + UiListSelection ui_listmodel_getselection(UiList *list); + +} + #endif /* MODEL_H */