Hi,
I’m trying to implement following case:
There is 2d table with values. I need to implement UI for viewing data and editing it.
To simplify synchronisation between edits from UI and table updates coming from the back-end, I want model to store uncommitted edited values and expose a couple of methods to accept/reject pending changes.
From what I understand this is reasonably easy to do with QtWidgets + models:
Base model on QAbstractTableModel
Add a few extra roles for storing/querying pending changes, etc.
Use QTableView with custom item delegate, which can query model whether cell is editable, show uncommitted changes, etc.
But I’m puzzled about how to implement it QtQuick.Controls.TableView.
From my experiments, TableView doesn’t work with QAbstractTableModel — it iterates over the first column of the model and uses roles to simulate second dimension.
Is there a way to make TableView work with QAbstractTableModel correctly?
As an alternative — I can change model to use roles for columns, but I’m not sure how to handle other aspects of cell data (modified flag, uncommited value, etc.). The only idea I have so far is to return composite (dictionary) value for each cell. E.g. return QMap<QString, QVariant> or QJsonObject as a value of “cell” and interpret it on QML side.
Are there any other ways to do it?
What’s more effective if I decide to implement my second solution — QMap or QJsonObject?
↧