Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qquickpackage.cpp
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#include "qquickpackage_p.h"
5
6#include <private/qobject_p.h>
7#include <private/qqmlguard_p.h>
8
10
51{
52public:
54
55 struct DataGuard : public QQmlGuard<QObject>
56 {
57 DataGuard(QObject *obj, QList<DataGuard> *l) : QQmlGuard<QObject>(DataGuard::objectDestroyedImpl, nullptr), list(l) { (QQmlGuard<QObject>&)*this = obj; }
58 QList<DataGuard> *list;
59
60 private:
61 static void objectDestroyedImpl(QQmlGuardImpl *guard) {
62 auto This = static_cast<DataGuard *>(guard);
63 // we assume priv will always be destroyed after objectDestroyed calls
64 This->list->removeOne(*This);
65 }
66 };
67
68 QList<DataGuard> dataList;
69 static void data_append(QQmlListProperty<QObject> *prop, QObject *o) {
70 QList<DataGuard> *list = static_cast<QList<DataGuard> *>(prop->data);
72 }
73 static void data_clear(QQmlListProperty<QObject> *prop) {
74 QList<DataGuard> *list = static_cast<QList<DataGuard> *>(prop->data);
75 list->clear();
76 }
77 static QObject *data_at(QQmlListProperty<QObject> *prop, qsizetype index) {
78 QList<DataGuard> *list = static_cast<QList<DataGuard> *>(prop->data);
79 return list->at(index);
80 }
81 static qsizetype data_count(QQmlListProperty<QObject> *prop) {
82 QList<DataGuard> *list = static_cast<QList<DataGuard> *>(prop->data);
83 return list->size();
84 }
85 static void data_replace(QQmlListProperty<QObject> *prop, qsizetype index, QObject *o) {
86 QList<DataGuard> *list = static_cast<QList<DataGuard> *>(prop->data);
88 }
89 static void data_removeLast(QQmlListProperty<QObject> *prop) {
90 QList<DataGuard> *list = static_cast<QList<DataGuard> *>(prop->data);
92 }
93};
94
95QHash<QObject *, QQuickPackageAttached *> QQuickPackageAttached::attached;
96
98: QObject(parent)
99{
100 attached.insert(parent, this);
101}
102
107
109{
110 return _name;
111}
112
114{
115 _name = n;
116}
117
119 : QObject(*(new QQuickPackagePrivate), parent)
120{
121}
122
123QQmlListProperty<QObject> QQuickPackage::data()
124{
125 Q_D(QQuickPackage);
126 return QQmlListProperty<QObject>(this, &d->dataList,
133}
134
136{
137 Q_D(QQuickPackage);
138 for (int ii = 0; ii < d->dataList.size(); ++ii) {
139 QObject *obj = d->dataList.at(ii);
141 if (a && a->name() == name)
142 return true;
143 }
144 return false;
145}
146
148{
149 Q_D(QQuickPackage);
150 if (name.isEmpty() && !d->dataList.isEmpty())
151 return d->dataList.at(0);
152
153 for (int ii = 0; ii < d->dataList.size(); ++ii) {
154 QObject *obj = d->dataList.at(ii);
156 if (a && a->name() == name)
157 return obj;
158 }
159
160 if (name == QLatin1String("default") && !d->dataList.isEmpty())
161 return d->dataList.at(0);
162
163 return nullptr;
164}
165
170
171
172
174
175#include "moc_qquickpackage_p.cpp"
constexpr bool isEmpty() const noexcept
qsizetype size() const noexcept
Definition qlist.h:397
const_reference at(qsizetype i) const noexcept
Definition qlist.h:446
void replace(qsizetype i, parameter_type t)
Definition qlist.h:543
void removeLast() noexcept
Definition qlist.h:815
void append(parameter_type t)
Definition qlist.h:458
void clear()
Definition qlist.h:434
\inmodule QtCore
Definition qobject.h:103
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
void setName(const QString &n)
static QHash< QObject *, QQuickPackageAttached * > attached
QQuickPackageAttached(QObject *parent)
\qmltype Package \instantiates QQuickPackage \inqmlmodule QtQml.Models
static void data_removeLast(QQmlListProperty< QObject > *prop)
QList< DataGuard > dataList
static QObject * data_at(QQmlListProperty< QObject > *prop, qsizetype index)
static void data_append(QQmlListProperty< QObject > *prop, QObject *o)
static qsizetype data_count(QQmlListProperty< QObject > *prop)
static void data_clear(QQmlListProperty< QObject > *prop)
static void data_replace(QQmlListProperty< QObject > *prop, qsizetype index, QObject *o)
QQuickPackage(QObject *parent=nullptr)
QObject * part(const QString &=QString())
QQmlListProperty< QObject > data
static QQuickPackageAttached * qmlAttachedProperties(QObject *)
bool hasPart(const QString &)
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
Combined button and popup list for selecting options.
GLboolean GLboolean GLboolean GLboolean a
[7]
GLuint index
[2]
GLuint name
GLfloat n
GLhandleARB obj
[2]
QLatin1StringView QLatin1String
Definition qstringfwd.h:31
ptrdiff_t qsizetype
Definition qtypes.h:165
QList< int > list
[14]
QObject::connect nullptr
DataGuard(QObject *obj, QList< DataGuard > *l)