From 093ab48adf43cf80fa2756f3a5ac8b475d2a0347 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Tue, 29 Apr 2025 20:53:23 +0200 Subject: [PATCH] Widgets/Stylesheets: Remove double negations for stylehseet feature Replace ifndef QT_NO_STYLE_STYLESHEET antipattern by if QT_CONFIG(style_stylesheet). Task-number: QTBUG-136341 Change-Id: I8f5d5ff0b7b5cce010df167977214bc92a9443b7 Reviewed-by: Axel Spoerl (cherry picked from commit a1612886bade6192fecad33d0dacb1d24792e315) Reviewed-by: Qt Cherry-pick Bot --- src/widgets/kernel/qapplication.cpp | 14 +++++++------- src/widgets/kernel/qtooltip.cpp | 10 +++++----- src/widgets/kernel/qwidget.cpp | 22 +++++++++++----------- src/widgets/widgets/qlabel.cpp | 2 +- src/widgets/widgets/qlineedit.cpp | 2 +- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index d4ae436ae4d..56059369ca7 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -318,7 +318,7 @@ QWidget *QApplication::topLevelAt(const QPoint &pos) void qt_init_tooltip_palette(); QStyle *QApplicationPrivate::app_style = nullptr; // default application style -#ifndef QT_NO_STYLE_STYLESHEET +#if QT_CONFIG(style_stylesheet) QString QApplicationPrivate::styleSheet; // default application stylesheet #endif QPointer QApplicationPrivate::leaveAfterRelease = nullptr; @@ -387,7 +387,7 @@ void QApplicationPrivate::process_cmdline() ++arg; if (strcmp(arg, "-qdevel") == 0 || strcmp(arg, "-qdebug") == 0) { // obsolete argument -#ifndef QT_NO_STYLE_STYLESHEET +#if QT_CONFIG(style_stylesheet) } else if (strcmp(arg, "-stylesheet") == 0 && i < argc -1) { styleSheet = "file:///"_L1; styleSheet.append(QString::fromLocal8Bit(argv[++i])); @@ -872,7 +872,7 @@ bool QApplication::autoSipEnabled() const return QApplicationPrivate::autoSipEnabled; } -#ifndef QT_NO_STYLE_STYLESHEET +#if QT_CONFIG(style_stylesheet) QString QApplication::styleSheet() const { @@ -932,7 +932,7 @@ QStyle *QApplication::style() QGuiApplicationPrivate::updatePalette(); -#ifndef QT_NO_STYLE_STYLESHEET +#if QT_CONFIG(style_stylesheet) if (!QApplicationPrivate::styleSheet.isEmpty()) { qApp->setStyleSheet(QApplicationPrivate::styleSheet); } else @@ -990,7 +990,7 @@ void QApplication::setStyle(QStyle *style) QStyle *old = QApplicationPrivate::app_style; // save -#ifndef QT_NO_STYLE_STYLESHEET +#if QT_CONFIG(style_stylesheet) if (!QApplicationPrivate::styleSheet.isEmpty() && !qt_styleSheet(style)) { // we have a stylesheet already and a new style is being set QStyleSheetStyle *newStyleSheetStyle = new QStyleSheetStyle(style); @@ -1023,7 +1023,7 @@ void QApplication::setStyle(QStyle *style) if (w->windowType() != Qt::Desktop && w->testAttribute(Qt::WA_WState_Polished)) { if (w->style() == QApplicationPrivate::app_style) QApplicationPrivate::app_style->polish(w); // repolish -#ifndef QT_NO_STYLE_STYLESHEET +#if QT_CONFIG(style_stylesheet) else w->setStyleSheet(w->styleSheet()); // touch #endif @@ -1040,7 +1040,7 @@ void QApplication::setStyle(QStyle *style) } } -#ifndef QT_NO_STYLE_STYLESHEET +#if QT_CONFIG(style_stylesheet) if (QStyleSheetStyle *oldStyleSheetStyle = qt_styleSheet(old)) { oldStyleSheetStyle->deref(); } else diff --git a/src/widgets/kernel/qtooltip.cpp b/src/widgets/kernel/qtooltip.cpp index eeb89adf8f3..12ba8ae545b 100644 --- a/src/widgets/kernel/qtooltip.cpp +++ b/src/widgets/kernel/qtooltip.cpp @@ -122,7 +122,7 @@ protected: void mouseMoveEvent(QMouseEvent *e) override; void resizeEvent(QResizeEvent *e) override; -#ifndef QT_NO_STYLE_STYLESHEET +#if QT_CONFIG(style_stylesheet) public slots: /** \internal Cleanup the _q_stylesheet_parent property. @@ -145,7 +145,7 @@ QTipLabel *QTipLabel::instance = nullptr; QTipLabel::QTipLabel(const QString &text, const QPoint &pos, QWidget *w, int msecDisplayTime) : QLabel(w, Qt::ToolTip | Qt::BypassGraphicsProxyWidget) -#ifndef QT_NO_STYLE_STYLESHEET +#if QT_CONFIG(style_stylesheet) , styleSheetParent(nullptr) #endif , widget(nullptr) @@ -180,7 +180,7 @@ void QTipLabel::restartExpireTimer(int msecDisplayTime) void QTipLabel::reuseTip(const QString &text, int msecDisplayTime, const QPoint &pos) { -#ifndef QT_NO_STYLE_STYLESHEET +#if QT_CONFIG(style_stylesheet) if (styleSheetParent){ disconnect(styleSheetParent, &QWidget::destroyed, this, &QTipLabel::styleSheetParentDestroyed); @@ -348,7 +348,7 @@ QScreen *QTipLabel::getTipScreen(const QPoint &pos, QWidget *w) void QTipLabel::placeTip(const QPoint &pos, QWidget *w) { -#ifndef QT_NO_STYLE_STYLESHEET +#if QT_CONFIG(style_stylesheet) if (testAttribute(Qt::WA_StyleSheet) || (w && qt_styleSheet(w->style()))) { //the stylesheet need to know the real parent QTipLabel::instance->setProperty("_q_stylesheet_parent", QVariant::fromValue(w)); @@ -367,7 +367,7 @@ void QTipLabel::placeTip(const QPoint &pos, QWidget *w) // correct content margin. QTipLabel::instance->updateSize(pos); } -#endif //QT_NO_STYLE_STYLESHEET +#endif //QT_CONFIG(style_stylesheet) QPoint p = pos; const QScreen *screen = getTipScreen(pos, w); diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index f2c2bcf7218..a604cb1e439 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -1694,7 +1694,7 @@ void QWidgetPrivate::deleteExtra() { if (extra) { // if exists deleteSysExtra(); -#ifndef QT_NO_STYLE_STYLESHEET +#if QT_CONFIG(style_stylesheet) // dereference the stylesheet style if (QStyleSheetStyle *proxy = qt_styleSheet(extra->style)) proxy->deref(); @@ -2554,7 +2554,7 @@ void QWidget::setScreen(QScreen *screen) d->setScreen(screen); } -#ifndef QT_NO_STYLE_STYLESHEET +#if QT_CONFIG(style_stylesheet) /*! \property QWidget::styleSheet @@ -2659,7 +2659,7 @@ void QWidget::setStyle(QStyle *style) Q_D(QWidget); setAttribute(Qt::WA_SetStyle, style != nullptr); d->createExtra(); -#ifndef QT_NO_STYLE_STYLESHEET +#if QT_CONFIG(style_stylesheet) if (QStyleSheetStyle *styleSheetStyle = qt_styleSheet(style)) { //if for some reason someone try to set a QStyleSheetStyle, ref it //(this may happen for example in QButtonDialogBox which propagates its style) @@ -2680,7 +2680,7 @@ void QWidgetPrivate::setStyle_helper(QStyle *newStyle, bool propagate) createExtra(); -#ifndef QT_NO_STYLE_STYLESHEET +#if QT_CONFIG(style_stylesheet) QPointer origStyle = extra->style; #endif extra->style = newStyle; @@ -2701,7 +2701,7 @@ void QWidgetPrivate::setStyle_helper(QStyle *newStyle, bool propagate) } } -#ifndef QT_NO_STYLE_STYLESHEET +#if QT_CONFIG(style_stylesheet) if (!qt_styleSheet(newStyle)) { if (const QStyleSheetStyle* cssStyle = qt_styleSheet(origStyle)) { cssStyle->clearWidgetFont(q); @@ -2712,7 +2712,7 @@ void QWidgetPrivate::setStyle_helper(QStyle *newStyle, bool propagate) QEvent e(QEvent::StyleChange); QCoreApplication::sendEvent(q, &e); -#ifndef QT_NO_STYLE_STYLESHEET +#if QT_CONFIG(style_stylesheet) // dereference the old stylesheet style if (QStyleSheetStyle *proxy = qt_styleSheet(origStyle)) proxy->deref(); @@ -2722,7 +2722,7 @@ void QWidgetPrivate::setStyle_helper(QStyle *newStyle, bool propagate) // Inherits style from the current parent and propagates it as necessary void QWidgetPrivate::inheritStyle() { -#ifndef QT_NO_STYLE_STYLESHEET +#if QT_CONFIG(style_stylesheet) Q_Q(QWidget); QStyle *extraStyle = extra ? (QStyle*)extra->style : nullptr; @@ -4700,7 +4700,7 @@ void QWidget::setFont(const QFont &font) { Q_D(QWidget); -#ifndef QT_NO_STYLE_STYLESHEET +#if QT_CONFIG(style_stylesheet) const QStyleSheetStyle* style; if (d->extra && (style = qt_styleSheet(d->extra->style))) style->saveWidgetFont(this, font); @@ -4809,7 +4809,7 @@ void QWidgetPrivate::resolveFont() void QWidgetPrivate::updateFont(const QFont &font) { Q_Q(QWidget); -#ifndef QT_NO_STYLE_STYLESHEET +#if QT_CONFIG(style_stylesheet) const QStyleSheetStyle* cssStyle; cssStyle = extra ? qt_styleSheet(extra->style) : nullptr; const bool useStyleSheetPropagationInWidgetStyles = @@ -4839,7 +4839,7 @@ void QWidgetPrivate::updateFont(const QFont &font) QWidget *w = qobject_cast(children.at(i)); if (w) { if (0) { -#ifndef QT_NO_STYLE_STYLESHEET +#if QT_CONFIG(style_stylesheet) } else if (!useStyleSheetPropagationInWidgetStyles && w->testAttribute(Qt::WA_StyleSheet)) { // Style sheets follow a different font propagation scheme. if (cssStyle) @@ -4854,7 +4854,7 @@ void QWidgetPrivate::updateFont(const QFont &font) } } -#ifndef QT_NO_STYLE_STYLESHEET +#if QT_CONFIG(style_stylesheet) if (!useStyleSheetPropagationInWidgetStyles && cssStyle) { cssStyle->updateStyleSheetFont(q); } diff --git a/src/widgets/widgets/qlabel.cpp b/src/widgets/widgets/qlabel.cpp index bab24211e87..a71faa77782 100644 --- a/src/widgets/widgets/qlabel.cpp +++ b/src/widgets/widgets/qlabel.cpp @@ -985,7 +985,7 @@ void QLabel::paintEvent(QPaintEvent *) QRectF lr = d->layoutRect().toAlignedRect(); QStyleOption opt; opt.initFrom(this); -#ifndef QT_NO_STYLE_STYLESHEET +#if QT_CONFIG(style_stylesheet) if (QStyleSheetStyle* cssStyle = qt_styleSheet(style)) cssStyle->styleSheetPalette(this, &opt, &opt.palette); #endif diff --git a/src/widgets/widgets/qlineedit.cpp b/src/widgets/widgets/qlineedit.cpp index 00cbbb9d187..2f68ad5d4d5 100644 --- a/src/widgets/widgets/qlineedit.cpp +++ b/src/widgets/widgets/qlineedit.cpp @@ -2071,7 +2071,7 @@ void QLineEdit::paintEvent(QPaintEvent *) QPoint topLeft = lineRect.topLeft() - QPoint(d->hscroll, d->control->ascent() - fm.ascent()); // draw text, selections and cursors -#ifndef QT_NO_STYLE_STYLESHEET +#if QT_CONFIG(style_stylesheet) if (QStyleSheetStyle* cssStyle = qt_styleSheet(style())) { cssStyle->styleSheetPalette(this, &panel, &pal); }