Details
-
Task
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
5.13.0
-
None
Description
I use a QStandardItemModel with several "layers" as Remote Object. After calling acquireModel I wait for the initialized signal and connect to the dataChanged signal to wait for the data of the items of the first layer.
auto model = node.acquireModel("MyModel"); QObject::connect(model, &QAbstractItemModelReplica::initialized, [model]() { QObject::connect(model, &QAbstractItemModelReplica::dataChanged, [model](const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles) { auto indices = onDataChanged(*model, topLeft, bottomRight, roles); for (const auto& index : indices) request(*model, index); // --> request the items of the next layer }); request(*model); // --> request items of the first layer });
But when the request is called for the items of the next layer, rowCount and columnCount are always 0.
void request(const QAbstractItemModelReplica& model, const QModelIndex& parentIndex = {}) { int rowCount = model.rowCount(parentIndex); int colCount = model.columnCount(parentIndex); if (rowCount == 0 && colCount == 0) { qDebug() << "empty"; // --> if parentIndex is not empty rowCount and colCount are 0 return; } for (int row = 0; row != rowCount; row++) { for (int col = 0; col != colCount; col++) { QModelIndex idx = model.index(row, col, parentIndex); model.data(idx, Qt::UserRole + 1); // request the data } } }
onDataChanged prints the data and returns the parent indices for the next request:
QVector<QModelIndex> onDataChanged(QAbstractItemModelReplica& model, const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles) { QVector<QModelIndex> indices; QModelIndex parentIndex = topLeft.parent(); for (int row = topLeft.row(); row <= bottomRight.row(); row++) { for (int col = topLeft.column(); col <= bottomRight.column(); col++) { for (int role : roles) { QModelIndex idx = model.index(row, col, parentIndex); QVariant value = model.data(idx, role); qDebug() << value.toString(); indices.append(idx); } } } return indices; }
Actually I would need a rowCountChanged or a columnCountChanged signal now, or is there another possibility?
Code: https://gitlab.com/sulisahne/replicatedstandarditemmodel