From d45fcac787196bcbbe366c997801d5bcebf1a475 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 2 Feb 2017 09:35:43 +0100 Subject: Introduce logging category "qt.svg" It is then possible to suppress warnings by setting for example QT_LOGGING_RULES to qt.svg.warning=false. This will suppress the warnings floods which are currently produced by faulty theme svg icons on KDE 5 systems. Task-number: QTBUG-52079 Change-Id: I50e3c2e3eab610e182293c8938c6188694eabfb7 Reviewed-by: David Faure --- src/svg/qsvghandler.cpp | 33 ++++++++++++++++++--------------- src/svg/qsvghandler_p.h | 3 +++ src/svg/qsvgtinydocument.cpp | 14 +++++++------- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/svg/qsvghandler.cpp b/src/svg/qsvghandler.cpp index 3b1cbb8..0b0750b 100644 --- a/src/svg/qsvghandler.cpp +++ b/src/svg/qsvghandler.cpp @@ -65,6 +65,8 @@ QT_BEGIN_NAMESPACE +Q_LOGGING_CATEGORY(lcSvgHandler, "qt.svg") + static const char *qt_inherit_text = "inherit"; #define QT_INHERIT QLatin1String(qt_inherit_text) @@ -2692,11 +2694,11 @@ static QSvgNode *createImageNode(QSvgNode *parent, filename = filename.trimmed(); if (filename.isEmpty()) { - qWarning() << "QSvgHandler: Image filename is empty"; + qCWarning(lcSvgHandler) << "QSvgHandler: Image filename is empty"; return 0; } if (nwidth <= 0 || nheight <= 0) { - qWarning() << "QSvgHandler: Width or height for" << filename << "image was not greater than 0"; + qCWarning(lcSvgHandler) << "QSvgHandler: Width or height for" << filename << "image was not greater than 0"; return 0; } @@ -2709,7 +2711,7 @@ static QSvgNode *createImageNode(QSvgNode *parent, QByteArray data = QByteArray::fromBase64(dataStr.toLatin1()); image = QImage::fromData(data); } else { - qDebug()<<"QSvgHandler::createImageNode: Unrecognized inline image format!"; + qCDebug(lcSvgHandler) << "QSvgHandler::createImageNode: Unrecognized inline image format!"; } } else image = QImage(filename); @@ -3166,7 +3168,7 @@ static QSvgNode *createSvgNode(QSvgNode *parent, QString baseProfile = attributes.value(QLatin1String("baseProfile")).toString(); #if 0 if (baseProfile.isEmpty() && baseProfile != QLatin1String("tiny")) { - qWarning("Profile is %s while we only support tiny!", + qCWarning(lcSvgHandler, "Profile is %s while we only support tiny!", qPrintable(baseProfile)); } #endif @@ -3332,7 +3334,7 @@ static QSvgNode *createUseNode(QSvgNode *parent, } } - qWarning("link %s hasn't been detected!", qPrintable(linkId)); + qCWarning(lcSvgHandler, "link %s hasn't been detected!", qPrintable(linkId)); return 0; } @@ -3619,8 +3621,9 @@ bool QSvgHandler::startElement(const QString &localName, } else if (xmlSpace == QLatin1String("default")) { m_whitespaceMode.push(QSvgText::Default); } else { - qWarning() << QString::fromLatin1("\"%1\" is an invalid value for attribute xml:space. " - "Valid values are \"preserve\" and \"default\".").arg(xmlSpace.toString()); + qCWarning(lcSvgHandler).noquote() + << QString::fromLatin1("\"%1\" is an invalid value for attribute xml:space. " + "Valid values are \"preserve\" and \"default\".").arg(xmlSpace.toString()); m_whitespaceMode.push(QSvgText::Default); } @@ -3676,13 +3679,13 @@ bool QSvgHandler::startElement(const QString &localName, if (node->type() == QSvgNode::TSPAN) { static_cast(m_nodes.top())->addTspan(static_cast(node)); } else { - qWarning("\'text\' or \'textArea\' element contains invalid element type."); + qCWarning(lcSvgHandler, "\'text\' or \'textArea\' element contains invalid element type."); delete node; node = 0; } break; default: - qWarning("Could not add child element to parent element because the types are incorrect."); + qCWarning(lcSvgHandler, "Could not add child element to parent element because the types are incorrect."); delete node; node = 0; break; @@ -3704,7 +3707,7 @@ bool QSvgHandler::startElement(const QString &localName, } else if (ParseMethod method = findUtilFactory(localName)) { Q_ASSERT(!m_nodes.isEmpty()); if (!method(m_nodes.top(), attributes, this)) { - qWarning("Problem parsing %s", qPrintable(localName)); + qCWarning(lcSvgHandler, "Problem parsing %s", qPrintable(localName)); } } else if (StyleFactoryMethod method = findStyleFactoryMethod(localName)) { QSvgStyleProperty *prop = method(m_nodes.top(), attributes, this); @@ -3712,16 +3715,16 @@ bool QSvgHandler::startElement(const QString &localName, m_style = prop; m_nodes.top()->appendStyleProperty(prop, someId(attributes)); } else { - qWarning("Could not parse node: %s", qPrintable(localName)); + qCWarning(lcSvgHandler, "Could not parse node: %s", qPrintable(localName)); } } else if (StyleParseMethod method = findStyleUtilFactoryMethod(localName)) { if (m_style) { if (!method(m_style, attributes, this)) { - qWarning("Problem parsing %s", qPrintable(localName)); + qCWarning(lcSvgHandler, "Problem parsing %s", qPrintable(localName)); } } } else { - //qWarning()<<"Skipping unknown element!"<setFillStyle(style); } else { - qWarning("Could not resolve property : %s", qPrintable(id)); + qCWarning(lcSvgHandler, "Could not resolve property : %s", qPrintable(id)); fill->setBrush(Qt::NoBrush); } } @@ -3792,7 +3795,7 @@ void QSvgHandler::resolveGradients(QSvgNode *node) if (style) { stroke->setStyle(style); } else { - qWarning("Could not resolve property : %s", qPrintable(id)); + qCWarning(lcSvgHandler, "Could not resolve property : %s", qPrintable(id)); stroke->setStroke(Qt::NoBrush); } } diff --git a/src/svg/qsvghandler_p.h b/src/svg/qsvghandler_p.h index 32dd059..2c06cb4 100644 --- a/src/svg/qsvghandler_p.h +++ b/src/svg/qsvghandler_p.h @@ -54,6 +54,7 @@ #include "QtCore/qxmlstream.h" #include "QtCore/qhash.h" #include "QtCore/qstack.h" +#include #include "qsvgstyle_p.h" #include "private/qcssparser_p.h" #include "qsvggraphics_p.h" @@ -186,6 +187,8 @@ private: const bool m_ownsReader; }; +Q_DECLARE_LOGGING_CATEGORY(lcSvgHandler) + QT_END_NAMESPACE #endif // QSVGHANDLER_P_H diff --git a/src/svg/qsvgtinydocument.cpp b/src/svg/qsvgtinydocument.cpp index 7bb1f75..15351bd 100644 --- a/src/svg/qsvgtinydocument.cpp +++ b/src/svg/qsvgtinydocument.cpp @@ -104,7 +104,7 @@ QByteArray qt_inflateGZipDataFrom(QIODevice *device) // Adding 16 to the window size gives us gzip decoding if (inflateInit2(&zlibStream, MAX_WBITS + 16) != Z_OK) { - qWarning("Cannot initialize zlib, because: %s", + qCWarning(lcSvgHandler, "Cannot initialize zlib, because: %s", (zlibStream.msg != NULL ? zlibStream.msg : "Unknown error")); return QByteArray(); } @@ -137,7 +137,7 @@ QByteArray qt_inflateGZipDataFrom(QIODevice *device) case Z_STREAM_ERROR: case Z_MEM_ERROR: { inflateEnd(&zlibStream); - qWarning("Error while inflating gzip file: %s", + qCWarning(lcSvgHandler, "Error while inflating gzip file: %s", (zlibStream.msg != NULL ? zlibStream.msg : "Unknown error")); destination.chop(zlibStream.avail_out); return destination; @@ -167,8 +167,8 @@ QSvgTinyDocument * QSvgTinyDocument::load(const QString &fileName) { QFile file(fileName); if (!file.open(QFile::ReadOnly)) { - qWarning("Cannot open file '%s', because: %s", - qPrintable(fileName), qPrintable(file.errorString())); + qCWarning(lcSvgHandler, "Cannot open file '%s', because: %s", + qPrintable(fileName), qPrintable(file.errorString())); return 0; } @@ -185,7 +185,7 @@ QSvgTinyDocument * QSvgTinyDocument::load(const QString &fileName) doc = handler.document(); doc->m_animationDuration = handler.animationDuration(); } else { - qWarning("Cannot read file '%s', because: %s (line %d)", + qCWarning(lcSvgHandler, "Cannot read file '%s', because: %s (line %d)", qPrintable(fileName), qPrintable(handler.errorString()), handler.lineNumber()); } return doc; @@ -261,7 +261,7 @@ void QSvgTinyDocument::draw(QPainter *p, const QString &id, QSvgNode *node = scopeNode(id); if (!node) { - qDebug("Couldn't find node %s. Skipping rendering.", qPrintable(id)); + qCDebug(lcSvgHandler, "Couldn't find node %s. Skipping rendering.", qPrintable(id)); return; } if (m_time.isNull()) { @@ -443,7 +443,7 @@ QMatrix QSvgTinyDocument::matrixForElement(const QString &id) const QSvgNode *node = scopeNode(id); if (!node) { - qDebug("Couldn't find node %s. Skipping rendering.", qPrintable(id)); + qCDebug(lcSvgHandler, "Couldn't find node %s. Skipping rendering.", qPrintable(id)); return QMatrix(); } -- cgit v1.2.1