diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2020-06-10 21:19:50 +0200 |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2020-06-11 11:53:28 +0000 |
commit | 5c48daa014171e0c40a2511750a9d9a27d057399 (patch) | |
tree | 60a149d216616790fa8d1a2663406e3056ff5f4d | |
parent | 501dfdfe77213a32d29cd14612f30834f83dceed (diff) |
Native style: make the debug flags more type safe
Take the opportunity to clean up the flags a bit, and
improve how we print the options to the console.
Change-Id: Ia6e81453bfd53a5bfe6328b7cb8f6abcbf2dbed1
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r-- | src/imports/nativestyle/items/qquickstyleitem.cpp | 64 | ||||
-rw-r--r-- | src/imports/nativestyle/items/qquickstyleitem.h | 10 |
2 files changed, 30 insertions, 44 deletions
diff --git a/src/imports/nativestyle/items/qquickstyleitem.cpp b/src/imports/nativestyle/items/qquickstyleitem.cpp index c536c3d0..c3aaa9a9 100644 --- a/src/imports/nativestyle/items/qquickstyleitem.cpp +++ b/src/imports/nativestyle/items/qquickstyleitem.cpp @@ -313,48 +313,32 @@ void QQuickStyleItem::componentComplete() #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. Note that - // some of the options cannot be shown unless we switch off using - // nine patch image scaling. - const QString name = m_control->objectName(); - if (name.startsWith(QLatin1String("debug"))) { - if (name.contains(QStringLiteral("output"))) { - m_debugFlags.setFlag(PrintOutput); - qDebug() << "debug: setting PrintOutput"; - } - if (name.contains(QStringLiteral("imagerect"))) { - m_debugFlags.setFlag(ShowImageRect); - qDebug() << "debug: setting ShowImageRect"; - } - if (name.contains(QStringLiteral("contentrect"))) { - m_debugFlags.setFlag(ShowContentRect); - m_useNinePatchImage = false; - qDebug() << "debug: setting ShowContentRect"; - qDebug() << "debug: setting useNinePatchImage to false"; - } - if (name.contains(QStringLiteral("layoutrect"))) { - m_debugFlags.setFlag(ShowLayoutRect); - m_useNinePatchImage = false; - qDebug() << "debug: setting ShowLayoutRect"; - qDebug() << "debug: setting useNinePatchImage to false"; - } - if (name.contains(QStringLiteral("inputcontentsize"))) { - m_debugFlags.setFlag(ShowInputContentSize); - m_useNinePatchImage = false; - qDebug() << "debug: setting ShowInputContentSize"; - qDebug() << "debug: setting useNinePatchImage to false"; - } - if (name.contains(QStringLiteral("dontuseninepatchimage"))) { + // by space to show extra information about this item. + +#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(ShowImageRect); + QQC2_DEBUG_FLAG(ShowContentRect); + QQC2_DEBUG_FLAG(ShowLayoutRect); + QQC2_DEBUG_FLAG(ShowInputContentSize); + QQC2_DEBUG_FLAG(DontUseNinePatchImage); + QQC2_DEBUG_FLAG(ShowUnscaled); + + if (m_debugFlags & (DontUseNinePatchImage | ShowInputContentSize | ShowContentRect | ShowLayoutRect)) { + // Some rects will not fit inside the drawn image unless + // we switch off (nine patch) image scaling. + m_debugFlags |= DontUseNinePatchImage; m_useNinePatchImage = false; - qDebug() << "debug: setting useNinePatchImage to false"; } - if (name.contains(QStringLiteral("unscaled"))) { - m_debugFlags.setFlag(ShowUnscaled); - qDebug() << "debug: setting ShowUnscaled"; - } - if (m_debugFlags == NoDebug) - qDebug() << "debug options: output, imagerect, contentrect" - << "layoutrect, unscaled, inputcontentsize, dontuseninepatchimage"; + + if (m_debugFlags != NoDebug) + qDebug() << "debug options set:" << m_debugFlags; + else + qDebug() << "available debug options:" << DebugFlags(0xFFFF); } } #endif diff --git a/src/imports/nativestyle/items/qquickstyleitem.h b/src/imports/nativestyle/items/qquickstyleitem.h index b7ff5d44..20c6133f 100644 --- a/src/imports/nativestyle/items/qquickstyleitem.h +++ b/src/imports/nativestyle/items/qquickstyleitem.h @@ -56,8 +56,8 @@ #endif #ifdef QT_DEBUG -#define qqc2Debug() if (m_debugFlags.testFlag(PrintOutput)) qDebug() << __FUNCTION__ << ":" -#define qqc2DebugHeading(HEADING) if (m_debugFlags.testFlag(PrintOutput)) qDebug() << "--------" << HEADING << "--------" +#define qqc2Debug() if (m_debugFlags.testFlag(Output)) qDebug() << __FUNCTION__ << ":" +#define qqc2DebugHeading(HEADING) if (m_debugFlags.testFlag(Output)) qDebug() << "--------" << HEADING << "--------" #else #define qqc2Debug() if (false) qDebug() #define qqc2DebugHeading(HEADING) if (false) qDebug() @@ -178,13 +178,15 @@ public: #ifdef QT_DEBUG enum DebugFlag { NoDebug = 0x00, - PrintOutput = 0x01, + Output = 0x01, ShowImageRect = 0x02, ShowContentRect = 0x04, ShowLayoutRect = 0x08, ShowUnscaled = 0x10, - ShowInputContentSize = 0x20 + ShowInputContentSize = 0x20, + DontUseNinePatchImage = 0x40 }; + Q_FLAG(DebugFlag) Q_DECLARE_FLAGS(DebugFlags, DebugFlag) #endif |