diff --git a/src/plasma/svg.cpp b/src/plasma/svg.cpp --- a/src/plasma/svg.cpp +++ b/src/plasma/svg.cpp @@ -85,6 +85,9 @@ const QString &styleSheet, QHash &interestingElements) { + QVector elements; + static const QRegularExpression interestingIdExpr(QStringLiteral("-[a-z]")); + // Apply the style sheet. if (!styleSheet.isEmpty() && contents.contains("current-color-scheme")) { QByteArray processedContents; @@ -94,8 +97,18 @@ QBuffer buffer(&processedContents); buffer.open(QIODevice::WriteOnly); QXmlStreamWriter writer(&buffer); + + while (!reader.atEnd()) { - if (reader.readNext() == QXmlStreamReader::StartElement && + const auto element = reader.readNext(); + if (element == QXmlStreamReader::StartElement) { + const QStringRef id = reader.attributes().value(QLatin1String("id")); + if (interestingIdExpr.match(id).hasMatch()) { + elements << id.toString(); + } + } + + if (element == QXmlStreamReader::StartElement && reader.qualifiedName() == QLatin1String("style") && reader.attributes().value(QLatin1String("id")) == QLatin1String("current-color-scheme")) { writer.writeStartElement(QLatin1String("style")); @@ -113,20 +126,25 @@ if (!QSvgRenderer::load(processedContents)) { return false; } - } else if (!QSvgRenderer::load(contents)) { - return false; - } + } else { + if (!QSvgRenderer::load(contents)) + return false; - // Search the SVG to find and store all ids that contain size hints. - const QString contentsAsString(QString::fromLatin1(contents)); - static const QRegularExpression idExpr(QLatin1String("id\\s*?=\\s*?(['\"])(\\d+?-\\d+?-.*?)\\1")); - Q_ASSERT(idExpr.isValid()); + // Search the SVG to find and store all ids that contain size hints. + const QString contentsAsString(QString::fromLatin1(contents)); + static const QRegularExpression idExpr(QLatin1String("id\\s*?=\\s*?(['\"])(.*?)\\1")); + Q_ASSERT(idExpr.isValid()); - auto matchIt = idExpr.globalMatch(contentsAsString); - while (matchIt.hasNext()) { - auto match = matchIt.next(); - QString elementId = match.captured(2); + auto matchIt = idExpr.globalMatch(contentsAsString); + while (matchIt.hasNext()) { + auto match = matchIt.next(); + if (interestingIdExpr.match(match.capturedRef(2)).hasMatch()) { + elements << match.captured(2); + } + } + } + for (const QString& elementId : qAsConst(elements)) { QRectF elementRect = boundsOnElement(elementId); if (elementRect.isValid()) { interestingElements.insert(elementId, elementRect);