| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/util/qquickstyledtext.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 <QStack> | - | ||||||||||||||||||
| 41 | #include <QVector> | - | ||||||||||||||||||
| 42 | #include <QPainter> | - | ||||||||||||||||||
| 43 | #include <QTextLayout> | - | ||||||||||||||||||
| 44 | #include <QDebug> | - | ||||||||||||||||||
| 45 | #include <qmath.h> | - | ||||||||||||||||||
| 46 | #include "qquickstyledtext_p.h" | - | ||||||||||||||||||
| 47 | #include <QQmlContext> | - | ||||||||||||||||||
| 48 | - | |||||||||||||||||||
| 49 | /* | - | ||||||||||||||||||
| 50 | QQuickStyledText supports few tags: | - | ||||||||||||||||||
| 51 | - | |||||||||||||||||||
| 52 | <b></b> - bold | - | ||||||||||||||||||
| 53 | <strong></strong> - bold | - | ||||||||||||||||||
| 54 | <i></i> - italic | - | ||||||||||||||||||
| 55 | <br> - new line | - | ||||||||||||||||||
| 56 | <p> - paragraph | - | ||||||||||||||||||
| 57 | <u> - underlined text | - | ||||||||||||||||||
| 58 | <font color="color_name" size="1-7"></font> | - | ||||||||||||||||||
| 59 | <h1> to <h6> - headers | - | ||||||||||||||||||
| 60 | <a href=""> - anchor | - | ||||||||||||||||||
| 61 | <ol type="">, <ul type=""> and <li> - ordered and unordered lists | - | ||||||||||||||||||
| 62 | <pre></pre> - preformated | - | ||||||||||||||||||
| 63 | <img src=""> - images | - | ||||||||||||||||||
| 64 | - | |||||||||||||||||||
| 65 | The opening and closing tags must be correctly nested. | - | ||||||||||||||||||
| 66 | */ | - | ||||||||||||||||||
| 67 | - | |||||||||||||||||||
| 68 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 69 | - | |||||||||||||||||||
| 70 | Q_GUI_EXPORT int qt_defaultDpi(); | - | ||||||||||||||||||
| 71 | - | |||||||||||||||||||
| 72 | class QQuickStyledTextPrivate | - | ||||||||||||||||||
| 73 | { | - | ||||||||||||||||||
| 74 | public: | - | ||||||||||||||||||
| 75 | enum ListType { Ordered, Unordered }; | - | ||||||||||||||||||
| 76 | enum ListFormat { Bullet, Disc, Square, Decimal, LowerAlpha, UpperAlpha, LowerRoman, UpperRoman }; | - | ||||||||||||||||||
| 77 | - | |||||||||||||||||||
| 78 | struct List { | - | ||||||||||||||||||
| 79 | int level; | - | ||||||||||||||||||
| 80 | ListType type; | - | ||||||||||||||||||
| 81 | ListFormat format; | - | ||||||||||||||||||
| 82 | }; | - | ||||||||||||||||||
| 83 | - | |||||||||||||||||||
| 84 | QQuickStyledTextPrivate(const QString &t, QTextLayout &l, | - | ||||||||||||||||||
| 85 | QList<QQuickStyledTextImgTag*> &imgTags, | - | ||||||||||||||||||
| 86 | const QUrl &baseUrl, | - | ||||||||||||||||||
| 87 | QQmlContext *context, | - | ||||||||||||||||||
| 88 | bool preloadImages, | - | ||||||||||||||||||
| 89 | bool *fontSizeModified) | - | ||||||||||||||||||
| 90 | : text(t), layout(l), imgTags(&imgTags), baseFont(layout.font()), baseUrl(baseUrl), hasNewLine(true), nbImages(0), updateImagePositions(false) | - | ||||||||||||||||||
| 91 | , preFormat(false), prependSpace(false), hasSpace(true), preloadImages(preloadImages), fontSizeModified(fontSizeModified), context(context) | - | ||||||||||||||||||
| 92 | { | - | ||||||||||||||||||
| 93 | } executed 2146 times by 7 tests: end of blockExecuted by:
| 2146 | ||||||||||||||||||
| 94 | - | |||||||||||||||||||
| 95 | void parse(); | - | ||||||||||||||||||
| 96 | void appendText(const QString &textIn, int start, int length, QString &textOut); | - | ||||||||||||||||||
| 97 | bool parseTag(const QChar *&ch, const QString &textIn, QString &textOut, QTextCharFormat &format); | - | ||||||||||||||||||
| 98 | bool parseCloseTag(const QChar *&ch, const QString &textIn, QString &textOut); | - | ||||||||||||||||||
| 99 | void parseEntity(const QChar *&ch, const QString &textIn, QString &textOut); | - | ||||||||||||||||||
| 100 | bool parseFontAttributes(const QChar *&ch, const QString &textIn, QTextCharFormat &format); | - | ||||||||||||||||||
| 101 | bool parseOrderedListAttributes(const QChar *&ch, const QString &textIn); | - | ||||||||||||||||||
| 102 | bool parseUnorderedListAttributes(const QChar *&ch, const QString &textIn); | - | ||||||||||||||||||
| 103 | bool parseAnchorAttributes(const QChar *&ch, const QString &textIn, QTextCharFormat &format); | - | ||||||||||||||||||
| 104 | void parseImageAttributes(const QChar *&ch, const QString &textIn, QString &textOut); | - | ||||||||||||||||||
| 105 | QPair<QStringRef,QStringRef> parseAttribute(const QChar *&ch, const QString &textIn); | - | ||||||||||||||||||
| 106 | QStringRef parseValue(const QChar *&ch, const QString &textIn); | - | ||||||||||||||||||
| 107 | void setFontSize(int size, QTextCharFormat &format); | - | ||||||||||||||||||
| 108 | - | |||||||||||||||||||
| 109 | inline void skipSpace(const QChar *&ch) { | - | ||||||||||||||||||
| 110 | while (ch->isSpace() && !ch->isNull())
| 0-6806 | ||||||||||||||||||
| 111 | ++ch; executed 1046 times by 3 tests: ++ch;Executed by:
| 1046 | ||||||||||||||||||
| 112 | } executed 6806 times by 7 tests: end of blockExecuted by:
| 6806 | ||||||||||||||||||
| 113 | - | |||||||||||||||||||
| 114 | static QString toAlpha(int value, bool upper); | - | ||||||||||||||||||
| 115 | static QString toRoman(int value, bool upper); | - | ||||||||||||||||||
| 116 | - | |||||||||||||||||||
| 117 | QString text; | - | ||||||||||||||||||
| 118 | QTextLayout &layout; | - | ||||||||||||||||||
| 119 | QList<QQuickStyledTextImgTag*> *imgTags; | - | ||||||||||||||||||
| 120 | QFont baseFont; | - | ||||||||||||||||||
| 121 | QStack<List> listStack; | - | ||||||||||||||||||
| 122 | QUrl baseUrl; | - | ||||||||||||||||||
| 123 | bool hasNewLine; | - | ||||||||||||||||||
| 124 | int nbImages; | - | ||||||||||||||||||
| 125 | bool updateImagePositions; | - | ||||||||||||||||||
| 126 | bool preFormat; | - | ||||||||||||||||||
| 127 | bool prependSpace; | - | ||||||||||||||||||
| 128 | bool hasSpace; | - | ||||||||||||||||||
| 129 | bool preloadImages; | - | ||||||||||||||||||
| 130 | bool *fontSizeModified; | - | ||||||||||||||||||
| 131 | QQmlContext *context; | - | ||||||||||||||||||
| 132 | - | |||||||||||||||||||
| 133 | static const QChar lessThan; | - | ||||||||||||||||||
| 134 | static const QChar greaterThan; | - | ||||||||||||||||||
| 135 | static const QChar equals; | - | ||||||||||||||||||
| 136 | static const QChar singleQuote; | - | ||||||||||||||||||
| 137 | static const QChar doubleQuote; | - | ||||||||||||||||||
| 138 | static const QChar slash; | - | ||||||||||||||||||
| 139 | static const QChar ampersand; | - | ||||||||||||||||||
| 140 | static const QChar bullet; | - | ||||||||||||||||||
| 141 | static const QChar disc; | - | ||||||||||||||||||
| 142 | static const QChar square; | - | ||||||||||||||||||
| 143 | static const QChar lineFeed; | - | ||||||||||||||||||
| 144 | static const QChar space; | - | ||||||||||||||||||
| 145 | static const int tabsize = 6; | - | ||||||||||||||||||
| 146 | }; | - | ||||||||||||||||||
| 147 | - | |||||||||||||||||||
| 148 | const QChar QQuickStyledTextPrivate::lessThan(QLatin1Char('<')); | - | ||||||||||||||||||
| 149 | const QChar QQuickStyledTextPrivate::greaterThan(QLatin1Char('>')); | - | ||||||||||||||||||
| 150 | const QChar QQuickStyledTextPrivate::equals(QLatin1Char('=')); | - | ||||||||||||||||||
| 151 | const QChar QQuickStyledTextPrivate::singleQuote(QLatin1Char('\'')); | - | ||||||||||||||||||
| 152 | const QChar QQuickStyledTextPrivate::doubleQuote(QLatin1Char('\"')); | - | ||||||||||||||||||
| 153 | const QChar QQuickStyledTextPrivate::slash(QLatin1Char('/')); | - | ||||||||||||||||||
| 154 | const QChar QQuickStyledTextPrivate::ampersand(QLatin1Char('&')); | - | ||||||||||||||||||
| 155 | const QChar QQuickStyledTextPrivate::bullet(0x2022); | - | ||||||||||||||||||
| 156 | const QChar QQuickStyledTextPrivate::disc(0x25e6); | - | ||||||||||||||||||
| 157 | const QChar QQuickStyledTextPrivate::square(0x25a1); | - | ||||||||||||||||||
| 158 | const QChar QQuickStyledTextPrivate::lineFeed(QLatin1Char('\n')); | - | ||||||||||||||||||
| 159 | const QChar QQuickStyledTextPrivate::space(QLatin1Char(' ')); | - | ||||||||||||||||||
| 160 | - | |||||||||||||||||||
| 161 | QQuickStyledText::QQuickStyledText(const QString &string, QTextLayout &layout, | - | ||||||||||||||||||
| 162 | QList<QQuickStyledTextImgTag*> &imgTags, | - | ||||||||||||||||||
| 163 | const QUrl &baseUrl, | - | ||||||||||||||||||
| 164 | QQmlContext *context, | - | ||||||||||||||||||
| 165 | bool preloadImages, | - | ||||||||||||||||||
| 166 | bool *fontSizeModified) | - | ||||||||||||||||||
| 167 | : d(new QQuickStyledTextPrivate(string, layout, imgTags, baseUrl, context, preloadImages, fontSizeModified)) | - | ||||||||||||||||||
| 168 | { | - | ||||||||||||||||||
| 169 | } executed 2146 times by 7 tests: end of blockExecuted by:
| 2146 | ||||||||||||||||||
| 170 | - | |||||||||||||||||||
| 171 | QQuickStyledText::~QQuickStyledText() | - | ||||||||||||||||||
| 172 | { | - | ||||||||||||||||||
| 173 | delete d; | - | ||||||||||||||||||
| 174 | } executed 2146 times by 7 tests: end of blockExecuted by:
| 2146 | ||||||||||||||||||
| 175 | - | |||||||||||||||||||
| 176 | void QQuickStyledText::parse(const QString &string, QTextLayout &layout, | - | ||||||||||||||||||
| 177 | QList<QQuickStyledTextImgTag*> &imgTags, | - | ||||||||||||||||||
| 178 | const QUrl &baseUrl, | - | ||||||||||||||||||
| 179 | QQmlContext *context, | - | ||||||||||||||||||
| 180 | bool preloadImages, | - | ||||||||||||||||||
| 181 | bool *fontSizeModified) | - | ||||||||||||||||||
| 182 | { | - | ||||||||||||||||||
| 183 | if (string.isEmpty())
| 2-2146 | ||||||||||||||||||
| 184 | return; executed 2 times by 1 test: return;Executed by:
| 2 | ||||||||||||||||||
| 185 | QQuickStyledText styledText(string, layout, imgTags, baseUrl, context, preloadImages, fontSizeModified); | - | ||||||||||||||||||
| 186 | styledText.d->parse(); | - | ||||||||||||||||||
| 187 | } executed 2146 times by 7 tests: end of blockExecuted by:
| 2146 | ||||||||||||||||||
| 188 | - | |||||||||||||||||||
| 189 | void QQuickStyledTextPrivate::parse() | - | ||||||||||||||||||
| 190 | { | - | ||||||||||||||||||
| 191 | QVector<QTextLayout::FormatRange> ranges; | - | ||||||||||||||||||
| 192 | QStack<QTextCharFormat> formatStack; | - | ||||||||||||||||||
| 193 | - | |||||||||||||||||||
| 194 | QString drawText; | - | ||||||||||||||||||
| 195 | drawText.reserve(text.count()); | - | ||||||||||||||||||
| 196 | - | |||||||||||||||||||
| 197 | updateImagePositions = !imgTags->isEmpty(); | - | ||||||||||||||||||
| 198 | - | |||||||||||||||||||
| 199 | int textStart = 0; | - | ||||||||||||||||||
| 200 | int textLength = 0; | - | ||||||||||||||||||
| 201 | int rangeStart = 0; | - | ||||||||||||||||||
| 202 | bool formatChanged = false; | - | ||||||||||||||||||
| 203 | - | |||||||||||||||||||
| 204 | const QChar *ch = text.constData(); | - | ||||||||||||||||||
| 205 | while (!ch->isNull()) {
| 2146-20051504 | ||||||||||||||||||
| 206 | if (*ch == lessThan) {
| 4844-20046660 | ||||||||||||||||||
| 207 | if (textLength) {
| 2356-2488 | ||||||||||||||||||
| 208 | appendText(text, textStart, textLength, drawText); | - | ||||||||||||||||||
| 209 | } else if (prependSpace) { executed 2356 times by 7 tests: end of blockExecuted by:
| 812-2356 | ||||||||||||||||||
| 210 | drawText.append(space); | - | ||||||||||||||||||
| 211 | prependSpace = false; | - | ||||||||||||||||||
| 212 | hasSpace = true; | - | ||||||||||||||||||
| 213 | } executed 1676 times by 3 tests: end of blockExecuted by:
| 1676 | ||||||||||||||||||
| 214 | - | |||||||||||||||||||
| 215 | if (rangeStart != drawText.length() && formatStack.count()) {
| 778-4066 | ||||||||||||||||||
| 216 | if (formatChanged) {
| 18-2298 | ||||||||||||||||||
| 217 | QTextLayout::FormatRange formatRange; | - | ||||||||||||||||||
| 218 | formatRange.format = formatStack.top(); | - | ||||||||||||||||||
| 219 | formatRange.start = rangeStart; | - | ||||||||||||||||||
| 220 | formatRange.length = drawText.length() - rangeStart; | - | ||||||||||||||||||
| 221 | ranges.append(formatRange); | - | ||||||||||||||||||
| 222 | formatChanged = false; | - | ||||||||||||||||||
| 223 | } else if (ranges.count()) { executed 2298 times by 7 tests: end of blockExecuted by:
| 0-2298 | ||||||||||||||||||
| 224 | ranges.last().length += drawText.length() - rangeStart; | - | ||||||||||||||||||
| 225 | } executed 18 times by 3 tests: end of blockExecuted by:
| 18 | ||||||||||||||||||
| 226 | } executed 2316 times by 7 tests: end of blockExecuted by:
| 2316 | ||||||||||||||||||
| 227 | rangeStart = drawText.length(); | - | ||||||||||||||||||
| 228 | ++ch; | - | ||||||||||||||||||
| 229 | if (*ch == slash) {
| 2220-2624 | ||||||||||||||||||
| 230 | ++ch; | - | ||||||||||||||||||
| 231 | if (parseCloseTag(ch, text, drawText)) {
| 114-2106 | ||||||||||||||||||
| 232 | if (formatStack.count()) {
| 16-2090 | ||||||||||||||||||
| 233 | formatChanged = true; | - | ||||||||||||||||||
| 234 | formatStack.pop(); | - | ||||||||||||||||||
| 235 | } executed 2090 times by 6 tests: end of blockExecuted by:
| 2090 | ||||||||||||||||||
| 236 | } executed 2106 times by 6 tests: end of blockExecuted by:
| 2106 | ||||||||||||||||||
| 237 | } else { executed 2220 times by 6 tests: end of blockExecuted by:
| 2220 | ||||||||||||||||||
| 238 | QTextCharFormat format; | - | ||||||||||||||||||
| 239 | if (formatStack.count())
| 256-2368 | ||||||||||||||||||
| 240 | format = formatStack.top(); executed 256 times by 4 tests: format = formatStack.top();Executed by:
| 256 | ||||||||||||||||||
| 241 | if (parseTag(ch, text, drawText, format)) {
| 504-2120 | ||||||||||||||||||
| 242 | formatChanged = true; | - | ||||||||||||||||||
| 243 | formatStack.push(format); | - | ||||||||||||||||||
| 244 | } executed 2120 times by 7 tests: end of blockExecuted by:
| 2120 | ||||||||||||||||||
| 245 | } executed 2624 times by 7 tests: end of blockExecuted by:
| 2624 | ||||||||||||||||||
| 246 | textStart = ch - text.constData() + 1; | - | ||||||||||||||||||
| 247 | textLength = 0; | - | ||||||||||||||||||
| 248 | } else if (*ch == ampersand) { executed 4844 times by 7 tests: end of blockExecuted by:
| 30-20046630 | ||||||||||||||||||
| 249 | ++ch; | - | ||||||||||||||||||
| 250 | appendText(text, textStart, textLength, drawText); | - | ||||||||||||||||||
| 251 | parseEntity(ch, text, drawText); | - | ||||||||||||||||||
| 252 | textStart = ch - text.constData() + 1; | - | ||||||||||||||||||
| 253 | textLength = 0; | - | ||||||||||||||||||
| 254 | } else if (ch->isSpace()) { executed 30 times by 1 test: end of blockExecuted by:
| 30-20039182 | ||||||||||||||||||
| 255 | if (textLength)
| 1436-6012 | ||||||||||||||||||
| 256 | appendText(text, textStart, textLength, drawText); executed 6012 times by 6 tests: appendText(text, textStart, textLength, drawText);Executed by:
| 6012 | ||||||||||||||||||
| 257 | if (!preFormat) {
| 6-7442 | ||||||||||||||||||
| 258 | prependSpace = !hasSpace; | - | ||||||||||||||||||
| 259 | for (const QChar *n = ch + 1; !n->isNull() && n->isSpace(); ++n)
| 6-20009776 | ||||||||||||||||||
| 260 | ch = n; executed 20002340 times by 3 tests: ch = n;Executed by:
| 20002340 | ||||||||||||||||||
| 261 | hasNewLine = false; | - | ||||||||||||||||||
| 262 | } else if (*ch == lineFeed) { executed 7442 times by 6 tests: end of blockExecuted by:
| 2-7442 | ||||||||||||||||||
| 263 | drawText.append(QChar(QChar::LineSeparator)); | - | ||||||||||||||||||
| 264 | hasNewLine = true; | - | ||||||||||||||||||
| 265 | } else { executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 266 | drawText.append(QChar(QChar::Nbsp)); | - | ||||||||||||||||||
| 267 | hasNewLine = false; | - | ||||||||||||||||||
| 268 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 269 | textStart = ch - text.constData() + 1; | - | ||||||||||||||||||
| 270 | textLength = 0; | - | ||||||||||||||||||
| 271 | } else { executed 7448 times by 6 tests: end of blockExecuted by:
| 7448 | ||||||||||||||||||
| 272 | ++textLength; | - | ||||||||||||||||||
| 273 | } executed 20039182 times by 7 tests: end of blockExecuted by:
| 20039182 | ||||||||||||||||||
| 274 | if (!ch->isNull())
| 10-20051494 | ||||||||||||||||||
| 275 | ++ch; executed 20051494 times by 7 tests: ++ch;Executed by:
| 20051494 | ||||||||||||||||||
| 276 | } executed 20051504 times by 7 tests: end of blockExecuted by:
| 20051504 | ||||||||||||||||||
| 277 | if (textLength)
| 244-1902 | ||||||||||||||||||
| 278 | appendText(text, textStart, textLength, drawText); executed 1902 times by 6 tests: appendText(text, textStart, textLength, drawText);Executed by:
| 1902 | ||||||||||||||||||
| 279 | if (rangeStart != drawText.length() && formatStack.count()) {
| 20-1958 | ||||||||||||||||||
| 280 | if (formatChanged) {
| 4-16 | ||||||||||||||||||
| 281 | QTextLayout::FormatRange formatRange; | - | ||||||||||||||||||
| 282 | formatRange.format = formatStack.top(); | - | ||||||||||||||||||
| 283 | formatRange.start = rangeStart; | - | ||||||||||||||||||
| 284 | formatRange.length = drawText.length() - rangeStart; | - | ||||||||||||||||||
| 285 | ranges.append(formatRange); | - | ||||||||||||||||||
| 286 | } else if (ranges.count()) { executed 16 times by 1 test: end of blockExecuted by:
| 0-16 | ||||||||||||||||||
| 287 | ranges.last().length += drawText.length() - rangeStart; | - | ||||||||||||||||||
| 288 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 289 | } executed 20 times by 1 test: end of blockExecuted by:
| 20 | ||||||||||||||||||
| 290 | - | |||||||||||||||||||
| 291 | layout.setText(drawText); | - | ||||||||||||||||||
| 292 | layout.setFormats(ranges); | - | ||||||||||||||||||
| 293 | } executed 2146 times by 7 tests: end of blockExecuted by:
| 2146 | ||||||||||||||||||
| 294 | - | |||||||||||||||||||
| 295 | void QQuickStyledTextPrivate::appendText(const QString &textIn, int start, int length, QString &textOut) | - | ||||||||||||||||||
| 296 | { | - | ||||||||||||||||||
| 297 | if (prependSpace)
| 4940-5360 | ||||||||||||||||||
| 298 | textOut.append(space); executed 4940 times by 6 tests: textOut.append(space);Executed by:
| 4940 | ||||||||||||||||||
| 299 | textOut.append(QStringRef(&textIn, start, length)); | - | ||||||||||||||||||
| 300 | prependSpace = false; | - | ||||||||||||||||||
| 301 | hasSpace = false; | - | ||||||||||||||||||
| 302 | hasNewLine = false; | - | ||||||||||||||||||
| 303 | } executed 10300 times by 7 tests: end of blockExecuted by:
| 10300 | ||||||||||||||||||
| 304 | - | |||||||||||||||||||
| 305 | // | - | ||||||||||||||||||
| 306 | // Calculates and sets the correct font size in points | - | ||||||||||||||||||
| 307 | // depending on the size multiplier and base font. | - | ||||||||||||||||||
| 308 | // | - | ||||||||||||||||||
| 309 | void QQuickStyledTextPrivate::setFontSize(int size, QTextCharFormat &format) | - | ||||||||||||||||||
| 310 | { | - | ||||||||||||||||||
| 311 | static const qreal scaling[] = { 0.7, 0.8, 1.0, 1.2, 1.5, 2.0, 2.4 }; | - | ||||||||||||||||||
| 312 | if (baseFont.pointSizeF() != -1)
| 648-666 | ||||||||||||||||||
| 313 | format.setFontPointSize(baseFont.pointSize() * scaling[size - 1]); executed 666 times by 2 tests: format.setFontPointSize(baseFont.pointSize() * scaling[size - 1]);Executed by:
| 666 | ||||||||||||||||||
| 314 | else | - | ||||||||||||||||||
| 315 | format.setFontPointSize(baseFont.pixelSize() * qreal(72.) / qreal(qt_defaultDpi()) * scaling[size - 1]); executed 648 times by 1 test: format.setFontPointSize(baseFont.pixelSize() * qreal(72.) / qreal(qt_defaultDpi()) * scaling[size - 1]);Executed by:
| 648 | ||||||||||||||||||
| 316 | *fontSizeModified = true; | - | ||||||||||||||||||
| 317 | } executed 1314 times by 2 tests: end of blockExecuted by:
| 1314 | ||||||||||||||||||
| 318 | - | |||||||||||||||||||
| 319 | bool QQuickStyledTextPrivate::parseTag(const QChar *&ch, const QString &textIn, QString &textOut, QTextCharFormat &format) | - | ||||||||||||||||||
| 320 | { | - | ||||||||||||||||||
| 321 | skipSpace(ch); | - | ||||||||||||||||||
| 322 | - | |||||||||||||||||||
| 323 | int tagStart = ch - textIn.constData(); | - | ||||||||||||||||||
| 324 | int tagLength = 0; | - | ||||||||||||||||||
| 325 | while (!ch->isNull()) {
| 4-8732 | ||||||||||||||||||
| 326 | if (*ch == greaterThan) {
| 1684-7048 | ||||||||||||||||||
| 327 | if (tagLength == 0)
| 6-1678 | ||||||||||||||||||
| 328 | return false; executed 6 times by 2 tests: return false;Executed by:
| 6 | ||||||||||||||||||
| 329 | QStringRef tag(&textIn, tagStart, tagLength); | - | ||||||||||||||||||
| 330 | const QChar char0 = tag.at(0); | - | ||||||||||||||||||
| 331 | if (char0 == QLatin1Char('b')) {
| 760-918 | ||||||||||||||||||
| 332 | if (tagLength == 1) {
| 174-586 | ||||||||||||||||||
| 333 | format.setFontWeight(QFont::Bold); | - | ||||||||||||||||||
| 334 | return true; executed 586 times by 7 tests: return true;Executed by:
| 586 | ||||||||||||||||||
| 335 | } else if (tagLength == 2 && tag.at(1) == QLatin1Char('r')) {
| 2-168 | ||||||||||||||||||
| 336 | textOut.append(QChar(QChar::LineSeparator)); | - | ||||||||||||||||||
| 337 | hasSpace = true; | - | ||||||||||||||||||
| 338 | prependSpace = false; | - | ||||||||||||||||||
| 339 | return false; executed 166 times by 2 tests: return false;Executed by:
| 166 | ||||||||||||||||||
| 340 | } | - | ||||||||||||||||||
| 341 | } else if (char0 == QLatin1Char('i')) { executed 8 times by 1 test: end of blockExecuted by:
| 8-846 | ||||||||||||||||||
| 342 | if (tagLength == 1) {
| 2-70 | ||||||||||||||||||
| 343 | format.setFontItalic(true); | - | ||||||||||||||||||
| 344 | return true; executed 70 times by 2 tests: return true;Executed by:
| 70 | ||||||||||||||||||
| 345 | } | - | ||||||||||||||||||
| 346 | } else if (char0 == QLatin1Char('p')) { executed 2 times by 1 test: end of blockExecuted by:
| 2-824 | ||||||||||||||||||
| 347 | if (tagLength == 1) {
| 10-12 | ||||||||||||||||||
| 348 | if (!hasNewLine)
| 0-12 | ||||||||||||||||||
| 349 | textOut.append(QChar::LineSeparator); executed 12 times by 2 tests: textOut.append(QChar::LineSeparator);Executed by:
| 12 | ||||||||||||||||||
| 350 | hasSpace = true; | - | ||||||||||||||||||
| 351 | prependSpace = false; | - | ||||||||||||||||||
| 352 | } else if (tag == QLatin1String("pre")) { executed 12 times by 2 tests: end of blockExecuted by:
| 4-12 | ||||||||||||||||||
| 353 | preFormat = true; | - | ||||||||||||||||||
| 354 | if (!hasNewLine)
| 0-4 | ||||||||||||||||||
| 355 | textOut.append(QChar::LineSeparator); executed 4 times by 1 test: textOut.append(QChar::LineSeparator);Executed by:
| 4 | ||||||||||||||||||
| 356 | format.setFontFamily(QString::fromLatin1("Courier New,courier")); | - | ||||||||||||||||||
| 357 | format.setFontFixedPitch(true); | - | ||||||||||||||||||
| 358 | return true; executed 4 times by 1 test: return true;Executed by:
| 4 | ||||||||||||||||||
| 359 | } | - | ||||||||||||||||||
| 360 | } else if (char0 == QLatin1Char('u')) { executed 18 times by 2 tests: end of blockExecuted by:
| 18-806 | ||||||||||||||||||
| 361 | if (tagLength == 1) {
| 4-14 | ||||||||||||||||||
| 362 | format.setFontUnderline(true); | - | ||||||||||||||||||
| 363 | return true; executed 4 times by 1 test: return true;Executed by:
| 4 | ||||||||||||||||||
| 364 | } else if (tag == QLatin1String("ul")) {
| 2-12 | ||||||||||||||||||
| 365 | List listItem; | - | ||||||||||||||||||
| 366 | listItem.level = 0; | - | ||||||||||||||||||
| 367 | listItem.type = Unordered; | - | ||||||||||||||||||
| 368 | listItem.format = Bullet; | - | ||||||||||||||||||
| 369 | listStack.push(listItem); | - | ||||||||||||||||||
| 370 | } executed 12 times by 2 tests: end of blockExecuted by:
| 12 | ||||||||||||||||||
| 371 | } else if (char0 == QLatin1Char('h') && tagLength == 2) { executed 14 times by 2 tests: end of blockExecuted by:
| 14-660 | ||||||||||||||||||
| 372 | int level = tag.at(1).digitValue(); | - | ||||||||||||||||||
| 373 | if (level >= 1 && level <= 6) {
| 2-642 | ||||||||||||||||||
| 374 | if (!hasNewLine)
| 16-624 | ||||||||||||||||||
| 375 | textOut.append(QChar::LineSeparator); executed 624 times by 1 test: textOut.append(QChar::LineSeparator);Executed by:
| 624 | ||||||||||||||||||
| 376 | hasSpace = true; | - | ||||||||||||||||||
| 377 | prependSpace = false; | - | ||||||||||||||||||
| 378 | setFontSize(7 - level, format); | - | ||||||||||||||||||
| 379 | format.setFontWeight(QFont::Bold); | - | ||||||||||||||||||
| 380 | return true; executed 640 times by 2 tests: return true;Executed by:
| 640 | ||||||||||||||||||
| 381 | } | - | ||||||||||||||||||
| 382 | } else if (tag == QLatin1String("strong")) { executed 4 times by 1 test: end of blockExecuted by:
| 2-160 | ||||||||||||||||||
| 383 | format.setFontWeight(QFont::Bold); | - | ||||||||||||||||||
| 384 | return true; executed 2 times by 1 test: return true;Executed by:
| 2 | ||||||||||||||||||
| 385 | } else if (tag == QLatin1String("ol")) {
| 12-148 | ||||||||||||||||||
| 386 | List listItem; | - | ||||||||||||||||||
| 387 | listItem.level = 0; | - | ||||||||||||||||||
| 388 | listItem.type = Ordered; | - | ||||||||||||||||||
| 389 | listItem.format = Decimal; | - | ||||||||||||||||||
| 390 | listStack.push(listItem); | - | ||||||||||||||||||
| 391 | } else if (tag == QLatin1String("li")) { executed 12 times by 2 tests: end of blockExecuted by:
| 12-110 | ||||||||||||||||||
| 392 | if (!hasNewLine)
| 24-86 | ||||||||||||||||||
| 393 | textOut.append(QChar(QChar::LineSeparator)); executed 86 times by 2 tests: textOut.append(QChar(QChar::LineSeparator));Executed by:
| 86 | ||||||||||||||||||
| 394 | if (!listStack.isEmpty()) {
| 0-110 | ||||||||||||||||||
| 395 | int count = ++listStack.top().level; | - | ||||||||||||||||||
| 396 | for (int i = 0; i < listStack.size(); ++i)
| 110 | ||||||||||||||||||
| 397 | textOut += QString(tabsize, QChar::Nbsp); executed 110 times by 2 tests: textOut += QString(tabsize, QChar::Nbsp);Executed by:
| 110 | ||||||||||||||||||
| 398 | switch (listStack.top().format) { | - | ||||||||||||||||||
| 399 | case Decimal: executed 40 times by 2 tests: case Decimal:Executed by:
| 40 | ||||||||||||||||||
| 400 | textOut += QString::number(count) % QLatin1Char('.'); | - | ||||||||||||||||||
| 401 | break; executed 40 times by 2 tests: break;Executed by:
| 40 | ||||||||||||||||||
| 402 | case LowerAlpha: executed 4 times by 1 test: case LowerAlpha:Executed by:
| 4 | ||||||||||||||||||
| 403 | textOut += toAlpha(count, false) % QLatin1Char('.'); | - | ||||||||||||||||||
| 404 | break; executed 4 times by 1 test: break;Executed by:
| 4 | ||||||||||||||||||
| 405 | case UpperAlpha: executed 4 times by 1 test: case UpperAlpha:Executed by:
| 4 | ||||||||||||||||||
| 406 | textOut += toAlpha(count, true) % QLatin1Char('.'); | - | ||||||||||||||||||
| 407 | break; executed 4 times by 1 test: break;Executed by:
| 4 | ||||||||||||||||||
| 408 | case LowerRoman: executed 4 times by 1 test: case LowerRoman:Executed by:
| 4 | ||||||||||||||||||
| 409 | textOut += toRoman(count, false) % QLatin1Char('.'); | - | ||||||||||||||||||
| 410 | break; executed 4 times by 1 test: break;Executed by:
| 4 | ||||||||||||||||||
| 411 | case UpperRoman: executed 4 times by 1 test: case UpperRoman:Executed by:
| 4 | ||||||||||||||||||
| 412 | textOut += toRoman(count, true) % QLatin1Char('.'); | - | ||||||||||||||||||
| 413 | break; executed 4 times by 1 test: break;Executed by:
| 4 | ||||||||||||||||||
| 414 | case Bullet: executed 46 times by 2 tests: case Bullet:Executed by:
| 46 | ||||||||||||||||||
| 415 | textOut += bullet; | - | ||||||||||||||||||
| 416 | break; executed 46 times by 2 tests: break;Executed by:
| 46 | ||||||||||||||||||
| 417 | case Disc: executed 4 times by 1 test: case Disc:Executed by:
| 4 | ||||||||||||||||||
| 418 | textOut += disc; | - | ||||||||||||||||||
| 419 | break; executed 4 times by 1 test: break;Executed by:
| 4 | ||||||||||||||||||
| 420 | case Square: executed 4 times by 1 test: case Square:Executed by:
| 4 | ||||||||||||||||||
| 421 | textOut += square; | - | ||||||||||||||||||
| 422 | break; executed 4 times by 1 test: break;Executed by:
| 4 | ||||||||||||||||||
| 423 | } | - | ||||||||||||||||||
| 424 | textOut += QString(2, QChar::Nbsp); | - | ||||||||||||||||||
| 425 | } executed 110 times by 2 tests: end of blockExecuted by:
| 110 | ||||||||||||||||||
| 426 | } executed 110 times by 2 tests: end of blockExecuted by:
| 110 | ||||||||||||||||||
| 427 | return false; executed 206 times by 3 tests: return false;Executed by:
| 206 | ||||||||||||||||||
| 428 | } else if (ch->isSpace()) {
| 938-6110 | ||||||||||||||||||
| 429 | // may have params. | - | ||||||||||||||||||
| 430 | QStringRef tag(&textIn, tagStart, tagLength); | - | ||||||||||||||||||
| 431 | if (tag == QLatin1String("font"))
| 244-694 | ||||||||||||||||||
| 432 | return parseFontAttributes(ch, textIn, format); executed 694 times by 3 tests: return parseFontAttributes(ch, textIn, format);Executed by:
| 694 | ||||||||||||||||||
| 433 | if (tag == QLatin1String("ol")) {
| 10-234 | ||||||||||||||||||
| 434 | parseOrderedListAttributes(ch, textIn); | - | ||||||||||||||||||
| 435 | return false; // doesn't modify format executed 10 times by 1 test: return false;Executed by:
| 10 | ||||||||||||||||||
| 436 | } | - | ||||||||||||||||||
| 437 | if (tag == QLatin1String("ul")) {
| 6-228 | ||||||||||||||||||
| 438 | parseUnorderedListAttributes(ch, textIn); | - | ||||||||||||||||||
| 439 | return false; // doesn't modify format executed 6 times by 1 test: return false;Executed by:
| 6 | ||||||||||||||||||
| 440 | } | - | ||||||||||||||||||
| 441 | if (tag == QLatin1String("a")) {
| 98-130 | ||||||||||||||||||
| 442 | return parseAnchorAttributes(ch, textIn, format); executed 130 times by 2 tests: return parseAnchorAttributes(ch, textIn, format);Executed by:
| 130 | ||||||||||||||||||
| 443 | } | - | ||||||||||||||||||
| 444 | if (tag == QLatin1String("img")) {
| 2-96 | ||||||||||||||||||
| 445 | parseImageAttributes(ch, textIn, textOut); | - | ||||||||||||||||||
| 446 | return false; executed 96 times by 3 tests: return false;Executed by:
| 96 | ||||||||||||||||||
| 447 | } | - | ||||||||||||||||||
| 448 | if (*ch == greaterThan || ch->isNull())
| 0-2 | ||||||||||||||||||
| 449 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 450 | } else if (*ch != slash) { executed 2 times by 1 test: end of blockExecuted by:
| 2-5974 | ||||||||||||||||||
| 451 | tagLength++; | - | ||||||||||||||||||
| 452 | } executed 5974 times by 7 tests: end of blockExecuted by:
| 5974 | ||||||||||||||||||
| 453 | ++ch; | - | ||||||||||||||||||
| 454 | } executed 6112 times by 7 tests: end of blockExecuted by:
| 6112 | ||||||||||||||||||
| 455 | return false; executed 4 times by 2 tests: return false;Executed by:
| 4 | ||||||||||||||||||
| 456 | } | - | ||||||||||||||||||
| 457 | - | |||||||||||||||||||
| 458 | bool QQuickStyledTextPrivate::parseCloseTag(const QChar *&ch, const QString &textIn, QString &textOut) | - | ||||||||||||||||||
| 459 | { | - | ||||||||||||||||||
| 460 | skipSpace(ch); | - | ||||||||||||||||||
| 461 | - | |||||||||||||||||||
| 462 | int tagStart = ch - textIn.constData(); | - | ||||||||||||||||||
| 463 | int tagLength = 0; | - | ||||||||||||||||||
| 464 | while (!ch->isNull()) {
| 4-7304 | ||||||||||||||||||
| 465 | if (*ch == greaterThan) {
| 2216-5088 | ||||||||||||||||||
| 466 | if (tagLength == 0)
| 2-2214 | ||||||||||||||||||
| 467 | return false; executed 2 times by 1 test: return false;Executed by:
| 2 | ||||||||||||||||||
| 468 | QStringRef tag(&textIn, tagStart, tagLength); | - | ||||||||||||||||||
| 469 | const QChar char0 = tag.at(0); | - | ||||||||||||||||||
| 470 | hasNewLine = false; | - | ||||||||||||||||||
| 471 | if (char0 == QLatin1Char('b')) {
| 576-1638 | ||||||||||||||||||
| 472 | if (tagLength == 1)
| 0-576 | ||||||||||||||||||
| 473 | return true; executed 576 times by 6 tests: return true;Executed by:
| 576 | ||||||||||||||||||
| 474 | else if (tag.at(1) == QLatin1Char('r') && tagLength == 2)
| 0 | ||||||||||||||||||
| 475 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 476 | } else if (char0 == QLatin1Char('i')) { never executed: end of block
| 0-1566 | ||||||||||||||||||
| 477 | if (tagLength == 1)
| 2-70 | ||||||||||||||||||
| 478 | return true; executed 70 times by 2 tests: return true;Executed by:
| 70 | ||||||||||||||||||
| 479 | } else if (char0 == QLatin1Char('a')) { executed 2 times by 1 test: end of blockExecuted by:
| 2-1436 | ||||||||||||||||||
| 480 | if (tagLength == 1)
| 2-128 | ||||||||||||||||||
| 481 | return true; executed 128 times by 2 tests: return true;Executed by:
| 128 | ||||||||||||||||||
| 482 | } else if (char0 == QLatin1Char('p')) { executed 2 times by 1 test: end of blockExecuted by:
| 2-1426 | ||||||||||||||||||
| 483 | if (tagLength == 1) {
| 4-6 | ||||||||||||||||||
| 484 | textOut.append(QChar::LineSeparator); | - | ||||||||||||||||||
| 485 | hasNewLine = true; | - | ||||||||||||||||||
| 486 | hasSpace = true; | - | ||||||||||||||||||
| 487 | return false; executed 6 times by 1 test: return false;Executed by:
| 6 | ||||||||||||||||||
| 488 | } else if (tag == QLatin1String("pre")) {
| 0-4 | ||||||||||||||||||
| 489 | preFormat = false; | - | ||||||||||||||||||
| 490 | if (!hasNewLine)
| 0-4 | ||||||||||||||||||
| 491 | textOut.append(QChar::LineSeparator); executed 4 times by 1 test: textOut.append(QChar::LineSeparator);Executed by:
| 4 | ||||||||||||||||||
| 492 | hasNewLine = true; | - | ||||||||||||||||||
| 493 | hasSpace = true; | - | ||||||||||||||||||
| 494 | return true; executed 4 times by 1 test: return true;Executed by:
| 4 | ||||||||||||||||||
| 495 | } | - | ||||||||||||||||||
| 496 | } else if (char0 == QLatin1Char('u')) { never executed: end of block
| 0-1406 | ||||||||||||||||||
| 497 | if (tagLength == 1)
| 4-16 | ||||||||||||||||||
| 498 | return true; executed 4 times by 1 test: return true;Executed by:
| 4 | ||||||||||||||||||
| 499 | else if (tag == QLatin1String("ul")) {
| 0-16 | ||||||||||||||||||
| 500 | if (!listStack.isEmpty()) {
| 0-16 | ||||||||||||||||||
| 501 | listStack.pop(); | - | ||||||||||||||||||
| 502 | if (!listStack.count())
| 0-16 | ||||||||||||||||||
| 503 | textOut.append(QChar::LineSeparator); executed 16 times by 2 tests: textOut.append(QChar::LineSeparator);Executed by:
| 16 | ||||||||||||||||||
| 504 | } executed 16 times by 2 tests: end of blockExecuted by:
| 16 | ||||||||||||||||||
| 505 | return false; executed 16 times by 2 tests: return false;Executed by:
| 16 | ||||||||||||||||||
| 506 | } | - | ||||||||||||||||||
| 507 | } else if (char0 == QLatin1Char('h') && tagLength == 2) { never executed: end of block
| 0-762 | ||||||||||||||||||
| 508 | textOut.append(QChar::LineSeparator); | - | ||||||||||||||||||
| 509 | hasNewLine = true; | - | ||||||||||||||||||
| 510 | hasSpace = true; | - | ||||||||||||||||||
| 511 | return true; executed 628 times by 2 tests: return true;Executed by:
| 628 | ||||||||||||||||||
| 512 | } else if (tag == QLatin1String("font")) {
| 84-694 | ||||||||||||||||||
| 513 | return true; executed 694 times by 3 tests: return true;Executed by:
| 694 | ||||||||||||||||||
| 514 | } else if (tag == QLatin1String("strong")) {
| 2-82 | ||||||||||||||||||
| 515 | return true; executed 2 times by 1 test: return true;Executed by:
| 2 | ||||||||||||||||||
| 516 | } else if (tag == QLatin1String("ol")) {
| 20-62 | ||||||||||||||||||
| 517 | if (!listStack.isEmpty()) {
| 0-20 | ||||||||||||||||||
| 518 | listStack.pop(); | - | ||||||||||||||||||
| 519 | if (!listStack.count())
| 0-20 | ||||||||||||||||||
| 520 | textOut.append(QChar::LineSeparator); executed 20 times by 2 tests: textOut.append(QChar::LineSeparator);Executed by:
| 20 | ||||||||||||||||||
| 521 | } executed 20 times by 2 tests: end of blockExecuted by:
| 20 | ||||||||||||||||||
| 522 | return false; executed 20 times by 2 tests: return false;Executed by:
| 20 | ||||||||||||||||||
| 523 | } else if (tag == QLatin1String("li")) {
| 22-40 | ||||||||||||||||||
| 524 | return false; executed 40 times by 1 test: return false;Executed by:
| 40 | ||||||||||||||||||
| 525 | } | - | ||||||||||||||||||
| 526 | return false; executed 26 times by 2 tests: return false;Executed by:
| 26 | ||||||||||||||||||
| 527 | } else if (!ch->isSpace()){
| 0-5088 | ||||||||||||||||||
| 528 | tagLength++; | - | ||||||||||||||||||
| 529 | } executed 5088 times by 6 tests: end of blockExecuted by:
| 5088 | ||||||||||||||||||
| 530 | ++ch; | - | ||||||||||||||||||
| 531 | } executed 5088 times by 6 tests: end of blockExecuted by:
| 5088 | ||||||||||||||||||
| 532 | - | |||||||||||||||||||
| 533 | return false; executed 4 times by 1 test: return false;Executed by:
| 4 | ||||||||||||||||||
| 534 | } | - | ||||||||||||||||||
| 535 | - | |||||||||||||||||||
| 536 | void QQuickStyledTextPrivate::parseEntity(const QChar *&ch, const QString &textIn, QString &textOut) | - | ||||||||||||||||||
| 537 | { | - | ||||||||||||||||||
| 538 | int entityStart = ch - textIn.constData(); | - | ||||||||||||||||||
| 539 | int entityLength = 0; | - | ||||||||||||||||||
| 540 | while (!ch->isNull()) {
| 0-122 | ||||||||||||||||||
| 541 | if (*ch == QLatin1Char(';')) {
| 26-96 | ||||||||||||||||||
| 542 | QStringRef entity(&textIn, entityStart, entityLength); | - | ||||||||||||||||||
| 543 | if (entity == QLatin1String("gt"))
| 6-20 | ||||||||||||||||||
| 544 | textOut += QChar(62); executed 6 times by 1 test: textOut += QChar(62);Executed by:
| 6 | ||||||||||||||||||
| 545 | else if (entity == QLatin1String("lt"))
| 6-14 | ||||||||||||||||||
| 546 | textOut += QChar(60); executed 6 times by 1 test: textOut += QChar(60);Executed by:
| 6 | ||||||||||||||||||
| 547 | else if (entity == QLatin1String("amp"))
| 4-10 | ||||||||||||||||||
| 548 | textOut += QChar(38); executed 4 times by 1 test: textOut += QChar(38);Executed by:
| 4 | ||||||||||||||||||
| 549 | else if (entity == QLatin1String("quot"))
| 4-6 | ||||||||||||||||||
| 550 | textOut += QChar(34); executed 6 times by 1 test: textOut += QChar(34);Executed by:
| 6 | ||||||||||||||||||
| 551 | else if (entity == QLatin1String("nbsp"))
| 2 | ||||||||||||||||||
| 552 | textOut += QChar(QChar::Nbsp); executed 2 times by 1 test: textOut += QChar(QChar::Nbsp);Executed by:
| 2 | ||||||||||||||||||
| 553 | return; executed 26 times by 1 test: return;Executed by:
| 26 | ||||||||||||||||||
| 554 | } else if (*ch == QLatin1Char(' ')) {
| 4-92 | ||||||||||||||||||
| 555 | QStringRef entity(&textIn, entityStart - 1, entityLength + 1); | - | ||||||||||||||||||
| 556 | textOut += entity + *ch; | - | ||||||||||||||||||
| 557 | return; executed 4 times by 1 test: return;Executed by:
| 4 | ||||||||||||||||||
| 558 | } | - | ||||||||||||||||||
| 559 | ++entityLength; | - | ||||||||||||||||||
| 560 | ++ch; | - | ||||||||||||||||||
| 561 | } executed 92 times by 1 test: end of blockExecuted by:
| 92 | ||||||||||||||||||
| 562 | } never executed: end of block | 0 | ||||||||||||||||||
| 563 | - | |||||||||||||||||||
| 564 | bool QQuickStyledTextPrivate::parseFontAttributes(const QChar *&ch, const QString &textIn, QTextCharFormat &format) | - | ||||||||||||||||||
| 565 | { | - | ||||||||||||||||||
| 566 | bool valid = false; | - | ||||||||||||||||||
| 567 | QPair<QStringRef,QStringRef> attr; | - | ||||||||||||||||||
| 568 | do { | - | ||||||||||||||||||
| 569 | attr = parseAttribute(ch, textIn); | - | ||||||||||||||||||
| 570 | if (attr.first == QLatin1String("color")) {
| 16-1370 | ||||||||||||||||||
| 571 | valid = true; | - | ||||||||||||||||||
| 572 | format.setForeground(QColor(attr.second.toString())); | - | ||||||||||||||||||
| 573 | } else if (attr.first == QLatin1String("size")) { executed 16 times by 2 tests: end of blockExecuted by:
| 16-696 | ||||||||||||||||||
| 574 | valid = true; | - | ||||||||||||||||||
| 575 | int size = attr.second.toString().toInt(); | - | ||||||||||||||||||
| 576 | if (attr.second.at(0) == QLatin1Char('-') || attr.second.at(0) == QLatin1Char('+'))
| 0-674 | ||||||||||||||||||
| 577 | size += 3; never executed: size += 3; | 0 | ||||||||||||||||||
| 578 | if (size >= 1 && size <= 7)
| 0-674 | ||||||||||||||||||
| 579 | setFontSize(size, format); executed 674 times by 2 tests: setFontSize(size, format);Executed by:
| 674 | ||||||||||||||||||
| 580 | } executed 674 times by 2 tests: end of blockExecuted by:
| 674 | ||||||||||||||||||
| 581 | } while (!ch->isNull() && !attr.first.isEmpty()); executed 1386 times by 3 tests: end of blockExecuted by:
| 2-1386 | ||||||||||||||||||
| 582 | - | |||||||||||||||||||
| 583 | return valid; executed 694 times by 3 tests: return valid;Executed by:
| 694 | ||||||||||||||||||
| 584 | } | - | ||||||||||||||||||
| 585 | - | |||||||||||||||||||
| 586 | bool QQuickStyledTextPrivate::parseOrderedListAttributes(const QChar *&ch, const QString &textIn) | - | ||||||||||||||||||
| 587 | { | - | ||||||||||||||||||
| 588 | bool valid = false; | - | ||||||||||||||||||
| 589 | - | |||||||||||||||||||
| 590 | List listItem; | - | ||||||||||||||||||
| 591 | listItem.level = 0; | - | ||||||||||||||||||
| 592 | listItem.type = Ordered; | - | ||||||||||||||||||
| 593 | listItem.format = Decimal; | - | ||||||||||||||||||
| 594 | - | |||||||||||||||||||
| 595 | QPair<QStringRef,QStringRef> attr; | - | ||||||||||||||||||
| 596 | do { | - | ||||||||||||||||||
| 597 | attr = parseAttribute(ch, textIn); | - | ||||||||||||||||||
| 598 | if (attr.first == QLatin1String("type")) {
| 10 | ||||||||||||||||||
| 599 | valid = true; | - | ||||||||||||||||||
| 600 | if (attr.second == QLatin1String("a"))
| 2-8 | ||||||||||||||||||
| 601 | listItem.format = LowerAlpha; executed 2 times by 1 test: listItem.format = LowerAlpha;Executed by:
| 2 | ||||||||||||||||||
| 602 | else if (attr.second == QLatin1String("A"))
| 2-6 | ||||||||||||||||||
| 603 | listItem.format = UpperAlpha; executed 2 times by 1 test: listItem.format = UpperAlpha;Executed by:
| 2 | ||||||||||||||||||
| 604 | else if (attr.second == QLatin1String("i"))
| 2-4 | ||||||||||||||||||
| 605 | listItem.format = LowerRoman; executed 2 times by 1 test: listItem.format = LowerRoman;Executed by:
| 2 | ||||||||||||||||||
| 606 | else if (attr.second == QLatin1String("I"))
| 2 | ||||||||||||||||||
| 607 | listItem.format = UpperRoman; executed 2 times by 1 test: listItem.format = UpperRoman;Executed by:
| 2 | ||||||||||||||||||
| 608 | } executed 10 times by 1 test: end of blockExecuted by:
| 10 | ||||||||||||||||||
| 609 | } while (!ch->isNull() && !attr.first.isEmpty()); executed 20 times by 1 test: end of blockExecuted by:
| 0-20 | ||||||||||||||||||
| 610 | - | |||||||||||||||||||
| 611 | listStack.push(listItem); | - | ||||||||||||||||||
| 612 | return valid; executed 10 times by 1 test: return valid;Executed by:
| 10 | ||||||||||||||||||
| 613 | } | - | ||||||||||||||||||
| 614 | - | |||||||||||||||||||
| 615 | bool QQuickStyledTextPrivate::parseUnorderedListAttributes(const QChar *&ch, const QString &textIn) | - | ||||||||||||||||||
| 616 | { | - | ||||||||||||||||||
| 617 | bool valid = false; | - | ||||||||||||||||||
| 618 | - | |||||||||||||||||||
| 619 | List listItem; | - | ||||||||||||||||||
| 620 | listItem.level = 0; | - | ||||||||||||||||||
| 621 | listItem.type = Unordered; | - | ||||||||||||||||||
| 622 | listItem.format = Bullet; | - | ||||||||||||||||||
| 623 | - | |||||||||||||||||||
| 624 | QPair<QStringRef,QStringRef> attr; | - | ||||||||||||||||||
| 625 | do { | - | ||||||||||||||||||
| 626 | attr = parseAttribute(ch, textIn); | - | ||||||||||||||||||
| 627 | if (attr.first == QLatin1String("type")) {
| 6 | ||||||||||||||||||
| 628 | valid = true; | - | ||||||||||||||||||
| 629 | if (attr.second == QLatin1String("disc"))
| 2-4 | ||||||||||||||||||
| 630 | listItem.format = Disc; executed 2 times by 1 test: listItem.format = Disc;Executed by:
| 2 | ||||||||||||||||||
| 631 | else if (attr.second == QLatin1String("square"))
| 2 | ||||||||||||||||||
| 632 | listItem.format = Square; executed 2 times by 1 test: listItem.format = Square;Executed by:
| 2 | ||||||||||||||||||
| 633 | } executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||||||||
| 634 | } while (!ch->isNull() && !attr.first.isEmpty()); executed 12 times by 1 test: end of blockExecuted by:
| 0-12 | ||||||||||||||||||
| 635 | - | |||||||||||||||||||
| 636 | listStack.push(listItem); | - | ||||||||||||||||||
| 637 | return valid; executed 6 times by 1 test: return valid;Executed by:
| 6 | ||||||||||||||||||
| 638 | } | - | ||||||||||||||||||
| 639 | - | |||||||||||||||||||
| 640 | bool QQuickStyledTextPrivate::parseAnchorAttributes(const QChar *&ch, const QString &textIn, QTextCharFormat &format) | - | ||||||||||||||||||
| 641 | { | - | ||||||||||||||||||
| 642 | bool valid = false; | - | ||||||||||||||||||
| 643 | - | |||||||||||||||||||
| 644 | QPair<QStringRef,QStringRef> attr; | - | ||||||||||||||||||
| 645 | do { | - | ||||||||||||||||||
| 646 | attr = parseAttribute(ch, textIn); | - | ||||||||||||||||||
| 647 | if (attr.first == QLatin1String("href")) {
| 124-132 | ||||||||||||||||||
| 648 | format.setAnchorHref(attr.second.toString()); | - | ||||||||||||||||||
| 649 | format.setAnchor(true); | - | ||||||||||||||||||
| 650 | format.setFontUnderline(true); | - | ||||||||||||||||||
| 651 | valid = true; | - | ||||||||||||||||||
| 652 | } executed 124 times by 2 tests: end of blockExecuted by:
| 124 | ||||||||||||||||||
| 653 | } while (!ch->isNull() && !attr.first.isEmpty()); executed 256 times by 2 tests: end of blockExecuted by:
| 0-256 | ||||||||||||||||||
| 654 | - | |||||||||||||||||||
| 655 | return valid; executed 130 times by 2 tests: return valid;Executed by:
| 130 | ||||||||||||||||||
| 656 | } | - | ||||||||||||||||||
| 657 | - | |||||||||||||||||||
| 658 | void QQuickStyledTextPrivate::parseImageAttributes(const QChar *&ch, const QString &textIn, QString &textOut) | - | ||||||||||||||||||
| 659 | { | - | ||||||||||||||||||
| 660 | qreal imgWidth = 0.0; | - | ||||||||||||||||||
| 661 | QFontMetricsF fm(layout.font()); | - | ||||||||||||||||||
| 662 | const qreal spaceWidth = fm.width(QChar::Nbsp); | - | ||||||||||||||||||
| 663 | const bool trailingSpace = textOut.endsWith(space); | - | ||||||||||||||||||
| 664 | - | |||||||||||||||||||
| 665 | if (!updateImagePositions) {
| 10-86 | ||||||||||||||||||
| 666 | QQuickStyledTextImgTag *image = new QQuickStyledTextImgTag; | - | ||||||||||||||||||
| 667 | image->position = textOut.length() + (trailingSpace ? 0 : 1);
| 34-52 | ||||||||||||||||||
| 668 | - | |||||||||||||||||||
| 669 | QPair<QStringRef,QStringRef> attr; | - | ||||||||||||||||||
| 670 | do { | - | ||||||||||||||||||
| 671 | attr = parseAttribute(ch, textIn); | - | ||||||||||||||||||
| 672 | if (attr.first == QLatin1String("src")) {
| 86-180 | ||||||||||||||||||
| 673 | image->url = QUrl(attr.second.toString()); | - | ||||||||||||||||||
| 674 | } else if (attr.first == QLatin1String("width")) { executed 86 times by 3 tests: end of blockExecuted by:
| 30-150 | ||||||||||||||||||
| 675 | image->size.setWidth(attr.second.toString().toInt()); | - | ||||||||||||||||||
| 676 | } else if (attr.first == QLatin1String("height")) { executed 30 times by 2 tests: end of blockExecuted by:
| 30-120 | ||||||||||||||||||
| 677 | image->size.setHeight(attr.second.toString().toInt()); | - | ||||||||||||||||||
| 678 | } else if (attr.first == QLatin1String("align")) { executed 30 times by 2 tests: end of blockExecuted by:
| 30-86 | ||||||||||||||||||
| 679 | if (attr.second.toString() == QLatin1String("top")) {
| 8-26 | ||||||||||||||||||
| 680 | image->align = QQuickStyledTextImgTag::Top; | - | ||||||||||||||||||
| 681 | } else if (attr.second.toString() == QLatin1String("middle")) { executed 8 times by 2 tests: end of blockExecuted by:
| 8-16 | ||||||||||||||||||
| 682 | image->align = QQuickStyledTextImgTag::Middle; | - | ||||||||||||||||||
| 683 | } executed 16 times by 2 tests: end of blockExecuted by:
| 16 | ||||||||||||||||||
| 684 | } executed 34 times by 2 tests: end of blockExecuted by:
| 34 | ||||||||||||||||||
| 685 | } while (!ch->isNull() && !attr.first.isEmpty()); executed 266 times by 3 tests: end of blockExecuted by:
| 0-266 | ||||||||||||||||||
| 686 | - | |||||||||||||||||||
| 687 | if (preloadImages && !image->size.isValid()) {
| 6-80 | ||||||||||||||||||
| 688 | // if we don't know its size but the image is a local image, | - | ||||||||||||||||||
| 689 | // we load it in the pixmap cache and save its implicit size | - | ||||||||||||||||||
| 690 | // to avoid a relayout later on. | - | ||||||||||||||||||
| 691 | QUrl url = baseUrl.resolved(image->url); | - | ||||||||||||||||||
| 692 | if (url.isLocalFile()) {
| 8-44 | ||||||||||||||||||
| 693 | image->pix = new QQuickPixmap(context->engine(), url, image->size); | - | ||||||||||||||||||
| 694 | if (image->pix && image->pix->isReady()) {
| 0-44 | ||||||||||||||||||
| 695 | image->size = image->pix->implicitSize(); | - | ||||||||||||||||||
| 696 | } else { executed 44 times by 2 tests: end of blockExecuted by:
| 44 | ||||||||||||||||||
| 697 | delete image->pix; | - | ||||||||||||||||||
| 698 | image->pix = nullptr; | - | ||||||||||||||||||
| 699 | } never executed: end of block | 0 | ||||||||||||||||||
| 700 | } | - | ||||||||||||||||||
| 701 | } executed 52 times by 2 tests: end of blockExecuted by:
| 52 | ||||||||||||||||||
| 702 | - | |||||||||||||||||||
| 703 | imgWidth = image->size.width(); | - | ||||||||||||||||||
| 704 | image->offset = -std::fmod(imgWidth, spaceWidth) / 2.0; | - | ||||||||||||||||||
| 705 | imgTags->append(image); | - | ||||||||||||||||||
| 706 | - | |||||||||||||||||||
| 707 | } else { executed 86 times by 3 tests: end of blockExecuted by:
| 86 | ||||||||||||||||||
| 708 | // if we already have a list of img tags for this text | - | ||||||||||||||||||
| 709 | // we only want to update the positions of these tags. | - | ||||||||||||||||||
| 710 | QQuickStyledTextImgTag *image = imgTags->value(nbImages); | - | ||||||||||||||||||
| 711 | image->position = textOut.length() + (trailingSpace ? 0 : 1);
| 4-6 | ||||||||||||||||||
| 712 | imgWidth = image->size.width(); | - | ||||||||||||||||||
| 713 | image->offset = -std::fmod(imgWidth, spaceWidth) / 2.0; | - | ||||||||||||||||||
| 714 | QPair<QStringRef,QStringRef> attr; | - | ||||||||||||||||||
| 715 | do { | - | ||||||||||||||||||
| 716 | attr = parseAttribute(ch, textIn); | - | ||||||||||||||||||
| 717 | } while (!ch->isNull() && !attr.first.isEmpty()); executed 22 times by 2 tests: end of blockExecuted by:
| 0-22 | ||||||||||||||||||
| 718 | nbImages++; | - | ||||||||||||||||||
| 719 | } executed 10 times by 2 tests: end of blockExecuted by:
| 10 | ||||||||||||||||||
| 720 | - | |||||||||||||||||||
| 721 | QString padding(qFloor(imgWidth / spaceWidth), QChar::Nbsp); | - | ||||||||||||||||||
| 722 | if (!trailingSpace)
| 38-58 | ||||||||||||||||||
| 723 | textOut += QLatin1Char(' '); executed 38 times by 3 tests: textOut += QLatin1Char(' ');Executed by:
| 38 | ||||||||||||||||||
| 724 | textOut += padding + QLatin1Char(' '); | - | ||||||||||||||||||
| 725 | } executed 96 times by 3 tests: end of blockExecuted by:
| 96 | ||||||||||||||||||
| 726 | - | |||||||||||||||||||
| 727 | QPair<QStringRef,QStringRef> QQuickStyledTextPrivate::parseAttribute(const QChar *&ch, const QString &textIn) | - | ||||||||||||||||||
| 728 | { | - | ||||||||||||||||||
| 729 | skipSpace(ch); | - | ||||||||||||||||||
| 730 | - | |||||||||||||||||||
| 731 | int attrStart = ch - textIn.constData(); | - | ||||||||||||||||||
| 732 | int attrLength = 0; | - | ||||||||||||||||||
| 733 | while (!ch->isNull()) {
| 0-6186 | ||||||||||||||||||
| 734 | if (*ch == greaterThan) {
| 930-5256 | ||||||||||||||||||
| 735 | break; executed 930 times by 3 tests: break;Executed by:
| 930 | ||||||||||||||||||
| 736 | } else if (*ch == equals) {
| 1032-4224 | ||||||||||||||||||
| 737 | ++ch; | - | ||||||||||||||||||
| 738 | if (*ch != singleQuote && *ch != doubleQuote) {
| 4-1028 | ||||||||||||||||||
| 739 | while (*ch != greaterThan && !ch->isNull())
| 0-4 | ||||||||||||||||||
| 740 | ++ch; never executed: ++ch; | 0 | ||||||||||||||||||
| 741 | break; executed 4 times by 1 test: break;Executed by:
| 4 | ||||||||||||||||||
| 742 | } | - | ||||||||||||||||||
| 743 | ++ch; | - | ||||||||||||||||||
| 744 | if (!attrLength)
| 0-1028 | ||||||||||||||||||
| 745 | break; never executed: break; | 0 | ||||||||||||||||||
| 746 | QStringRef attr(&textIn, attrStart, attrLength); | - | ||||||||||||||||||
| 747 | QStringRef val = parseValue(ch, textIn); | - | ||||||||||||||||||
| 748 | if (!val.isEmpty())
| 2-1026 | ||||||||||||||||||
| 749 | return QPair<QStringRef,QStringRef>(attr,val); executed 1026 times by 3 tests: return QPair<QStringRef,QStringRef>(attr,val);Executed by:
| 1026 | ||||||||||||||||||
| 750 | break; executed 2 times by 1 test: break;Executed by:
| 2 | ||||||||||||||||||
| 751 | } else { | - | ||||||||||||||||||
| 752 | ++attrLength; | - | ||||||||||||||||||
| 753 | } executed 4224 times by 3 tests: end of blockExecuted by:
| 4224 | ||||||||||||||||||
| 754 | ++ch; | - | ||||||||||||||||||
| 755 | } executed 4224 times by 3 tests: end of blockExecuted by:
| 4224 | ||||||||||||||||||
| 756 | - | |||||||||||||||||||
| 757 | return QPair<QStringRef,QStringRef>(); executed 936 times by 3 tests: return QPair<QStringRef,QStringRef>();Executed by:
| 936 | ||||||||||||||||||
| 758 | } | - | ||||||||||||||||||
| 759 | - | |||||||||||||||||||
| 760 | QStringRef QQuickStyledTextPrivate::parseValue(const QChar *&ch, const QString &textIn) | - | ||||||||||||||||||
| 761 | { | - | ||||||||||||||||||
| 762 | int valStart = ch - textIn.constData(); | - | ||||||||||||||||||
| 763 | int valLength = 0; | - | ||||||||||||||||||
| 764 | while (*ch != singleQuote && *ch != doubleQuote && !ch->isNull()) {
| 2-7680 | ||||||||||||||||||
| 765 | ++valLength; | - | ||||||||||||||||||
| 766 | ++ch; | - | ||||||||||||||||||
| 767 | } executed 6658 times by 3 tests: end of blockExecuted by:
| 6658 | ||||||||||||||||||
| 768 | if (ch->isNull())
| 2-1026 | ||||||||||||||||||
| 769 | return QStringRef(); executed 2 times by 1 test: return QStringRef();Executed by:
| 2 | ||||||||||||||||||
| 770 | ++ch; // skip quote | - | ||||||||||||||||||
| 771 | - | |||||||||||||||||||
| 772 | return QStringRef(&textIn, valStart, valLength); executed 1026 times by 3 tests: return QStringRef(&textIn, valStart, valLength);Executed by:
| 1026 | ||||||||||||||||||
| 773 | } | - | ||||||||||||||||||
| 774 | - | |||||||||||||||||||
| 775 | QString QQuickStyledTextPrivate::toAlpha(int value, bool upper) | - | ||||||||||||||||||
| 776 | { | - | ||||||||||||||||||
| 777 | const char baseChar = upper ? 'A' : 'a';
| 4 | ||||||||||||||||||
| 778 | - | |||||||||||||||||||
| 779 | QString result; | - | ||||||||||||||||||
| 780 | int c = value; | - | ||||||||||||||||||
| 781 | while (c > 0) {
| 8 | ||||||||||||||||||
| 782 | c--; | - | ||||||||||||||||||
| 783 | result.prepend(QChar(baseChar + (c % 26))); | - | ||||||||||||||||||
| 784 | c /= 26; | - | ||||||||||||||||||
| 785 | } executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||||||||
| 786 | return result; executed 8 times by 1 test: return result;Executed by:
| 8 | ||||||||||||||||||
| 787 | } | - | ||||||||||||||||||
| 788 | - | |||||||||||||||||||
| 789 | QString QQuickStyledTextPrivate::toRoman(int value, bool upper) | - | ||||||||||||||||||
| 790 | { | - | ||||||||||||||||||
| 791 | QString result = QLatin1String("?"); | - | ||||||||||||||||||
| 792 | // works for up to 4999 items | - | ||||||||||||||||||
| 793 | if (value < 5000) {
| 0-8 | ||||||||||||||||||
| 794 | QByteArray romanNumeral; | - | ||||||||||||||||||
| 795 | - | |||||||||||||||||||
| 796 | static const char romanSymbolsLower[] = "iiivixxxlxcccdcmmmm"; | - | ||||||||||||||||||
| 797 | static const char romanSymbolsUpper[] = "IIIVIXXXLXCCCDCMMMM"; | - | ||||||||||||||||||
| 798 | QByteArray romanSymbols; | - | ||||||||||||||||||
| 799 | if (!upper)
| 4 | ||||||||||||||||||
| 800 | romanSymbols = QByteArray::fromRawData(romanSymbolsLower, sizeof(romanSymbolsLower)); executed 4 times by 1 test: romanSymbols = QByteArray::fromRawData(romanSymbolsLower, sizeof(romanSymbolsLower));Executed by:
| 4 | ||||||||||||||||||
| 801 | else | - | ||||||||||||||||||
| 802 | romanSymbols = QByteArray::fromRawData(romanSymbolsUpper, sizeof(romanSymbolsUpper)); executed 4 times by 1 test: romanSymbols = QByteArray::fromRawData(romanSymbolsUpper, sizeof(romanSymbolsUpper));Executed by:
| 4 | ||||||||||||||||||
| 803 | - | |||||||||||||||||||
| 804 | int c[] = { 1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000 }; | - | ||||||||||||||||||
| 805 | int n = value; | - | ||||||||||||||||||
| 806 | for (int i = 12; i >= 0; n %= c[i], i--) {
| 8-104 | ||||||||||||||||||
| 807 | int q = n / c[i]; | - | ||||||||||||||||||
| 808 | if (q > 0) {
| 8-96 | ||||||||||||||||||
| 809 | int startDigit = i + (i + 3) / 4; | - | ||||||||||||||||||
| 810 | int numDigits; | - | ||||||||||||||||||
| 811 | if (i % 4) {
| 0-8 | ||||||||||||||||||
| 812 | if ((i - 2) % 4)
| 0 | ||||||||||||||||||
| 813 | numDigits = 2; never executed: numDigits = 2; | 0 | ||||||||||||||||||
| 814 | else | - | ||||||||||||||||||
| 815 | numDigits = 1; never executed: numDigits = 1; | 0 | ||||||||||||||||||
| 816 | } | - | ||||||||||||||||||
| 817 | else | - | ||||||||||||||||||
| 818 | numDigits = q; executed 8 times by 1 test: numDigits = q;Executed by:
| 8 | ||||||||||||||||||
| 819 | romanNumeral.append(romanSymbols.mid(startDigit, numDigits)); | - | ||||||||||||||||||
| 820 | } executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||||||||
| 821 | } executed 104 times by 1 test: end of blockExecuted by:
| 104 | ||||||||||||||||||
| 822 | result = QString::fromLatin1(romanNumeral); | - | ||||||||||||||||||
| 823 | } executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||||||||
| 824 | return result; executed 8 times by 1 test: return result;Executed by:
| 8 | ||||||||||||||||||
| 825 | } | - | ||||||||||||||||||
| 826 | - | |||||||||||||||||||
| 827 | QT_END_NAMESPACE | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |