Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-77225

QAbstractItemModelReplica synchronization

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Reported
    • Priority: Not Evaluated
    • Resolution: Unresolved
    • Affects Version/s: 5.13.0
    • Fix Version/s: None
    • Component/s: Remote Objects
    • Labels:
      None
    • Platform/s:
      All
    • Technical Risk:
      Normal

      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

       

        Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            bstottle Brett Stottlemyer
            Reporter:
            chrisser Suli Sahne
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:

                Gerrit Reviews

                There are no open Gerrit changes