From fd9b0b86bb5f78ffa855409c4dd5976505ef83f5 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Mon, 6 Jan 2020 12:26:43 +0100 Subject: Don't mix QHash and QMultiHash MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I8a6ec788f995ef2609e971e0a2f330973975657a Reviewed-by: MÃ¥rten Nordheim --- src/corelib/itemmodels/qabstractitemmodel.cpp | 28 +++++++++++---------------- 1 file changed, 11 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/corelib/itemmodels/qabstractitemmodel.cpp b/src/corelib/itemmodels/qabstractitemmodel.cpp index 3be56f5fe6..3bcd81bcdf 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.cpp +++ b/src/corelib/itemmodels/qabstractitemmodel.cpp @@ -63,7 +63,7 @@ QPersistentModelIndexData *QPersistentModelIndexData::create(const QModelIndex & Q_ASSERT(index.isValid()); // we will _never_ insert an invalid index in the list QPersistentModelIndexData *d = nullptr; QAbstractItemModel *model = const_cast(index.model()); - QHash &indexes = model->d_func()->persistent.indexes; + QMultiHash &indexes = model->d_func()->persistent.indexes; const auto it = indexes.constFind(index); if (it != indexes.cend()) { d = (*it); @@ -662,8 +662,7 @@ void QAbstractItemModelPrivate::rowsAboutToBeInserted(const QModelIndex &parent, Q_UNUSED(last); QVector persistent_moved; if (first < q->rowCount(parent)) { - for (QHash::const_iterator it = persistent.indexes.constBegin(); - it != persistent.indexes.constEnd(); ++it) { + for (auto it = persistent.indexes.constBegin(); it != persistent.indexes.constEnd(); ++it) { QPersistentModelIndexData *data = *it; const QModelIndex &index = data->index; if (index.row() >= first && index.isValid() && index.parent() == parent) { @@ -699,14 +698,13 @@ void QAbstractItemModelPrivate::itemsAboutToBeMoved(const QModelIndex &srcParent QVector persistent_moved_in_source; QVector persistent_moved_in_destination; - QHash::const_iterator it; - const QHash::const_iterator begin = persistent.indexes.constBegin(); - const QHash::const_iterator end = persistent.indexes.constEnd(); + const auto begin = persistent.indexes.constBegin(); + const auto end = persistent.indexes.constEnd(); const bool sameParent = (srcParent == destinationParent); const bool movingUp = (srcFirst > destinationChild); - for ( it = begin; it != end; ++it) { + for (auto it = begin; it != end; ++it) { QPersistentModelIndexData *data = *it; const QModelIndex &index = data->index; const QModelIndex &parent = index.parent(); @@ -811,8 +809,7 @@ void QAbstractItemModelPrivate::rowsAboutToBeRemoved(const QModelIndex &parent, QVector persistent_invalidated; // find the persistent indexes that are affected by the change, either by being in the removed subtree // or by being on the same level and below the removed rows - for (QHash::const_iterator it = persistent.indexes.constBegin(); - it != persistent.indexes.constEnd(); ++it) { + for (auto it = persistent.indexes.constBegin(); it != persistent.indexes.constEnd(); ++it) { QPersistentModelIndexData *data = *it; bool level_changed = false; QModelIndex current = data->index; @@ -867,8 +864,7 @@ void QAbstractItemModelPrivate::columnsAboutToBeInserted(const QModelIndex &pare Q_UNUSED(last); QVector persistent_moved; if (first < q->columnCount(parent)) { - for (QHash::const_iterator it = persistent.indexes.constBegin(); - it != persistent.indexes.constEnd(); ++it) { + for (auto it = persistent.indexes.constBegin(); it != persistent.indexes.constEnd(); ++it) { QPersistentModelIndexData *data = *it; const QModelIndex &index = data->index; if (index.column() >= first && index.isValid() && index.parent() == parent) @@ -904,8 +900,7 @@ void QAbstractItemModelPrivate::columnsAboutToBeRemoved(const QModelIndex &paren QVector persistent_invalidated; // find the persistent indexes that are affected by the change, either by being in the removed subtree // or by being on the same level and to the right of the removed columns - for (QHash::const_iterator it = persistent.indexes.constBegin(); - it != persistent.indexes.constEnd(); ++it) { + for (auto it = persistent.indexes.constBegin(); it != persistent.indexes.constEnd(); ++it) { QPersistentModelIndexData *data = *it; bool level_changed = false; QModelIndex current = data->index; @@ -3376,8 +3371,7 @@ QModelIndexList QAbstractItemModel::persistentIndexList() const Q_D(const QAbstractItemModel); QModelIndexList result; result.reserve(d->persistent.indexes.count()); - for (QHash::const_iterator it = d->persistent.indexes.constBegin(); - it != d->persistent.indexes.constEnd(); ++it) { + for (auto it = d->persistent.indexes.constBegin(); it != d->persistent.indexes.constEnd(); ++it) { QPersistentModelIndexData *data = *it; result.append(data->index); } @@ -3995,8 +3989,8 @@ bool QAbstractListModel::dropMimeData(const QMimeData *data, Qt::DropAction acti */ void QAbstractItemModelPrivate::Persistent::insertMultiAtEnd(const QModelIndex& key, QPersistentModelIndexData *data) { - QHash::iterator newIt = indexes.insert(key, data); - QHash::iterator it = newIt; + auto newIt = indexes.insert(key, data); + auto it = newIt; ++it; while (it != indexes.end() && it.key() == key) { qSwap(*newIt,*it); -- cgit v1.2.3