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

QStringListModel should reimplement setItemData

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P4: Low
    • 5.13
    • 5.11.0
    • Core: Item Models
    • None
    • 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

            VRonin Luca
            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