Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qqmltypemodule.cpp
Go to the documentation of this file.
1// Copyright (C) 2019 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant
4
6
7#include <private/qqmltype_p_p.h>
8
9#include <QtCore/qmutex.h>
10
12
13void QQmlTypeModule::addMinorVersion(quint8 version)
14{
15 for (int oldVersion = m_minMinorVersion.loadRelaxed();
16 oldVersion > version && !m_minMinorVersion.testAndSetOrdered(oldVersion, version);
17 oldVersion = m_minMinorVersion.loadRelaxed()) {
18 }
19
20 for (int oldVersion = m_maxMinorVersion.loadRelaxed();
21 oldVersion < version && !m_maxMinorVersion.testAndSetOrdered(oldVersion, version);
22 oldVersion = m_maxMinorVersion.loadRelaxed()) {
23 }
24}
25
26void QQmlTypeModule::add(QQmlTypePrivate *type)
27{
28 QMutexLocker lock(&m_mutex);
29
30 if (type->version.hasMinorVersion())
31 addMinorVersion(type->version.minorVersion());
32
33 QList<QQmlTypePrivate *> &list = m_typeHash[type->elementName];
34 for (int ii = 0; ii < list.size(); ++ii) {
35 QQmlTypePrivate *in_list = list.at(ii);
36 Q_ASSERT(in_list);
37 if (in_list->version.minorVersion() < type->version.minorVersion()) {
38 list.insert(ii, type);
39 return;
40 } else if (in_list->version.minorVersion() == type->version.minorVersion()) {
41 list[ii] = type;
42 return;
43 }
44 }
45 list.append(type);
46}
47
48void QQmlTypeModule::remove(const QQmlTypePrivate *type)
49{
50 QMutexLocker lock(&m_mutex);
51 for (auto elementIt = m_typeHash.begin(); elementIt != m_typeHash.end(); ++elementIt)
52 QQmlMetaType::removeQQmlTypePrivate(elementIt.value(), type);
53}
54
55QQmlType QQmlTypeModule::findType(const QList<QQmlTypePrivate *> *types, QTypeRevision version)
56{
57 if (types) {
58 for (int ii = 0; ii < types->size(); ++ii)
59 if (types->at(ii)->version.minorVersion() <= version.minorVersion())
60 return QQmlType(types->at(ii));
61 }
62
63 return QQmlType();
64}
65
66void QQmlTypeModule::walkCompositeSingletons(const std::function<void(const QQmlType &)> &callback) const
67{
68 QMutexLocker lock(&m_mutex);
69 for (auto typeCandidates = m_typeHash.begin(), end = m_typeHash.end();
70 typeCandidates != end; ++typeCandidates) {
71 for (auto type: typeCandidates.value()) {
72 if (type->regType == QQmlType::CompositeSingletonType)
73 callback(QQmlType(type));
74 }
75 }
76}
77
78QT_END_NAMESPACE
void walkCompositeSingletons(const std::function< void(const QQmlType &)> &callback) const
void remove(const QQmlTypePrivate *type)
void addMinorVersion(quint8 minorVersion)
void add(QQmlTypePrivate *)
Combined button and popup list for selecting options.