| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/items/qquickscalegrid.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 "qquickscalegrid_p_p.h" | - | ||||||||||||||||||||||||||||||
| 41 | - | |||||||||||||||||||||||||||||||
| 42 | #include <QtQml/qqml.h> | - | ||||||||||||||||||||||||||||||
| 43 | - | |||||||||||||||||||||||||||||||
| 44 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||||||||
| 45 | - | |||||||||||||||||||||||||||||||
| 46 | /*! | - | ||||||||||||||||||||||||||||||
| 47 | \internal | - | ||||||||||||||||||||||||||||||
| 48 | \class QQuickScaleGrid | - | ||||||||||||||||||||||||||||||
| 49 | \brief The QQuickScaleGrid class allows you to specify a 3x3 grid to use in scaling an image. | - | ||||||||||||||||||||||||||||||
| 50 | */ | - | ||||||||||||||||||||||||||||||
| 51 | - | |||||||||||||||||||||||||||||||
| 52 | QQuickScaleGrid::QQuickScaleGrid(QObject *parent) : QObject(parent), _left(0), _top(0), _right(0), _bottom(0) | - | ||||||||||||||||||||||||||||||
| 53 | { | - | ||||||||||||||||||||||||||||||
| 54 | } executed 100 times by 2 tests: end of blockExecuted by:
| 100 | ||||||||||||||||||||||||||||||
| 55 | - | |||||||||||||||||||||||||||||||
| 56 | QQuickScaleGrid::~QQuickScaleGrid() | - | ||||||||||||||||||||||||||||||
| 57 | { | - | ||||||||||||||||||||||||||||||
| 58 | } | - | ||||||||||||||||||||||||||||||
| 59 | - | |||||||||||||||||||||||||||||||
| 60 | bool QQuickScaleGrid::isNull() const | - | ||||||||||||||||||||||||||||||
| 61 | { | - | ||||||||||||||||||||||||||||||
| 62 | return !_left && !_top && !_right && !_bottom; never executed: return !_left && !_top && !_right && !_bottom; | 0 | ||||||||||||||||||||||||||||||
| 63 | } | - | ||||||||||||||||||||||||||||||
| 64 | - | |||||||||||||||||||||||||||||||
| 65 | void QQuickScaleGrid::setLeft(int pos) | - | ||||||||||||||||||||||||||||||
| 66 | { | - | ||||||||||||||||||||||||||||||
| 67 | if (_left != pos) {
| 2-98 | ||||||||||||||||||||||||||||||
| 68 | _left = pos; | - | ||||||||||||||||||||||||||||||
| 69 | emit leftBorderChanged(); | - | ||||||||||||||||||||||||||||||
| 70 | emit borderChanged(); | - | ||||||||||||||||||||||||||||||
| 71 | } executed 98 times by 2 tests: end of blockExecuted by:
| 98 | ||||||||||||||||||||||||||||||
| 72 | } executed 100 times by 2 tests: end of blockExecuted by:
| 100 | ||||||||||||||||||||||||||||||
| 73 | - | |||||||||||||||||||||||||||||||
| 74 | void QQuickScaleGrid::setTop(int pos) | - | ||||||||||||||||||||||||||||||
| 75 | { | - | ||||||||||||||||||||||||||||||
| 76 | if (_top != pos) {
| 0-94 | ||||||||||||||||||||||||||||||
| 77 | _top = pos; | - | ||||||||||||||||||||||||||||||
| 78 | emit topBorderChanged(); | - | ||||||||||||||||||||||||||||||
| 79 | emit borderChanged(); | - | ||||||||||||||||||||||||||||||
| 80 | } executed 94 times by 2 tests: end of blockExecuted by:
| 94 | ||||||||||||||||||||||||||||||
| 81 | } executed 94 times by 2 tests: end of blockExecuted by:
| 94 | ||||||||||||||||||||||||||||||
| 82 | - | |||||||||||||||||||||||||||||||
| 83 | void QQuickScaleGrid::setRight(int pos) | - | ||||||||||||||||||||||||||||||
| 84 | { | - | ||||||||||||||||||||||||||||||
| 85 | if (_right != pos) {
| 2-98 | ||||||||||||||||||||||||||||||
| 86 | _right = pos; | - | ||||||||||||||||||||||||||||||
| 87 | emit rightBorderChanged(); | - | ||||||||||||||||||||||||||||||
| 88 | emit borderChanged(); | - | ||||||||||||||||||||||||||||||
| 89 | } executed 98 times by 2 tests: end of blockExecuted by:
| 98 | ||||||||||||||||||||||||||||||
| 90 | } executed 100 times by 2 tests: end of blockExecuted by:
| 100 | ||||||||||||||||||||||||||||||
| 91 | - | |||||||||||||||||||||||||||||||
| 92 | void QQuickScaleGrid::setBottom(int pos) | - | ||||||||||||||||||||||||||||||
| 93 | { | - | ||||||||||||||||||||||||||||||
| 94 | if (_bottom != pos) {
| 0-94 | ||||||||||||||||||||||||||||||
| 95 | _bottom = pos; | - | ||||||||||||||||||||||||||||||
| 96 | emit bottomBorderChanged(); | - | ||||||||||||||||||||||||||||||
| 97 | emit borderChanged(); | - | ||||||||||||||||||||||||||||||
| 98 | } executed 94 times by 2 tests: end of blockExecuted by:
| 94 | ||||||||||||||||||||||||||||||
| 99 | } executed 94 times by 2 tests: end of blockExecuted by:
| 94 | ||||||||||||||||||||||||||||||
| 100 | - | |||||||||||||||||||||||||||||||
| 101 | QQuickGridScaledImage::QQuickGridScaledImage() | - | ||||||||||||||||||||||||||||||
| 102 | : _l(-1), _r(-1), _t(-1), _b(-1), | - | ||||||||||||||||||||||||||||||
| 103 | _h(QQuickBorderImage::Stretch), _v(QQuickBorderImage::Stretch) | - | ||||||||||||||||||||||||||||||
| 104 | { | - | ||||||||||||||||||||||||||||||
| 105 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 106 | - | |||||||||||||||||||||||||||||||
| 107 | QQuickGridScaledImage::QQuickGridScaledImage(const QQuickGridScaledImage &o) | - | ||||||||||||||||||||||||||||||
| 108 | : _l(o._l), _r(o._r), _t(o._t), _b(o._b), _h(o._h), _v(o._v), _pix(o._pix) | - | ||||||||||||||||||||||||||||||
| 109 | { | - | ||||||||||||||||||||||||||||||
| 110 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 111 | - | |||||||||||||||||||||||||||||||
| 112 | QQuickGridScaledImage &QQuickGridScaledImage::operator=(const QQuickGridScaledImage &o) | - | ||||||||||||||||||||||||||||||
| 113 | { | - | ||||||||||||||||||||||||||||||
| 114 | _l = o._l; | - | ||||||||||||||||||||||||||||||
| 115 | _r = o._r; | - | ||||||||||||||||||||||||||||||
| 116 | _t = o._t; | - | ||||||||||||||||||||||||||||||
| 117 | _b = o._b; | - | ||||||||||||||||||||||||||||||
| 118 | _h = o._h; | - | ||||||||||||||||||||||||||||||
| 119 | _v = o._v; | - | ||||||||||||||||||||||||||||||
| 120 | _pix = o._pix; | - | ||||||||||||||||||||||||||||||
| 121 | return *this; never executed: return *this; | 0 | ||||||||||||||||||||||||||||||
| 122 | } | - | ||||||||||||||||||||||||||||||
| 123 | - | |||||||||||||||||||||||||||||||
| 124 | QQuickGridScaledImage::QQuickGridScaledImage(QIODevice *data) | - | ||||||||||||||||||||||||||||||
| 125 | : _l(-1), _r(-1), _t(-1), _b(-1), _h(QQuickBorderImage::Stretch), _v(QQuickBorderImage::Stretch) | - | ||||||||||||||||||||||||||||||
| 126 | { | - | ||||||||||||||||||||||||||||||
| 127 | int l = -1; | - | ||||||||||||||||||||||||||||||
| 128 | int r = -1; | - | ||||||||||||||||||||||||||||||
| 129 | int t = -1; | - | ||||||||||||||||||||||||||||||
| 130 | int b = -1; | - | ||||||||||||||||||||||||||||||
| 131 | QString imgFile; | - | ||||||||||||||||||||||||||||||
| 132 | - | |||||||||||||||||||||||||||||||
| 133 | QByteArray raw; | - | ||||||||||||||||||||||||||||||
| 134 | while (raw = data->readLine(), !raw.isEmpty()) {
| 26-160 | ||||||||||||||||||||||||||||||
| 135 | QString line = QString::fromUtf8(raw.trimmed()); | - | ||||||||||||||||||||||||||||||
| 136 | if (line.isEmpty() || line.startsWith(QLatin1Char('#')))
| 0-160 | ||||||||||||||||||||||||||||||
| 137 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||||||||
| 138 | - | |||||||||||||||||||||||||||||||
| 139 | int colonId = line.indexOf(QLatin1Char(':')); | - | ||||||||||||||||||||||||||||||
| 140 | if (colonId <= 0)
| 0-160 | ||||||||||||||||||||||||||||||
| 141 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
| 142 | - | |||||||||||||||||||||||||||||||
| 143 | const QStringRef property = line.leftRef(colonId).trimmed(); | - | ||||||||||||||||||||||||||||||
| 144 | QStringRef value = line.midRef(colonId + 1).trimmed(); | - | ||||||||||||||||||||||||||||||
| 145 | - | |||||||||||||||||||||||||||||||
| 146 | if (property == QLatin1String("border.left")) {
| 24-136 | ||||||||||||||||||||||||||||||
| 147 | l = value.toInt(); | - | ||||||||||||||||||||||||||||||
| 148 | } else if (property == QLatin1String("border.right")) { executed 24 times by 2 tests: end of blockExecuted by:
| 22-114 | ||||||||||||||||||||||||||||||
| 149 | r = value.toInt(); | - | ||||||||||||||||||||||||||||||
| 150 | } else if (property == QLatin1String("border.top")) { executed 22 times by 2 tests: end of blockExecuted by:
| 22-90 | ||||||||||||||||||||||||||||||
| 151 | t = value.toInt(); | - | ||||||||||||||||||||||||||||||
| 152 | } else if (property == QLatin1String("border.bottom")) { executed 24 times by 2 tests: end of blockExecuted by:
| 22-68 | ||||||||||||||||||||||||||||||
| 153 | b = value.toInt(); | - | ||||||||||||||||||||||||||||||
| 154 | } else if (property == QLatin1String("source")) { executed 22 times by 2 tests: end of blockExecuted by:
| 22-44 | ||||||||||||||||||||||||||||||
| 155 | if (value.startsWith(QLatin1Char('"')) && value.endsWith(QLatin1Char('"')))
| 0-20 | ||||||||||||||||||||||||||||||
| 156 | value = value.mid(1, value.size() - 2); // remove leading/trailing quotes. executed 4 times by 1 test: value = value.mid(1, value.size() - 2);Executed by:
| 4 | ||||||||||||||||||||||||||||||
| 157 | imgFile = value.toString(); | - | ||||||||||||||||||||||||||||||
| 158 | } else if (property == QLatin1String("horizontalTileRule") || property == QLatin1String("horizontalTileMode")) { executed 24 times by 2 tests: end of blockExecuted by:
| 8-32 | ||||||||||||||||||||||||||||||
| 159 | _h = stringToRule(value); | - | ||||||||||||||||||||||||||||||
| 160 | } else if (property == QLatin1String("verticalTileRule") || property == QLatin1String("verticalTileMode")) { executed 20 times by 1 test: end of blockExecuted by:
| 4-20 | ||||||||||||||||||||||||||||||
| 161 | _v = stringToRule(value); | - | ||||||||||||||||||||||||||||||
| 162 | } executed 20 times by 1 test: end of blockExecuted by:
| 20 | ||||||||||||||||||||||||||||||
| 163 | } executed 160 times by 2 tests: end of blockExecuted by:
| 160 | ||||||||||||||||||||||||||||||
| 164 | - | |||||||||||||||||||||||||||||||
| 165 | if (l < 0 || r < 0 || t < 0 || b < 0 || imgFile.isEmpty())
| 0-24 | ||||||||||||||||||||||||||||||
| 166 | return; executed 4 times by 1 test: return;Executed by:
| 4 | ||||||||||||||||||||||||||||||
| 167 | - | |||||||||||||||||||||||||||||||
| 168 | _l = l; _r = r; _t = t; _b = b; | - | ||||||||||||||||||||||||||||||
| 169 | _pix = imgFile; | - | ||||||||||||||||||||||||||||||
| 170 | } executed 22 times by 2 tests: end of blockExecuted by:
| 22 | ||||||||||||||||||||||||||||||
| 171 | - | |||||||||||||||||||||||||||||||
| 172 | QQuickBorderImage::TileMode QQuickGridScaledImage::stringToRule(const QStringRef &s) | - | ||||||||||||||||||||||||||||||
| 173 | { | - | ||||||||||||||||||||||||||||||
| 174 | QStringRef string = s; | - | ||||||||||||||||||||||||||||||
| 175 | if (string.startsWith(QLatin1Char('"')) && string.endsWith(QLatin1Char('"')))
| 0-32 | ||||||||||||||||||||||||||||||
| 176 | string = string.mid(1, string.size() - 2); // remove leading/trailing quotes. executed 8 times by 1 test: string = string.mid(1, string.size() - 2);Executed by:
| 8 | ||||||||||||||||||||||||||||||
| 177 | - | |||||||||||||||||||||||||||||||
| 178 | if (string == QLatin1String("Stretch") || string == QLatin1String("BorderImage.Stretch"))
| 0-40 | ||||||||||||||||||||||||||||||
| 179 | return QQuickBorderImage::Stretch; never executed: return QQuickBorderImage::Stretch; | 0 | ||||||||||||||||||||||||||||||
| 180 | if (string == QLatin1String("Repeat") || string == QLatin1String("BorderImage.Repeat"))
| 4-26 | ||||||||||||||||||||||||||||||
| 181 | return QQuickBorderImage::Repeat; executed 18 times by 1 test: return QQuickBorderImage::Repeat;Executed by:
| 18 | ||||||||||||||||||||||||||||||
| 182 | if (string == QLatin1String("Round") || string == QLatin1String("BorderImage.Round"))
| 4-14 | ||||||||||||||||||||||||||||||
| 183 | return QQuickBorderImage::Round; executed 18 times by 1 test: return QQuickBorderImage::Round;Executed by:
| 18 | ||||||||||||||||||||||||||||||
| 184 | - | |||||||||||||||||||||||||||||||
| 185 | qWarning("QQuickGridScaledImage: Invalid tile rule specified. Using Stretch."); | - | ||||||||||||||||||||||||||||||
| 186 | return QQuickBorderImage::Stretch; executed 4 times by 1 test: return QQuickBorderImage::Stretch;Executed by:
| 4 | ||||||||||||||||||||||||||||||
| 187 | } | - | ||||||||||||||||||||||||||||||
| 188 | - | |||||||||||||||||||||||||||||||
| 189 | bool QQuickGridScaledImage::isValid() const | - | ||||||||||||||||||||||||||||||
| 190 | { | - | ||||||||||||||||||||||||||||||
| 191 | return _l >= 0; executed 26 times by 2 tests: return _l >= 0;Executed by:
| 26 | ||||||||||||||||||||||||||||||
| 192 | } | - | ||||||||||||||||||||||||||||||
| 193 | - | |||||||||||||||||||||||||||||||
| 194 | int QQuickGridScaledImage::gridLeft() const | - | ||||||||||||||||||||||||||||||
| 195 | { | - | ||||||||||||||||||||||||||||||
| 196 | return _l; executed 22 times by 2 tests: return _l;Executed by:
| 22 | ||||||||||||||||||||||||||||||
| 197 | } | - | ||||||||||||||||||||||||||||||
| 198 | - | |||||||||||||||||||||||||||||||
| 199 | int QQuickGridScaledImage::gridRight() const | - | ||||||||||||||||||||||||||||||
| 200 | { | - | ||||||||||||||||||||||||||||||
| 201 | return _r; executed 22 times by 2 tests: return _r;Executed by:
| 22 | ||||||||||||||||||||||||||||||
| 202 | } | - | ||||||||||||||||||||||||||||||
| 203 | - | |||||||||||||||||||||||||||||||
| 204 | int QQuickGridScaledImage::gridTop() const | - | ||||||||||||||||||||||||||||||
| 205 | { | - | ||||||||||||||||||||||||||||||
| 206 | return _t; executed 22 times by 2 tests: return _t;Executed by:
| 22 | ||||||||||||||||||||||||||||||
| 207 | } | - | ||||||||||||||||||||||||||||||
| 208 | - | |||||||||||||||||||||||||||||||
| 209 | int QQuickGridScaledImage::gridBottom() const | - | ||||||||||||||||||||||||||||||
| 210 | { | - | ||||||||||||||||||||||||||||||
| 211 | return _b; executed 22 times by 2 tests: return _b;Executed by:
| 22 | ||||||||||||||||||||||||||||||
| 212 | } | - | ||||||||||||||||||||||||||||||
| 213 | - | |||||||||||||||||||||||||||||||
| 214 | QString QQuickGridScaledImage::pixmapUrl() const | - | ||||||||||||||||||||||||||||||
| 215 | { | - | ||||||||||||||||||||||||||||||
| 216 | return _pix; executed 22 times by 2 tests: return _pix;Executed by:
| 22 | ||||||||||||||||||||||||||||||
| 217 | } | - | ||||||||||||||||||||||||||||||
| 218 | - | |||||||||||||||||||||||||||||||
| 219 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||||||||
| Source code | Switch to Preprocessed file |