| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/items/qquickimagebase.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 QtQuick 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 "qquickimagebase_p.h" | - | ||||||||||||||||||
| 41 | #include "qquickimagebase_p_p.h" | - | ||||||||||||||||||
| 42 | - | |||||||||||||||||||
| 43 | #include <QtGui/qguiapplication.h> | - | ||||||||||||||||||
| 44 | #include <QtGui/qscreen.h> | - | ||||||||||||||||||
| 45 | #include <QtGui/qicon.h> | - | ||||||||||||||||||
| 46 | - | |||||||||||||||||||
| 47 | #include <QtQml/qqmlinfo.h> | - | ||||||||||||||||||
| 48 | #include <QtQml/qqmlfile.h> | - | ||||||||||||||||||
| 49 | - | |||||||||||||||||||
| 50 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 51 | - | |||||||||||||||||||
| 52 | // This function gives derived classes the chance set the devicePixelRatio | - | ||||||||||||||||||
| 53 | // if they're not happy with our implementation of it. | - | ||||||||||||||||||
| 54 | bool QQuickImageBasePrivate::updateDevicePixelRatio(qreal targetDevicePixelRatio) | - | ||||||||||||||||||
| 55 | { | - | ||||||||||||||||||
| 56 | // QQuickImageProvider and SVG can generate a high resolution image when | - | ||||||||||||||||||
| 57 | // sourceSize is set (this function is only called if it's set). | - | ||||||||||||||||||
| 58 | // If sourceSize is not set then the provider default size will be used, as usual. | - | ||||||||||||||||||
| 59 | bool setDevicePixelRatio = false; | - | ||||||||||||||||||
| 60 | if (url.scheme() == QLatin1String("image")) {
| 12-22 | ||||||||||||||||||
| 61 | setDevicePixelRatio = true; | - | ||||||||||||||||||
| 62 | } else { executed 12 times by 2 tests: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 63 | QString stringUrl = url.path(QUrl::PrettyDecoded); | - | ||||||||||||||||||
| 64 | if (stringUrl.endsWith(QLatin1String("svg")) ||
| 0-22 | ||||||||||||||||||
| 65 | stringUrl.endsWith(QLatin1String("svgz"))) {
| 0-22 | ||||||||||||||||||
| 66 | setDevicePixelRatio = true; | - | ||||||||||||||||||
| 67 | } never executed: end of block | 0 | ||||||||||||||||||
| 68 | } executed 22 times by 3 tests: end of blockExecuted by:
| 22 | ||||||||||||||||||
| 69 | - | |||||||||||||||||||
| 70 | if (setDevicePixelRatio)
| 12-22 | ||||||||||||||||||
| 71 | devicePixelRatio = targetDevicePixelRatio; executed 12 times by 2 tests: devicePixelRatio = targetDevicePixelRatio;Executed by:
| 12 | ||||||||||||||||||
| 72 | - | |||||||||||||||||||
| 73 | return setDevicePixelRatio; executed 34 times by 4 tests: return setDevicePixelRatio;Executed by:
| 34 | ||||||||||||||||||
| 74 | } | - | ||||||||||||||||||
| 75 | - | |||||||||||||||||||
| 76 | QQuickImageBase::QQuickImageBase(QQuickItem *parent) | - | ||||||||||||||||||
| 77 | : QQuickImplicitSizeItem(*(new QQuickImageBasePrivate), parent) | - | ||||||||||||||||||
| 78 | { | - | ||||||||||||||||||
| 79 | setFlag(ItemHasContents); | - | ||||||||||||||||||
| 80 | } never executed: end of block | 0 | ||||||||||||||||||
| 81 | - | |||||||||||||||||||
| 82 | QQuickImageBase::QQuickImageBase(QQuickImageBasePrivate &dd, QQuickItem *parent) | - | ||||||||||||||||||
| 83 | : QQuickImplicitSizeItem(dd, parent) | - | ||||||||||||||||||
| 84 | { | - | ||||||||||||||||||
| 85 | setFlag(ItemHasContents); | - | ||||||||||||||||||
| 86 | } executed 5624 times by 15 tests: end of blockExecuted by:
| 5624 | ||||||||||||||||||
| 87 | - | |||||||||||||||||||
| 88 | QQuickImageBase::~QQuickImageBase() | - | ||||||||||||||||||
| 89 | { | - | ||||||||||||||||||
| 90 | } | - | ||||||||||||||||||
| 91 | - | |||||||||||||||||||
| 92 | QQuickImageBase::Status QQuickImageBase::status() const | - | ||||||||||||||||||
| 93 | { | - | ||||||||||||||||||
| 94 | Q_D(const QQuickImageBase); | - | ||||||||||||||||||
| 95 | return d->status; executed 1341 times by 5 tests: return d->status;Executed by:
| 1341 | ||||||||||||||||||
| 96 | } | - | ||||||||||||||||||
| 97 | - | |||||||||||||||||||
| 98 | - | |||||||||||||||||||
| 99 | qreal QQuickImageBase::progress() const | - | ||||||||||||||||||
| 100 | { | - | ||||||||||||||||||
| 101 | Q_D(const QQuickImageBase); | - | ||||||||||||||||||
| 102 | return d->progress; executed 260 times by 4 tests: return d->progress;Executed by:
| 260 | ||||||||||||||||||
| 103 | } | - | ||||||||||||||||||
| 104 | - | |||||||||||||||||||
| 105 | - | |||||||||||||||||||
| 106 | bool QQuickImageBase::asynchronous() const | - | ||||||||||||||||||
| 107 | { | - | ||||||||||||||||||
| 108 | Q_D(const QQuickImageBase); | - | ||||||||||||||||||
| 109 | return d->async; executed 28 times by 1 test: return d->async;Executed by:
| 28 | ||||||||||||||||||
| 110 | } | - | ||||||||||||||||||
| 111 | - | |||||||||||||||||||
| 112 | void QQuickImageBase::setAsynchronous(bool async) | - | ||||||||||||||||||
| 113 | { | - | ||||||||||||||||||
| 114 | Q_D(QQuickImageBase); | - | ||||||||||||||||||
| 115 | if (d->async != async) {
| 22-66 | ||||||||||||||||||
| 116 | d->async = async; | - | ||||||||||||||||||
| 117 | emit asynchronousChanged(); | - | ||||||||||||||||||
| 118 | } executed 66 times by 5 tests: end of blockExecuted by:
| 66 | ||||||||||||||||||
| 119 | } executed 88 times by 5 tests: end of blockExecuted by:
| 88 | ||||||||||||||||||
| 120 | - | |||||||||||||||||||
| 121 | QUrl QQuickImageBase::source() const | - | ||||||||||||||||||
| 122 | { | - | ||||||||||||||||||
| 123 | Q_D(const QQuickImageBase); | - | ||||||||||||||||||
| 124 | return d->url; executed 363 times by 7 tests: return d->url;Executed by:
| 363 | ||||||||||||||||||
| 125 | } | - | ||||||||||||||||||
| 126 | - | |||||||||||||||||||
| 127 | void QQuickImageBase::setSource(const QUrl &url) | - | ||||||||||||||||||
| 128 | { | - | ||||||||||||||||||
| 129 | Q_D(QQuickImageBase); | - | ||||||||||||||||||
| 130 | - | |||||||||||||||||||
| 131 | if (url == d->url)
| 14-5440 | ||||||||||||||||||
| 132 | return; executed 14 times by 1 test: return;Executed by:
| 14 | ||||||||||||||||||
| 133 | - | |||||||||||||||||||
| 134 | d->url = url; | - | ||||||||||||||||||
| 135 | emit sourceChanged(d->url); | - | ||||||||||||||||||
| 136 | - | |||||||||||||||||||
| 137 | if (isComponentComplete())
| 74-5366 | ||||||||||||||||||
| 138 | load(); executed 74 times by 3 tests: load();Executed by:
| 74 | ||||||||||||||||||
| 139 | } executed 5440 times by 12 tests: end of blockExecuted by:
| 5440 | ||||||||||||||||||
| 140 | - | |||||||||||||||||||
| 141 | void QQuickImageBase::setSourceSize(const QSize& size) | - | ||||||||||||||||||
| 142 | { | - | ||||||||||||||||||
| 143 | Q_D(QQuickImageBase); | - | ||||||||||||||||||
| 144 | if (d->sourcesize == size)
| 12-42 | ||||||||||||||||||
| 145 | return; executed 12 times by 2 tests: return;Executed by:
| 12 | ||||||||||||||||||
| 146 | - | |||||||||||||||||||
| 147 | d->sourcesize = size; | - | ||||||||||||||||||
| 148 | emit sourceSizeChanged(); | - | ||||||||||||||||||
| 149 | if (isComponentComplete())
| 4-38 | ||||||||||||||||||
| 150 | load(); executed 4 times by 1 test: load();Executed by:
| 4 | ||||||||||||||||||
| 151 | } executed 42 times by 4 tests: end of blockExecuted by:
| 42 | ||||||||||||||||||
| 152 | - | |||||||||||||||||||
| 153 | QSize QQuickImageBase::sourceSize() const | - | ||||||||||||||||||
| 154 | { | - | ||||||||||||||||||
| 155 | Q_D(const QQuickImageBase); | - | ||||||||||||||||||
| 156 | - | |||||||||||||||||||
| 157 | int width = d->sourcesize.width(); | - | ||||||||||||||||||
| 158 | int height = d->sourcesize.height(); | - | ||||||||||||||||||
| 159 | return QSize(width != -1 ? width : d->pix.width(), height != -1 ? height : d->pix.height()); executed 11286 times by 10 tests: return QSize(width != -1 ? width : d->pix.width(), height != -1 ? height : d->pix.height());Executed by:
| 11286 | ||||||||||||||||||
| 160 | } | - | ||||||||||||||||||
| 161 | - | |||||||||||||||||||
| 162 | void QQuickImageBase::resetSourceSize() | - | ||||||||||||||||||
| 163 | { | - | ||||||||||||||||||
| 164 | setSourceSize(QSize()); | - | ||||||||||||||||||
| 165 | } never executed: end of block | 0 | ||||||||||||||||||
| 166 | - | |||||||||||||||||||
| 167 | bool QQuickImageBase::cache() const | - | ||||||||||||||||||
| 168 | { | - | ||||||||||||||||||
| 169 | Q_D(const QQuickImageBase); | - | ||||||||||||||||||
| 170 | return d->cache; executed 30 times by 2 tests: return d->cache;Executed by:
| 30 | ||||||||||||||||||
| 171 | } | - | ||||||||||||||||||
| 172 | - | |||||||||||||||||||
| 173 | void QQuickImageBase::setCache(bool cache) | - | ||||||||||||||||||
| 174 | { | - | ||||||||||||||||||
| 175 | Q_D(QQuickImageBase); | - | ||||||||||||||||||
| 176 | if (d->cache == cache)
| 24-26 | ||||||||||||||||||
| 177 | return; executed 26 times by 1 test: return;Executed by:
| 26 | ||||||||||||||||||
| 178 | - | |||||||||||||||||||
| 179 | d->cache = cache; | - | ||||||||||||||||||
| 180 | emit cacheChanged(); | - | ||||||||||||||||||
| 181 | if (isComponentComplete())
| 0-24 | ||||||||||||||||||
| 182 | load(); never executed: load(); | 0 | ||||||||||||||||||
| 183 | } executed 24 times by 3 tests: end of blockExecuted by:
| 24 | ||||||||||||||||||
| 184 | - | |||||||||||||||||||
| 185 | QImage QQuickImageBase::image() const | - | ||||||||||||||||||
| 186 | { | - | ||||||||||||||||||
| 187 | Q_D(const QQuickImageBase); | - | ||||||||||||||||||
| 188 | return d->pix.image(); executed 84 times by 1 test: return d->pix.image();Executed by:
| 84 | ||||||||||||||||||
| 189 | } | - | ||||||||||||||||||
| 190 | - | |||||||||||||||||||
| 191 | void QQuickImageBase::setMirror(bool mirror) | - | ||||||||||||||||||
| 192 | { | - | ||||||||||||||||||
| 193 | Q_D(QQuickImageBase); | - | ||||||||||||||||||
| 194 | if (mirror == d->mirror)
| 0-24 | ||||||||||||||||||
| 195 | return; never executed: return; | 0 | ||||||||||||||||||
| 196 | - | |||||||||||||||||||
| 197 | d->mirror = mirror; | - | ||||||||||||||||||
| 198 | - | |||||||||||||||||||
| 199 | if (isComponentComplete())
| 2-22 | ||||||||||||||||||
| 200 | update(); executed 22 times by 3 tests: update();Executed by:
| 22 | ||||||||||||||||||
| 201 | - | |||||||||||||||||||
| 202 | emit mirrorChanged(); | - | ||||||||||||||||||
| 203 | } executed 24 times by 4 tests: end of blockExecuted by:
| 24 | ||||||||||||||||||
| 204 | - | |||||||||||||||||||
| 205 | bool QQuickImageBase::mirror() const | - | ||||||||||||||||||
| 206 | { | - | ||||||||||||||||||
| 207 | Q_D(const QQuickImageBase); | - | ||||||||||||||||||
| 208 | return d->mirror; never executed: return d->mirror; | 0 | ||||||||||||||||||
| 209 | } | - | ||||||||||||||||||
| 210 | - | |||||||||||||||||||
| 211 | void QQuickImageBase::load() | - | ||||||||||||||||||
| 212 | { | - | ||||||||||||||||||
| 213 | Q_D(QQuickImageBase); | - | ||||||||||||||||||
| 214 | - | |||||||||||||||||||
| 215 | if (d->url.isEmpty()) {
| 8-5444 | ||||||||||||||||||
| 216 | d->pix.clear(this); | - | ||||||||||||||||||
| 217 | if (d->progress != 0.0) {
| 0-8 | ||||||||||||||||||
| 218 | d->progress = 0.0; | - | ||||||||||||||||||
| 219 | emit progressChanged(d->progress); | - | ||||||||||||||||||
| 220 | } executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||||||||
| 221 | pixmapChange(); | - | ||||||||||||||||||
| 222 | d->status = Null; | - | ||||||||||||||||||
| 223 | emit statusChanged(d->status); | - | ||||||||||||||||||
| 224 | - | |||||||||||||||||||
| 225 | if (sourceSize() != d->oldSourceSize) {
| 0-8 | ||||||||||||||||||
| 226 | d->oldSourceSize = sourceSize(); | - | ||||||||||||||||||
| 227 | emit sourceSizeChanged(); | - | ||||||||||||||||||
| 228 | } executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||||||||
| 229 | if (autoTransform() != d->oldAutoTransform) {
| 0-8 | ||||||||||||||||||
| 230 | d->oldAutoTransform = autoTransform(); | - | ||||||||||||||||||
| 231 | emitAutoTransformBaseChanged(); | - | ||||||||||||||||||
| 232 | } never executed: end of block | 0 | ||||||||||||||||||
| 233 | update(); | - | ||||||||||||||||||
| 234 | - | |||||||||||||||||||
| 235 | } else { executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||||||||
| 236 | QQuickPixmap::Options options; | - | ||||||||||||||||||
| 237 | if (d->async)
| 66-5378 | ||||||||||||||||||
| 238 | options |= QQuickPixmap::Asynchronous; executed 66 times by 4 tests: options |= QQuickPixmap::Asynchronous;Executed by:
| 66 | ||||||||||||||||||
| 239 | if (d->cache)
| 42-5402 | ||||||||||||||||||
| 240 | options |= QQuickPixmap::Cache; executed 5402 times by 11 tests: options |= QQuickPixmap::Cache;Executed by:
| 5402 | ||||||||||||||||||
| 241 | d->pix.clear(this); | - | ||||||||||||||||||
| 242 | - | |||||||||||||||||||
| 243 | const qreal targetDevicePixelRatio = (window() ? window()->effectiveDevicePixelRatio() : qApp->devicePixelRatio());
| 2384-3060 | ||||||||||||||||||
| 244 | d->devicePixelRatio = 1.0; | - | ||||||||||||||||||
| 245 | - | |||||||||||||||||||
| 246 | QUrl loadUrl = d->url; | - | ||||||||||||||||||
| 247 | - | |||||||||||||||||||
| 248 | bool updatedDevicePixelRatio = false; | - | ||||||||||||||||||
| 249 | if (d->sourcesize.isValid())
| 34-5410 | ||||||||||||||||||
| 250 | updatedDevicePixelRatio = d->updateDevicePixelRatio(targetDevicePixelRatio); executed 34 times by 4 tests: updatedDevicePixelRatio = d->updateDevicePixelRatio(targetDevicePixelRatio);Executed by:
| 34 | ||||||||||||||||||
| 251 | - | |||||||||||||||||||
| 252 | if (!updatedDevicePixelRatio) {
| 12-5432 | ||||||||||||||||||
| 253 | // (possible) local file: loadUrl and d->devicePixelRatio will be modified if | - | ||||||||||||||||||
| 254 | // an "@2x" file is found. | - | ||||||||||||||||||
| 255 | resolve2xLocalFile(d->url, targetDevicePixelRatio, &loadUrl, &d->devicePixelRatio); | - | ||||||||||||||||||
| 256 | } executed 5432 times by 12 tests: end of blockExecuted by:
| 5432 | ||||||||||||||||||
| 257 | - | |||||||||||||||||||
| 258 | d->pix.load(qmlEngine(this), loadUrl, d->sourcesize * d->devicePixelRatio, options, d->providerOptions); | - | ||||||||||||||||||
| 259 | - | |||||||||||||||||||
| 260 | if (d->pix.isLoading()) {
| 126-5318 | ||||||||||||||||||
| 261 | if (d->progress != 0.0) {
| 10-116 | ||||||||||||||||||
| 262 | d->progress = 0.0; | - | ||||||||||||||||||
| 263 | emit progressChanged(d->progress); | - | ||||||||||||||||||
| 264 | } executed 10 times by 1 test: end of blockExecuted by:
| 10 | ||||||||||||||||||
| 265 | if (d->status != Loading) {
| 0-126 | ||||||||||||||||||
| 266 | d->status = Loading; | - | ||||||||||||||||||
| 267 | emit statusChanged(d->status); | - | ||||||||||||||||||
| 268 | } executed 126 times by 6 tests: end of blockExecuted by:
| 126 | ||||||||||||||||||
| 269 | - | |||||||||||||||||||
| 270 | static int thisRequestProgress = -1; | - | ||||||||||||||||||
| 271 | static int thisRequestFinished = -1; | - | ||||||||||||||||||
| 272 | if (thisRequestProgress == -1) {
| 12-114 | ||||||||||||||||||
| 273 | thisRequestProgress = | - | ||||||||||||||||||
| 274 | QQuickImageBase::staticMetaObject.indexOfSlot("requestProgress(qint64,qint64)"); | - | ||||||||||||||||||
| 275 | thisRequestFinished = | - | ||||||||||||||||||
| 276 | QQuickImageBase::staticMetaObject.indexOfSlot("requestFinished()"); | - | ||||||||||||||||||
| 277 | } executed 12 times by 6 tests: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 278 | - | |||||||||||||||||||
| 279 | d->pix.connectFinished(this, thisRequestFinished); | - | ||||||||||||||||||
| 280 | d->pix.connectDownloadProgress(this, thisRequestProgress); | - | ||||||||||||||||||
| 281 | update(); //pixmap may have invalidated texture, updatePaintNode needs to be called before the next repaint | - | ||||||||||||||||||
| 282 | } else { executed 126 times by 6 tests: end of blockExecuted by:
| 126 | ||||||||||||||||||
| 283 | requestFinished(); | - | ||||||||||||||||||
| 284 | } executed 5318 times by 10 tests: end of blockExecuted by:
| 5318 | ||||||||||||||||||
| 285 | } | - | ||||||||||||||||||
| 286 | } | - | ||||||||||||||||||
| 287 | - | |||||||||||||||||||
| 288 | void QQuickImageBase::requestFinished() | - | ||||||||||||||||||
| 289 | { | - | ||||||||||||||||||
| 290 | Q_D(QQuickImageBase); | - | ||||||||||||||||||
| 291 | - | |||||||||||||||||||
| 292 | if (d->pix.isError()) {
| 92-5314 | ||||||||||||||||||
| 293 | qmlWarning(this) << d->pix.error(); | - | ||||||||||||||||||
| 294 | d->pix.clear(this); | - | ||||||||||||||||||
| 295 | d->status = Error; | - | ||||||||||||||||||
| 296 | if (d->progress != 0.0) {
| 4-88 | ||||||||||||||||||
| 297 | d->progress = 0.0; | - | ||||||||||||||||||
| 298 | emit progressChanged(d->progress); | - | ||||||||||||||||||
| 299 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 300 | } else { executed 92 times by 3 tests: end of blockExecuted by:
| 92 | ||||||||||||||||||
| 301 | d->status = Ready; | - | ||||||||||||||||||
| 302 | if (d->progress != 1.0) {
| 60-5254 | ||||||||||||||||||
| 303 | d->progress = 1.0; | - | ||||||||||||||||||
| 304 | emit progressChanged(d->progress); | - | ||||||||||||||||||
| 305 | } executed 5254 times by 10 tests: end of blockExecuted by:
| 5254 | ||||||||||||||||||
| 306 | } executed 5314 times by 10 tests: end of blockExecuted by:
| 5314 | ||||||||||||||||||
| 307 | pixmapChange(); | - | ||||||||||||||||||
| 308 | emit statusChanged(d->status); | - | ||||||||||||||||||
| 309 | if (sourceSize() != d->oldSourceSize) {
| 20-5386 | ||||||||||||||||||
| 310 | d->oldSourceSize = sourceSize(); | - | ||||||||||||||||||
| 311 | emit sourceSizeChanged(); | - | ||||||||||||||||||
| 312 | } executed 5386 times by 10 tests: end of blockExecuted by:
| 5386 | ||||||||||||||||||
| 313 | if (autoTransform() != d->oldAutoTransform) {
| 0-5406 | ||||||||||||||||||
| 314 | d->oldAutoTransform = autoTransform(); | - | ||||||||||||||||||
| 315 | emitAutoTransformBaseChanged(); | - | ||||||||||||||||||
| 316 | } never executed: end of block | 0 | ||||||||||||||||||
| 317 | update(); | - | ||||||||||||||||||
| 318 | } executed 5406 times by 10 tests: end of blockExecuted by:
| 5406 | ||||||||||||||||||
| 319 | - | |||||||||||||||||||
| 320 | void QQuickImageBase::requestProgress(qint64 received, qint64 total) | - | ||||||||||||||||||
| 321 | { | - | ||||||||||||||||||
| 322 | Q_D(QQuickImageBase); | - | ||||||||||||||||||
| 323 | if (d->status == Loading && total > 0) {
| 0-38 | ||||||||||||||||||
| 324 | d->progress = qreal(received)/total; | - | ||||||||||||||||||
| 325 | emit progressChanged(d->progress); | - | ||||||||||||||||||
| 326 | } executed 36 times by 3 tests: end of blockExecuted by:
| 36 | ||||||||||||||||||
| 327 | } executed 38 times by 3 tests: end of blockExecuted by:
| 38 | ||||||||||||||||||
| 328 | - | |||||||||||||||||||
| 329 | void QQuickImageBase::itemChange(ItemChange change, const ItemChangeData &value) | - | ||||||||||||||||||
| 330 | { | - | ||||||||||||||||||
| 331 | Q_D(QQuickImageBase); | - | ||||||||||||||||||
| 332 | // If the screen DPI changed, reload image. | - | ||||||||||||||||||
| 333 | if (change == ItemDevicePixelRatioHasChanged && value.realValue != d->devicePixelRatio) {
| 0-48482 | ||||||||||||||||||
| 334 | // ### how can we get here with !qmlEngine(this)? that implies | - | ||||||||||||||||||
| 335 | // itemChange() on an item pending deletion, which seems strange. | - | ||||||||||||||||||
| 336 | if (qmlEngine(this) && isComponentComplete() && d->url.isValid()) {
| 0 | ||||||||||||||||||
| 337 | load(); | - | ||||||||||||||||||
| 338 | } never executed: end of block | 0 | ||||||||||||||||||
| 339 | } never executed: end of block | 0 | ||||||||||||||||||
| 340 | QQuickItem::itemChange(change, value); | - | ||||||||||||||||||
| 341 | } executed 48482 times by 13 tests: end of blockExecuted by:
| 48482 | ||||||||||||||||||
| 342 | - | |||||||||||||||||||
| 343 | void QQuickImageBase::componentComplete() | - | ||||||||||||||||||
| 344 | { | - | ||||||||||||||||||
| 345 | Q_D(QQuickImageBase); | - | ||||||||||||||||||
| 346 | QQuickItem::componentComplete(); | - | ||||||||||||||||||
| 347 | if (d->url.isValid())
| 44-5490 | ||||||||||||||||||
| 348 | load(); executed 5490 times by 12 tests: load();Executed by:
| 5490 | ||||||||||||||||||
| 349 | } executed 5534 times by 14 tests: end of blockExecuted by:
| 5534 | ||||||||||||||||||
| 350 | - | |||||||||||||||||||
| 351 | void QQuickImageBase::pixmapChange() | - | ||||||||||||||||||
| 352 | { | - | ||||||||||||||||||
| 353 | Q_D(QQuickImageBase); | - | ||||||||||||||||||
| 354 | setImplicitSize(d->pix.width() / d->devicePixelRatio, d->pix.height() / d->devicePixelRatio); | - | ||||||||||||||||||
| 355 | } executed 5980 times by 11 tests: end of blockExecuted by:
| 5980 | ||||||||||||||||||
| 356 | - | |||||||||||||||||||
| 357 | void QQuickImageBase::resolve2xLocalFile(const QUrl &url, qreal targetDevicePixelRatio, QUrl *sourceUrl, qreal *sourceDevicePixelRatio) | - | ||||||||||||||||||
| 358 | { | - | ||||||||||||||||||
| 359 | Q_ASSERT(sourceUrl); | - | ||||||||||||||||||
| 360 | Q_ASSERT(sourceDevicePixelRatio); | - | ||||||||||||||||||
| 361 | - | |||||||||||||||||||
| 362 | // Bail out if "@2x" image loading is disabled, don't change the source url or devicePixelRatio. | - | ||||||||||||||||||
| 363 | static const bool disable2xImageLoading = !qEnvironmentVariableIsEmpty("QT_HIGHDPI_DISABLE_2X_IMAGE_LOADING"); | - | ||||||||||||||||||
| 364 | if (disable2xImageLoading)
| 0-5802 | ||||||||||||||||||
| 365 | return; never executed: return; | 0 | ||||||||||||||||||
| 366 | - | |||||||||||||||||||
| 367 | const QString localFile = QQmlFile::urlToLocalFileOrQrc(url); | - | ||||||||||||||||||
| 368 | - | |||||||||||||||||||
| 369 | // Non-local file path: @2x loading is not supported. | - | ||||||||||||||||||
| 370 | if (localFile.isEmpty())
| 192-5610 | ||||||||||||||||||
| 371 | return; executed 192 times by 9 tests: return;Executed by:
| 192 | ||||||||||||||||||
| 372 | - | |||||||||||||||||||
| 373 | // Special case: the url in the QML source refers directly to an "@2x" file. | - | ||||||||||||||||||
| 374 | int atLocation = localFile.lastIndexOf(QLatin1Char('@')); | - | ||||||||||||||||||
| 375 | if (atLocation > 0 && atLocation + 3 < localFile.size()) {
| 0-5590 | ||||||||||||||||||
| 376 | if (localFile[atLocation + 1].isDigit()
| 0-20 | ||||||||||||||||||
| 377 | && localFile[atLocation + 2] == QLatin1Char('x')
| 0-20 | ||||||||||||||||||
| 378 | && localFile[atLocation + 3] == QLatin1Char('.')) {
| 0-20 | ||||||||||||||||||
| 379 | *sourceDevicePixelRatio = localFile[atLocation + 1].digitValue(); | - | ||||||||||||||||||
| 380 | return; executed 20 times by 1 test: return;Executed by:
| 20 | ||||||||||||||||||
| 381 | } | - | ||||||||||||||||||
| 382 | } never executed: end of block | 0 | ||||||||||||||||||
| 383 | - | |||||||||||||||||||
| 384 | // Look for an @2x version | - | ||||||||||||||||||
| 385 | QString localFileX = qt_findAtNxFile(localFile, targetDevicePixelRatio, sourceDevicePixelRatio); | - | ||||||||||||||||||
| 386 | if (localFileX != localFile)
| 0-5590 | ||||||||||||||||||
| 387 | *sourceUrl = QUrl::fromLocalFile(localFileX); never executed: *sourceUrl = QUrl::fromLocalFile(localFileX); | 0 | ||||||||||||||||||
| 388 | } executed 5590 times by 14 tests: end of blockExecuted by:
| 5590 | ||||||||||||||||||
| 389 | - | |||||||||||||||||||
| 390 | bool QQuickImageBase::autoTransform() const | - | ||||||||||||||||||
| 391 | { | - | ||||||||||||||||||
| 392 | Q_D(const QQuickImageBase); | - | ||||||||||||||||||
| 393 | if (d->providerOptions.autoTransform() == QQuickImageProviderOptions::UsePluginDefaultTransform)
| 0-5414 | ||||||||||||||||||
| 394 | return d->pix.autoTransform() == QQuickImageProviderOptions::ApplyTransform; executed 5414 times by 10 tests: return d->pix.autoTransform() == QQuickImageProviderOptions::ApplyTransform;Executed by:
| 5414 | ||||||||||||||||||
| 395 | return d->providerOptions.autoTransform() == QQuickImageProviderOptions::ApplyTransform; never executed: return d->providerOptions.autoTransform() == QQuickImageProviderOptions::ApplyTransform; | 0 | ||||||||||||||||||
| 396 | } | - | ||||||||||||||||||
| 397 | - | |||||||||||||||||||
| 398 | void QQuickImageBase::setAutoTransform(bool transform) | - | ||||||||||||||||||
| 399 | { | - | ||||||||||||||||||
| 400 | Q_D(QQuickImageBase); | - | ||||||||||||||||||
| 401 | if (d->providerOptions.autoTransform() != QQuickImageProviderOptions::UsePluginDefaultTransform &&
| 0 | ||||||||||||||||||
| 402 | transform == (d->providerOptions.autoTransform() == QQuickImageProviderOptions::ApplyTransform))
| 0 | ||||||||||||||||||
| 403 | return; never executed: return; | 0 | ||||||||||||||||||
| 404 | d->providerOptions.setAutoTransform(transform ? QQuickImageProviderOptions::ApplyTransform : QQuickImageProviderOptions::DoNotApplyTransform); | - | ||||||||||||||||||
| 405 | emitAutoTransformBaseChanged(); | - | ||||||||||||||||||
| 406 | } never executed: end of block | 0 | ||||||||||||||||||
| 407 | - | |||||||||||||||||||
| 408 | QT_END_NAMESPACE | - | ||||||||||||||||||
| 409 | - | |||||||||||||||||||
| 410 | #include "moc_qquickimagebase_p.cpp" | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |