| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/types/qquickpackage.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||
| 2 | ** | - | ||||||||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||
| 5 | ** | - | ||||||||||||
| 6 | ** This file is part of the QtQml module of the Qt Toolkit. | - | ||||||||||||
| 7 | ** | - | ||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||
| 9 | ** Commercial License Usage | - | ||||||||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||
| 16 | ** | - | ||||||||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||
| 19 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||
| 24 | ** | - | ||||||||||||
| 25 | ** GNU General Public License Usage | - | ||||||||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||
| 35 | ** | - | ||||||||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||||||||
| 37 | ** | - | ||||||||||||
| 38 | ****************************************************************************/ | - | ||||||||||||
| 39 | - | |||||||||||||
| 40 | #include "qquickpackage_p.h" | - | ||||||||||||
| 41 | - | |||||||||||||
| 42 | #include <private/qobject_p.h> | - | ||||||||||||
| 43 | #include <private/qqmlguard_p.h> | - | ||||||||||||
| 44 | - | |||||||||||||
| 45 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 46 | - | |||||||||||||
| 47 | /*! | - | ||||||||||||
| 48 | \qmltype Package | - | ||||||||||||
| 49 | \instantiates QQuickPackage | - | ||||||||||||
| 50 | \inqmlmodule QtQuick | - | ||||||||||||
| 51 | \ingroup qtquick-views | - | ||||||||||||
| 52 | \brief Specifies a collection of named items. | - | ||||||||||||
| 53 | - | |||||||||||||
| 54 | The Package type is used in conjunction with | - | ||||||||||||
| 55 | DelegateModel to enable delegates with a shared context | - | ||||||||||||
| 56 | to be provided to multiple views. | - | ||||||||||||
| 57 | - | |||||||||||||
| 58 | Any item within a Package may be assigned a name via the | - | ||||||||||||
| 59 | \l{Package::name}{Package.name} attached property. | - | ||||||||||||
| 60 | - | |||||||||||||
| 61 | The example below creates a Package containing two named items; | - | ||||||||||||
| 62 | \e list and \e grid. The third item in the package (the \l Rectangle) is parented to whichever | - | ||||||||||||
| 63 | delegate it should appear in. This allows an item to move | - | ||||||||||||
| 64 | between views. | - | ||||||||||||
| 65 | - | |||||||||||||
| 66 | \snippet package/Delegate.qml 0 | - | ||||||||||||
| 67 | - | |||||||||||||
| 68 | These named items are used as the delegates by the two views who | - | ||||||||||||
| 69 | reference the special \l{DelegateModel::parts} property to select | - | ||||||||||||
| 70 | a model which provides the chosen delegate. | - | ||||||||||||
| 71 | - | |||||||||||||
| 72 | \snippet package/view.qml 0 | - | ||||||||||||
| 73 | - | |||||||||||||
| 74 | \sa {Qt Quick Examples - Views}, {Qt Quick Demo - Photo Viewer}, {Qt QML} | - | ||||||||||||
| 75 | */ | - | ||||||||||||
| 76 | - | |||||||||||||
| 77 | /*! | - | ||||||||||||
| 78 | \qmlattachedproperty string QtQuick::Package::name | - | ||||||||||||
| 79 | This attached property holds the name of an item within a Package. | - | ||||||||||||
| 80 | */ | - | ||||||||||||
| 81 | - | |||||||||||||
| 82 | - | |||||||||||||
| 83 | class QQuickPackagePrivate : public QObjectPrivate | - | ||||||||||||
| 84 | { | - | ||||||||||||
| 85 | public: | - | ||||||||||||
| 86 | QQuickPackagePrivate() {} | - | ||||||||||||
| 87 | - | |||||||||||||
| 88 | struct DataGuard : public QQmlGuard<QObject> | - | ||||||||||||
| 89 | { | - | ||||||||||||
| 90 | DataGuard(QObject *obj, QList<DataGuard> *l) : list(l) { (QQmlGuard<QObject>&)*this = obj; } executed 5334 times by 6 tests: end of blockExecuted by:
| 5334 | ||||||||||||
| 91 | QList<DataGuard> *list; | - | ||||||||||||
| 92 | void objectDestroyed(QObject *) override { | - | ||||||||||||
| 93 | // we assume priv will always be destroyed after objectDestroyed calls | - | ||||||||||||
| 94 | list->removeOne(*this); | - | ||||||||||||
| 95 | } executed 5334 times by 6 tests: end of blockExecuted by:
| 5334 | ||||||||||||
| 96 | }; | - | ||||||||||||
| 97 | - | |||||||||||||
| 98 | QList<DataGuard> dataList; | - | ||||||||||||
| 99 | static void data_append(QQmlListProperty<QObject> *prop, QObject *o) { | - | ||||||||||||
| 100 | QList<DataGuard> *list = static_cast<QList<DataGuard> *>(prop->data); | - | ||||||||||||
| 101 | list->append(DataGuard(o, list)); | - | ||||||||||||
| 102 | } executed 5334 times by 6 tests: end of blockExecuted by:
| 5334 | ||||||||||||
| 103 | static void data_clear(QQmlListProperty<QObject> *prop) { | - | ||||||||||||
| 104 | QList<DataGuard> *list = static_cast<QList<DataGuard> *>(prop->data); | - | ||||||||||||
| 105 | list->clear(); | - | ||||||||||||
| 106 | } never executed: end of block | 0 | ||||||||||||
| 107 | static QObject *data_at(QQmlListProperty<QObject> *prop, int index) { | - | ||||||||||||
| 108 | QList<DataGuard> *list = static_cast<QList<DataGuard> *>(prop->data); | - | ||||||||||||
| 109 | return list->at(index); never executed: return list->at(index); | 0 | ||||||||||||
| 110 | } | - | ||||||||||||
| 111 | static int data_count(QQmlListProperty<QObject> *prop) { | - | ||||||||||||
| 112 | QList<DataGuard> *list = static_cast<QList<DataGuard> *>(prop->data); | - | ||||||||||||
| 113 | return list->count(); never executed: return list->count(); | 0 | ||||||||||||
| 114 | } | - | ||||||||||||
| 115 | }; | - | ||||||||||||
| 116 | - | |||||||||||||
| 117 | QHash<QObject *, QQuickPackageAttached *> QQuickPackageAttached::attached; | - | ||||||||||||
| 118 | - | |||||||||||||
| 119 | QQuickPackageAttached::QQuickPackageAttached(QObject *parent) | - | ||||||||||||
| 120 | : QObject(parent) | - | ||||||||||||
| 121 | { | - | ||||||||||||
| 122 | attached.insert(parent, this); | - | ||||||||||||
| 123 | } executed 5226 times by 6 tests: end of blockExecuted by:
| 5226 | ||||||||||||
| 124 | - | |||||||||||||
| 125 | QQuickPackageAttached::~QQuickPackageAttached() | - | ||||||||||||
| 126 | { | - | ||||||||||||
| 127 | attached.remove(parent()); | - | ||||||||||||
| 128 | } executed 5226 times by 6 tests: end of blockExecuted by:
| 5226 | ||||||||||||
| 129 | - | |||||||||||||
| 130 | QString QQuickPackageAttached::name() const | - | ||||||||||||
| 131 | { | - | ||||||||||||
| 132 | return _name; executed 18694 times by 6 tests: return _name;Executed by:
| 18694 | ||||||||||||
| 133 | } | - | ||||||||||||
| 134 | - | |||||||||||||
| 135 | void QQuickPackageAttached::setName(const QString &n) | - | ||||||||||||
| 136 | { | - | ||||||||||||
| 137 | _name = n; | - | ||||||||||||
| 138 | } executed 5226 times by 6 tests: end of blockExecuted by:
| 5226 | ||||||||||||
| 139 | - | |||||||||||||
| 140 | QQuickPackage::QQuickPackage(QObject *parent) | - | ||||||||||||
| 141 | : QObject(*(new QQuickPackagePrivate), parent) | - | ||||||||||||
| 142 | { | - | ||||||||||||
| 143 | } executed 4962 times by 6 tests: end of blockExecuted by:
| 4962 | ||||||||||||
| 144 | - | |||||||||||||
| 145 | QQuickPackage::~QQuickPackage() | - | ||||||||||||
| 146 | { | - | ||||||||||||
| 147 | } | - | ||||||||||||
| 148 | - | |||||||||||||
| 149 | QQmlListProperty<QObject> QQuickPackage::data() | - | ||||||||||||
| 150 | { | - | ||||||||||||
| 151 | Q_D(QQuickPackage); | - | ||||||||||||
| 152 | return QQmlListProperty<QObject>(this, &d->dataList, QQuickPackagePrivate::data_append, executed 4962 times by 6 tests: return QQmlListProperty<QObject>(this, &d->dataList, QQuickPackagePrivate::data_append, QQuickPackagePrivate::data_count, QQuickPackagePrivate::data_at, QQuickPackagePrivate::data_clear);Executed by:
| 4962 | ||||||||||||
| 153 | QQuickPackagePrivate::data_count, executed 4962 times by 6 tests: return QQmlListProperty<QObject>(this, &d->dataList, QQuickPackagePrivate::data_append, QQuickPackagePrivate::data_count, QQuickPackagePrivate::data_at, QQuickPackagePrivate::data_clear);Executed by:
| 4962 | ||||||||||||
| 154 | QQuickPackagePrivate::data_at, executed 4962 times by 6 tests: return QQmlListProperty<QObject>(this, &d->dataList, QQuickPackagePrivate::data_append, QQuickPackagePrivate::data_count, QQuickPackagePrivate::data_at, QQuickPackagePrivate::data_clear);Executed by:
| 4962 | ||||||||||||
| 155 | QQuickPackagePrivate::data_clear); executed 4962 times by 6 tests: return QQmlListProperty<QObject>(this, &d->dataList, QQuickPackagePrivate::data_append, QQuickPackagePrivate::data_count, QQuickPackagePrivate::data_at, QQuickPackagePrivate::data_clear);Executed by:
| 4962 | ||||||||||||
| 156 | } | - | ||||||||||||
| 157 | - | |||||||||||||
| 158 | bool QQuickPackage::hasPart(const QString &name) | - | ||||||||||||
| 159 | { | - | ||||||||||||
| 160 | Q_D(QQuickPackage); | - | ||||||||||||
| 161 | for (int ii = 0; ii < d->dataList.count(); ++ii) {
| 0 | ||||||||||||
| 162 | QObject *obj = d->dataList.at(ii); | - | ||||||||||||
| 163 | QQuickPackageAttached *a = QQuickPackageAttached::attached.value(obj); | - | ||||||||||||
| 164 | if (a && a->name() == name)
| 0 | ||||||||||||
| 165 | return true; never executed: return true; | 0 | ||||||||||||
| 166 | } never executed: end of block | 0 | ||||||||||||
| 167 | return false; never executed: return false; | 0 | ||||||||||||
| 168 | } | - | ||||||||||||
| 169 | - | |||||||||||||
| 170 | QObject *QQuickPackage::part(const QString &name) | - | ||||||||||||
| 171 | { | - | ||||||||||||
| 172 | Q_D(QQuickPackage); | - | ||||||||||||
| 173 | if (name.isEmpty() && !d->dataList.isEmpty())
| 0-17892 | ||||||||||||
| 174 | return d->dataList.at(0); never executed: return d->dataList.at(0); | 0 | ||||||||||||
| 175 | - | |||||||||||||
| 176 | for (int ii = 0; ii < d->dataList.count(); ++ii) {
| 0-18694 | ||||||||||||
| 177 | QObject *obj = d->dataList.at(ii); | - | ||||||||||||
| 178 | QQuickPackageAttached *a = QQuickPackageAttached::attached.value(obj); | - | ||||||||||||
| 179 | if (a && a->name() == name)
| 0-18694 | ||||||||||||
| 180 | return obj; executed 17892 times by 6 tests: return obj;Executed by:
| 17892 | ||||||||||||
| 181 | } executed 802 times by 6 tests: end of blockExecuted by:
| 802 | ||||||||||||
| 182 | - | |||||||||||||
| 183 | if (name == QLatin1String("default") && !d->dataList.isEmpty())
| 0 | ||||||||||||
| 184 | return d->dataList.at(0); never executed: return d->dataList.at(0); | 0 | ||||||||||||
| 185 | - | |||||||||||||
| 186 | return nullptr; never executed: return nullptr; | 0 | ||||||||||||
| 187 | } | - | ||||||||||||
| 188 | - | |||||||||||||
| 189 | QQuickPackageAttached *QQuickPackage::qmlAttachedProperties(QObject *o) | - | ||||||||||||
| 190 | { | - | ||||||||||||
| 191 | return new QQuickPackageAttached(o); executed 5226 times by 6 tests: return new QQuickPackageAttached(o);Executed by:
| 5226 | ||||||||||||
| 192 | } | - | ||||||||||||
| 193 | - | |||||||||||||
| 194 | - | |||||||||||||
| 195 | - | |||||||||||||
| 196 | QT_END_NAMESPACE | - | ||||||||||||
| 197 | - | |||||||||||||
| 198 | #include "moc_qquickpackage_p.cpp" | - | ||||||||||||
| Source code | Switch to Preprocessed file |