diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2020-09-30 15:22:06 +0200 |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2020-09-30 16:05:42 +0200 |
commit | e5a3438ff3a3891449f9c6fbfa449c785d6a6901 (patch) | |
tree | 38b8f87a7b3dc20c4597ce04d25687f0bdeebd01 | |
parent | 97197f94b4098783e7dc444b0cc4028ab1b25a4f (diff) |
Native style: improve debug output
Improve the debug implementation so that you don't need
to modify the application to get debug output. You
can now instead just do e.g:
QQC2_NATIVESTYLE_DEBUG="myButton output contentRect"
QQC2_NATIVESTYLE_DEBUG="combobox ninepatchmargins"
QQC2_NATIVESTYLE_DEBUG="all layoutrect"
Change-Id: I58cbcfb241bc0be20cae73735bc277d0662a476a
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
-rw-r--r-- | src/imports/nativestyle/items/qquickstyleitem.cpp | 86 | ||||
-rw-r--r-- | src/imports/nativestyle/items/qquickstyleitem.h | 4 |
2 files changed, 55 insertions, 35 deletions
diff --git a/src/imports/nativestyle/items/qquickstyleitem.cpp b/src/imports/nativestyle/items/qquickstyleitem.cpp index c45f0c91..4c84bf9a 100644 --- a/src/imports/nativestyle/items/qquickstyleitem.cpp +++ b/src/imports/nativestyle/items/qquickstyleitem.cpp @@ -328,48 +328,64 @@ void QQuickStyleItem::updatePolish() paintControlToImage(); } -void QQuickStyleItem::componentComplete() +#ifdef QT_DEBUG +void QQuickStyleItem::addDebugInfo() { - Q_ASSERT_X(m_control, Q_FUNC_INFO, "You need to assign a value to property 'control'"); + // Example debug strings: + // "QQC2_NATIVESTYLE_DEBUG="myButton output contentRect" + // "QQC2_NATIVESTYLE_DEBUG="ComboBox ninepatchmargins" + // "QQC2_NATIVESTYLE_DEBUG="All layoutrect" + + static const auto debugString = qEnvironmentVariable("QQC2_NATIVESTYLE_DEBUG"); + static const auto matchAll = debugString.startsWith(QLatin1String("All ")); + static const auto prefix = QStringLiteral("QQuickStyleItem"); + if (debugString.isEmpty()) + return; -#ifdef QT_DEBUG - if (!qEnvironmentVariable("QQC2_NATIVESTYLE_DEBUG").isEmpty()) { - // Set objectName to "debug" pluss one or more options separated - // by space to show extra information about this item. + const auto objectName = m_control->objectName(); + const auto typeName = QString::fromUtf8(metaObject()->className()).remove(prefix); + const bool matchName = !objectName.isEmpty() && debugString.startsWith(objectName); + const bool matchType = debugString.startsWith(typeName); -#define QQC2_DEBUG_FLAG(FLAG) \ - if (name.contains(QString(QLatin1String(#FLAG)).toLower())) m_debugFlags |= FLAG - - const QString name = m_control->objectName().toLower(); - if (name.startsWith(QString(QLatin1String("debug")).toLower())) { - QQC2_DEBUG_FLAG(Output); - QQC2_DEBUG_FLAG(ImageRect); - QQC2_DEBUG_FLAG(ContentRect); - QQC2_DEBUG_FLAG(LayoutRect); - QQC2_DEBUG_FLAG(InputContentSize); - QQC2_DEBUG_FLAG(DontUseNinePatchImage); - QQC2_DEBUG_FLAG(NinePatchMargins); - QQC2_DEBUG_FLAG(Unscaled); - - if (m_debugFlags & (DontUseNinePatchImage - | InputContentSize - | ContentRect - | LayoutRect - | NinePatchMargins)) { - // Some rects will not fit inside the drawn image unless - // we switch off (nine patch) image scaling. - m_debugFlags |= DontUseNinePatchImage; - m_useNinePatchImage = false; - } + if (!(matchAll || matchName || matchType)) + return; - if (m_debugFlags != NoDebug) - qDebug() << "debug options set:" << m_debugFlags; - else - qDebug() << "available debug options:" << DebugFlags(0xFFFF); - } +#define QQC2_DEBUG_FLAG(FLAG) \ + if (debugString.contains(QLatin1String(#FLAG), Qt::CaseInsensitive)) m_debugFlags |= FLAG + + QQC2_DEBUG_FLAG(Output); + QQC2_DEBUG_FLAG(ImageRect); + QQC2_DEBUG_FLAG(ContentRect); + QQC2_DEBUG_FLAG(LayoutRect); + QQC2_DEBUG_FLAG(InputContentSize); + QQC2_DEBUG_FLAG(DontUseNinePatchImage); + QQC2_DEBUG_FLAG(NinePatchMargins); + QQC2_DEBUG_FLAG(Unscaled); + + if (m_debugFlags & (DontUseNinePatchImage + | InputContentSize + | ContentRect + | LayoutRect + | NinePatchMargins)) { + // Some rects will not fit inside the drawn image unless + // we switch off (nine patch) image scaling. + m_debugFlags |= DontUseNinePatchImage; + m_useNinePatchImage = false; } + + if (m_debugFlags != NoDebug) + qDebug() << "debug options set for" << typeName << "(" << objectName << "):" << m_debugFlags; + else + qDebug() << "available debug options:" << DebugFlags(0xFFFF); +} #endif +void QQuickStyleItem::componentComplete() +{ + Q_ASSERT_X(m_control, Q_FUNC_INFO, "You need to assign a value to property 'control'"); +#ifdef QT_DEBUG + addDebugInfo(); +#endif QQuickItem::componentComplete(); connectToControl(); polish(); diff --git a/src/imports/nativestyle/items/qquickstyleitem.h b/src/imports/nativestyle/items/qquickstyleitem.h index ff870684..a92bc516 100644 --- a/src/imports/nativestyle/items/qquickstyleitem.h +++ b/src/imports/nativestyle/items/qquickstyleitem.h @@ -261,6 +261,10 @@ private: inline void updateGeometry(); inline void paintControlToImage(); +#ifdef QT_DEBUG + void addDebugInfo(); +#endif + private: QPointer<QQuickItem> m_control; QImage m_paintedImage; |