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

QStringListModel should reimplement setItemData

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4: Low
    • Resolution: Done
    • Affects Version/s: 5.11.0
    • Fix Version/s: 5.13
    • Component/s: Core: Item Models
    • Labels:
      None
    • Commits:
      Ibaea17530f15627a3cb8003e5284e54001731ded

      Description

      QStringListModel currently does not reimplement setItemData this causes

      QMap<int,QVariant> itemData;
      itemData.insert(Qt::DisplayRole,5);
      itemData.insert(Qt::EditRole,2);
      stringListModel->setItemData(stringListModel->index(0,0),itemData);

       to emit dataChanged twice.

       A possible implementation that fixes the problem would be

      bool QStringListModel::setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles){
          auto roleIter = roles.find(Qt::EditRole);
          if(roleIter==roles.end()){
              roleIter = roles.find(Qt::DisplayRole);
              if(roleIter==roles.end())
                  return false;
          }
          return setData(index,roleIter.value(),roleIter.key());
      }

        Attachments

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

          Activity

            People

            Assignee:
            VRonin Luca
            Reporter:
            VRonin Luca
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes