Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/util/qqmllistaccessor.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 "qqmllistaccessor_p.h" | - | ||||||||||||
41 | - | |||||||||||||
42 | #include <private/qqmlmetatype_p.h> | - | ||||||||||||
43 | - | |||||||||||||
44 | #include <QtCore/qstringlist.h> | - | ||||||||||||
45 | #include <QtCore/qdebug.h> | - | ||||||||||||
46 | - | |||||||||||||
47 | // ### Remove me | - | ||||||||||||
48 | #include <private/qqmlengine_p.h> | - | ||||||||||||
49 | - | |||||||||||||
50 | QT_BEGIN_NAMESPACE | - | ||||||||||||
51 | - | |||||||||||||
52 | QQmlListAccessor::QQmlListAccessor() | - | ||||||||||||
53 | : m_type(Invalid) | - | ||||||||||||
54 | { | - | ||||||||||||
55 | } executed 5622 times by 27 tests: end of block Executed by:
| 5622 | ||||||||||||
56 | - | |||||||||||||
57 | QQmlListAccessor::~QQmlListAccessor() | - | ||||||||||||
58 | { | - | ||||||||||||
59 | } | - | ||||||||||||
60 | - | |||||||||||||
61 | QVariant QQmlListAccessor::list() const | - | ||||||||||||
62 | { | - | ||||||||||||
63 | return d; executed 5492 times by 25 tests: return d; Executed by:
| 5492 | ||||||||||||
64 | } | - | ||||||||||||
65 | - | |||||||||||||
66 | void QQmlListAccessor::setList(const QVariant &v, QQmlEngine *engine) | - | ||||||||||||
67 | { | - | ||||||||||||
68 | d = v; | - | ||||||||||||
69 | - | |||||||||||||
70 | // An incoming JS array as model is treated as a variant list, so we need to | - | ||||||||||||
71 | // convert it first with toVariant(). | - | ||||||||||||
72 | if (d.userType() == qMetaTypeId<QJSValue>())
| 46-5436 | ||||||||||||
73 | d = d.value<QJSValue>().toVariant(); executed 46 times by 2 tests: d = d.value<QJSValue>().toVariant(); Executed by:
| 46 | ||||||||||||
74 | - | |||||||||||||
75 | QQmlEnginePrivate *enginePrivate = engine?QQmlEnginePrivate::get(engine):nullptr;
| 516-4966 | ||||||||||||
76 | - | |||||||||||||
77 | if (!d.isValid()) {
| 548-4934 | ||||||||||||
78 | m_type = Invalid; | - | ||||||||||||
79 | } else if (d.userType() == QVariant::StringList) { executed 548 times by 6 tests: end of block Executed by:
| 10-4924 | ||||||||||||
80 | m_type = StringList; | - | ||||||||||||
81 | } else if (d.userType() == QMetaType::QVariantList) { executed 10 times by 2 tests: end of block Executed by:
| 10-4730 | ||||||||||||
82 | m_type = VariantList; | - | ||||||||||||
83 | } else if (d.canConvert(QVariant::Int)) { executed 194 times by 9 tests: end of block Executed by:
| 194-4184 | ||||||||||||
84 | m_type = Integer; | - | ||||||||||||
85 | } else if ((!enginePrivate && QQmlMetaType::isQObject(d.userType())) || executed 546 times by 21 tests: end of block Executed by:
| 0-4184 | ||||||||||||
86 | (enginePrivate && enginePrivate->isQObject(d.userType()))) {
| 0-4184 | ||||||||||||
87 | QObject *data = enginePrivate?enginePrivate->toQObject(d):QQmlMetaType::toQObject(d);
| 0-3966 | ||||||||||||
88 | d = QVariant::fromValue(data); | - | ||||||||||||
89 | m_type = Instance; | - | ||||||||||||
90 | } else if (d.userType() == qMetaTypeId<QQmlListReference>()) { executed 3966 times by 12 tests: end of block Executed by:
| 22-3966 | ||||||||||||
91 | m_type = ListProperty; | - | ||||||||||||
92 | } else { executed 22 times by 3 tests: end of block Executed by:
| 22 | ||||||||||||
93 | m_type = Instance; | - | ||||||||||||
94 | } executed 196 times by 3 tests: end of block Executed by:
| 196 | ||||||||||||
95 | } | - | ||||||||||||
96 | - | |||||||||||||
97 | int QQmlListAccessor::count() const | - | ||||||||||||
98 | { | - | ||||||||||||
99 | switch(m_type) { | - | ||||||||||||
100 | case StringList: executed 530 times by 2 tests: case StringList: Executed by:
| 530 | ||||||||||||
101 | return qvariant_cast<QStringList>(d).count(); executed 530 times by 2 tests: return qvariant_cast<QStringList>(d).count(); Executed by:
| 530 | ||||||||||||
102 | case VariantList: executed 6014 times by 9 tests: case VariantList: Executed by:
| 6014 | ||||||||||||
103 | return qvariant_cast<QVariantList>(d).count(); executed 6014 times by 9 tests: return qvariant_cast<QVariantList>(d).count(); Executed by:
| 6014 | ||||||||||||
104 | case ListProperty: executed 1926 times by 3 tests: case ListProperty: Executed by:
| 1926 | ||||||||||||
105 | return ((const QQmlListReference *)d.constData())->count(); executed 1926 times by 3 tests: return ((const QQmlListReference *)d.constData())->count(); Executed by:
| 1926 | ||||||||||||
106 | case Instance: executed 10 times by 1 test: case Instance: Executed by:
| 10 | ||||||||||||
107 | return 1; executed 10 times by 1 test: return 1; Executed by:
| 10 | ||||||||||||
108 | case Integer: executed 34212 times by 21 tests: case Integer: Executed by:
| 34212 | ||||||||||||
109 | return d.toInt(); executed 34212 times by 21 tests: return d.toInt(); Executed by:
| 34212 | ||||||||||||
110 | default: never executed: default: | 0 | ||||||||||||
111 | case Invalid: never executed: case Invalid: | 0 | ||||||||||||
112 | return 0; never executed: return 0; | 0 | ||||||||||||
113 | } | - | ||||||||||||
114 | } | - | ||||||||||||
115 | - | |||||||||||||
116 | QVariant QQmlListAccessor::at(int idx) const | - | ||||||||||||
117 | { | - | ||||||||||||
118 | Q_ASSERT(idx >= 0 && idx < count()); | - | ||||||||||||
119 | switch(m_type) { | - | ||||||||||||
120 | case StringList: executed 130 times by 2 tests: case StringList: Executed by:
| 130 | ||||||||||||
121 | return QVariant::fromValue(qvariant_cast<QStringList>(d).at(idx)); executed 130 times by 2 tests: return QVariant::fromValue(qvariant_cast<QStringList>(d).at(idx)); Executed by:
| 130 | ||||||||||||
122 | case VariantList: executed 1442 times by 5 tests: case VariantList: Executed by:
| 1442 | ||||||||||||
123 | return qvariant_cast<QVariantList>(d).at(idx); executed 1442 times by 5 tests: return qvariant_cast<QVariantList>(d).at(idx); Executed by:
| 1442 | ||||||||||||
124 | case ListProperty: executed 494 times by 3 tests: case ListProperty: Executed by:
| 494 | ||||||||||||
125 | return QVariant::fromValue(((const QQmlListReference *)d.constData())->at(idx)); executed 494 times by 3 tests: return QVariant::fromValue(((const QQmlListReference *)d.constData())->at(idx)); Executed by:
| 494 | ||||||||||||
126 | case Instance: executed 2 times by 1 test: case Instance: Executed by:
| 2 | ||||||||||||
127 | return d; executed 2 times by 1 test: return d; Executed by:
| 2 | ||||||||||||
128 | case Integer: executed 8483 times by 21 tests: case Integer: Executed by:
| 8483 | ||||||||||||
129 | return QVariant(idx); executed 8483 times by 21 tests: return QVariant(idx); Executed by:
| 8483 | ||||||||||||
130 | default: never executed: default: | 0 | ||||||||||||
131 | case Invalid: never executed: case Invalid: | 0 | ||||||||||||
132 | return QVariant(); never executed: return QVariant(); | 0 | ||||||||||||
133 | } | - | ||||||||||||
134 | } | - | ||||||||||||
135 | - | |||||||||||||
136 | bool QQmlListAccessor::isValid() const | - | ||||||||||||
137 | { | - | ||||||||||||
138 | return m_type != Invalid; never executed: return m_type != Invalid; | 0 | ||||||||||||
139 | } | - | ||||||||||||
140 | - | |||||||||||||
141 | QT_END_NAMESPACE | - | ||||||||||||
Source code | Switch to Preprocessed file |