summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qassociativeiterable.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/kernel/qassociativeiterable.h')
-rw-r--r--src/corelib/kernel/qassociativeiterable.h74
1 files changed, 25 insertions, 49 deletions
diff --git a/src/corelib/kernel/qassociativeiterable.h b/src/corelib/kernel/qassociativeiterable.h
index 8412dc86fd..f3963d350e 100644
--- a/src/corelib/kernel/qassociativeiterable.h
+++ b/src/corelib/kernel/qassociativeiterable.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QASSOCIATIVEITERABLE_H
#define QASSOCIATIVEITERABLE_H
@@ -122,12 +86,14 @@ public:
{
}
+ // ### Qt7: Pass QMetaType as value rather than const ref.
QAssociativeIterable(const QMetaAssociation &metaAssociation, const QMetaType &metaType,
void *iterable)
: QIterable(metaAssociation, metaType.alignOf(), iterable)
{
}
+ // ### Qt7: Pass QMetaType as value rather than const ref.
QAssociativeIterable(const QMetaAssociation &metaAssociation, const QMetaType &metaType,
const void *iterable)
: QIterable(metaAssociation, metaType.alignOf(), iterable)
@@ -155,7 +121,12 @@ public:
const_iterator constFind(const QVariant &key) const { return find(key); }
iterator mutableFind(const QVariant &key);
+ bool containsKey(const QVariant &key);
+ void insertKey(const QVariant &key);
+ void removeKey(const QVariant &key);
+
QVariant value(const QVariant &key) const;
+ void setValue(const QVariant &key, const QVariant &mapped);
};
template<>
@@ -163,14 +134,15 @@ inline QVariantRef<QAssociativeIterator>::operator QVariant() const
{
if (m_pointer == nullptr)
return QVariant();
+
const auto metaAssociation = m_pointer->metaContainer();
- QMetaType metaType(metaAssociation.mappedMetaType());
+ const QMetaType metaType(metaAssociation.mappedMetaType());
if (!metaType.isValid())
return m_pointer->key();
QVariant v(metaType);
- void *dataPtr = metaType == QMetaType::fromType<QVariant>() ? &v : v.data();
- metaAssociation.mappedAtIterator(m_pointer->constIterator(), dataPtr);
+ metaAssociation.mappedAtIterator(m_pointer->constIterator(),
+ metaType == QMetaType::fromType<QVariant>() ? &v : v.data());
return v;
}
@@ -180,17 +152,21 @@ inline QVariantRef<QAssociativeIterator> &QVariantRef<QAssociativeIterator>::ope
{
if (m_pointer == nullptr)
return *this;
- const QMetaType metaType(m_pointer->metaContainer().mappedMetaType());
- const void *dataPtr = metaType == QMetaType::fromType<QVariant>()
- ? &value
- : value.constData();
- m_pointer->metaContainer().setMappedAtIterator(m_pointer->constIterator(), dataPtr);
+
+ const auto metaAssociation = m_pointer->metaContainer();
+ const QMetaType metaType(metaAssociation.mappedMetaType());
+ if (metaType.isValid()) {
+ QtPrivate::QVariantTypeCoercer coercer;
+ metaAssociation.setMappedAtIterator(m_pointer->constIterator(),
+ coercer.coerce(value, metaType));
+ }
+
return *this;
}
-Q_DECLARE_TYPEINFO(QAssociativeIterable, Q_MOVABLE_TYPE);
-Q_DECLARE_TYPEINFO(QAssociativeIterable::iterator, Q_MOVABLE_TYPE);
-Q_DECLARE_TYPEINFO(QAssociativeIterable::const_iterator, Q_MOVABLE_TYPE);
+Q_DECLARE_TYPEINFO(QAssociativeIterable, Q_RELOCATABLE_TYPE);
+Q_DECLARE_TYPEINFO(QAssociativeIterable::iterator, Q_RELOCATABLE_TYPE);
+Q_DECLARE_TYPEINFO(QAssociativeIterable::const_iterator, Q_RELOCATABLE_TYPE);
QT_END_NAMESPACE