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
qqmlpropertymap.h
Go to the documentation of this file.
1// Copyright (C) 2016 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
4#ifndef QQMLPROPERTYMAP_H
5#define QQMLPROPERTYMAP_H
6
7#include <QtQml/qtqmlglobal.h>
8#include <QtQml/qqmlregistration.h>
9#include <QtQml/qqmlprivate.h>
10
11#include <QtCore/QObject>
12#include <QtCore/QHash>
13#include <QtCore/QStringList>
14#include <QtCore/QVariant>
15
16QT_BEGIN_NAMESPACE
17
18
19class QQmlPropertyMapPrivate;
20class Q_QML_EXPORT QQmlPropertyMap : public QObject
21{
22 Q_OBJECT
23 QML_ANONYMOUS
24public:
25#if QT_DEPRECATED_SINCE(6, 11)
26 QT_DEPRECATED_VERSION_X_6_11("Use factory or protected two-argument constructor instead.")
27 explicit QQmlPropertyMap(QObject *parent = nullptr);
28#endif
29
30 static QQmlPropertyMap *create(QObject *parent = nullptr);
31
32 ~QQmlPropertyMap() override;
33
34 QVariant value(const QString &key) const;
35 void insert(const QString &key, const QVariant &value);
36 void insert(const QVariantHash &values);
37 void clear(const QString &key);
38 void freeze();
39
40 Q_INVOKABLE QStringList keys() const;
41
42 int count() const;
43 int size() const;
44 bool isEmpty() const;
45 bool contains(const QString &key) const;
46
47 QVariant &operator[](const QString &key);
48 QVariant operator[](const QString &key) const;
49
50Q_SIGNALS:
51 void valueChanged(const QString &key, const QVariant &value);
52
53protected:
54 virtual QVariant updateValue(const QString &key, const QVariant &input);
55
56 template<class DerivedType>
57 QQmlPropertyMap(DerivedType *derived, QObject *parentObj)
58 : QQmlPropertyMap(&DerivedType::staticMetaObject, parentObj)
59 {
60 Q_UNUSED(derived);
61 }
62
63private:
64 QQmlPropertyMap(const QMetaObject *staticMetaObject, QObject *parent);
65
66 Q_DECLARE_PRIVATE(QQmlPropertyMap)
67 Q_DISABLE_COPY(QQmlPropertyMap)
68};
69
70namespace QQmlPrivate {
71
72// Specialization of QQmlElement for QQmlPropertyMap, for the rare case
73// when you'd want to register QQmlPropertyMap directly, rather than some
74// derived class of it.
75template<>
77
78}
79
80QT_END_NAMESPACE
81
82#endif
const QString & propertyName(int index)
void propertyWritten(int index) override
QVariant propertyWriteValue(int, const QVariant &) override
void propertyCreated(int, QMetaPropertyBuilder &) override
QQmlPropertyMapMetaObject(QQmlPropertyMap *obj, QQmlPropertyMapPrivate *objPriv, const QMetaObject *staticMetaObject)
QVariant updateValue(const QString &key, const QVariant &input)
void emitChanged(const QString &key, const QVariant &value)
const QString & propertyName(int index) const
static bool validKeyName(const QString &name)
The QQmlPropertyMap class allows you to set key-value pairs that can be used in QML bindings.