diff options
author | Mitch Curtis <[email protected]> | 2022-12-19 11:41:00 +0800 |
---|---|---|
committer | Mitch Curtis <[email protected]> | 2022-12-22 10:57:04 +0800 |
commit | 0cd146b4b015d2ba79f258b27f3109b3e21e855a (patch) | |
tree | eaabb58702a9dccc339760a33c01918e2df8ebe9 | |
parent | ae6546c240bd3beb9295b512996a115bcebb831a (diff) |
Fix warnings with native styles
Amends e592a2ad31695695f0dd2069b17c6ab90ed1a739 to cover some cases
that were missed. They were missed because I incorrectly assumed that
the various test functions that I added in
0765c176e7b7ee73b1ac6d6efdabc93e4dec978f would catch warnings,
forgetting that the fact that we set
QT_QUICK_CONTROLS_IGNORE_CUSTOMIZATION_WARNINGS to 1 in tst_macos and
tst_windows meant that we'd never get the warnings.
Fixes: QTBUG-109438
Pick-to: 6.5
Change-Id: I527785a3adf3afb2a7ee4943300e87909f21562e
Reviewed-by: Qt CI Bot <[email protected]>
Reviewed-by: Richard Moe Gustavsen <[email protected]>
-rw-r--r-- | src/quickcontrols/macos/ComboBox.qml | 1 | ||||
-rw-r--r-- | src/quickcontrols/macos/Dialog.qml | 7 | ||||
-rw-r--r-- | src/quickcontrols/macos/DialogButtonBox.qml | 4 | ||||
-rw-r--r-- | src/quickcontrols/macos/GroupBox.qml | 2 | ||||
-rw-r--r-- | src/quickcontrols/macos/Slider.qml | 4 | ||||
-rw-r--r-- | src/quickcontrols/macos/SpinBox.qml | 6 | ||||
-rw-r--r-- | src/quicknativestyle/controls/DefaultButton.qml | 4 | ||||
-rw-r--r-- | src/quicknativestyle/controls/DefaultCheckBox.qml | 4 | ||||
-rw-r--r-- | src/quicknativestyle/controls/DefaultComboBox.qml | 4 | ||||
-rw-r--r-- | src/quicknativestyle/controls/DefaultDial.qml | 2 | ||||
-rw-r--r-- | src/quicktemplates/qquickpopup.cpp | 5 | ||||
-rw-r--r-- | tests/auto/quickcontrols/controls/windows/tst_windows.cpp | 7 | ||||
-rw-r--r-- | tests/auto/quickcontrols/customization/tst_customization.cpp | 36 |
13 files changed, 83 insertions, 3 deletions
diff --git a/src/quickcontrols/macos/ComboBox.qml b/src/quickcontrols/macos/ComboBox.qml index 4ea2012382..e530803f8c 100644 --- a/src/quickcontrols/macos/ComboBox.qml +++ b/src/quickcontrols/macos/ComboBox.qml @@ -28,5 +28,6 @@ NativeStyle.DefaultComboBox { verticalAlignment: Text.AlignVCenter readonly property Item __focusFrameControl: control + readonly property bool __ignoreNotCustomizable: true } } diff --git a/src/quickcontrols/macos/Dialog.qml b/src/quickcontrols/macos/Dialog.qml index 175beb6f6a..effb438733 100644 --- a/src/quickcontrols/macos/Dialog.qml +++ b/src/quickcontrols/macos/Dialog.qml @@ -30,6 +30,8 @@ T.Dialog { border.color: control.palette.mid radius: 2 + readonly property bool __ignoreNotCustomizable: true + Rectangle { x: 1 y: 1 @@ -48,6 +50,9 @@ T.Dialog { elide: Label.ElideRight font.bold: true padding: 6 + + readonly property bool __ignoreNotCustomizable: true + background: Rectangle { x: 1 y: 1 @@ -60,6 +65,8 @@ T.Dialog { footer: DialogButtonBox { visible: count > 0 + + readonly property bool __ignoreNotCustomizable: true } T.Overlay.modal: Rectangle { diff --git a/src/quickcontrols/macos/DialogButtonBox.qml b/src/quickcontrols/macos/DialogButtonBox.qml index 0d583e7170..6f844dba2f 100644 --- a/src/quickcontrols/macos/DialogButtonBox.qml +++ b/src/quickcontrols/macos/DialogButtonBox.qml @@ -28,6 +28,8 @@ T.DialogButtonBox { orientation: ListView.Horizontal boundsBehavior: Flickable.StopAtBounds snapMode: ListView.SnapToItem + + readonly property bool __ignoreNotCustomizable: true } background: Rectangle { @@ -38,5 +40,7 @@ T.DialogButtonBox { height: parent.height - 2 color: control.palette.window radius: 2 + + readonly property bool __ignoreNotCustomizable: true } } diff --git a/src/quickcontrols/macos/GroupBox.qml b/src/quickcontrols/macos/GroupBox.qml index 38c82891a1..c44063d1fb 100644 --- a/src/quickcontrols/macos/GroupBox.qml +++ b/src/quickcontrols/macos/GroupBox.qml @@ -11,6 +11,8 @@ NativeStyle.DefaultGroupBox { readonly property point labelPos : control.__nativeBackground ? background.labelPos : Qt.point(0,0) + readonly property bool __ignoreNotCustomizable: true + x: labelPos.x + background.x y: labelPos.y + background.y - (control.__nativeBackground ? background.groupBoxPadding.top : 0) width: children[0].implicitWidth diff --git a/src/quickcontrols/macos/Slider.qml b/src/quickcontrols/macos/Slider.qml index 33db57b16c..53472556ff 100644 --- a/src/quickcontrols/macos/Slider.qml +++ b/src/quickcontrols/macos/Slider.qml @@ -19,6 +19,8 @@ NativeStyle.DefaultSlider { // also use a different background color before, and // after, the handle. useNinePatchImage: false + + readonly property bool __ignoreNotCustomizable: true } handle: NativeStyle.Slider { @@ -32,5 +34,7 @@ NativeStyle.DefaultSlider { x: control.leftPadding + (control.horizontal ? control.visualPosition * (control.availableWidth - width) : (control.availableWidth - width) / 2) y: control.topPadding + (control.horizontal ? (control.availableHeight - height) / 2 : control.visualPosition * (control.availableHeight - height)) useNinePatchImage: false + + readonly property bool __ignoreNotCustomizable: true } } diff --git a/src/quickcontrols/macos/SpinBox.qml b/src/quickcontrols/macos/SpinBox.qml index dcc52f0ab2..f12fc6d2fe 100644 --- a/src/quickcontrols/macos/SpinBox.qml +++ b/src/quickcontrols/macos/SpinBox.qml @@ -44,6 +44,8 @@ T.SpinBox { readOnly: !control.editable validator: control.validator inputMethodHints: control.inputMethodHints + + readonly property bool __ignoreNotCustomizable: true } NativeStyle.SpinBox { @@ -60,6 +62,8 @@ T.SpinBox { y: (parent.height / 2) - height implicitWidth: upAndDown.width implicitHeight: upAndDown.height / 2 + + readonly property bool __ignoreNotCustomizable: true } down.indicator: Item { @@ -67,5 +71,7 @@ T.SpinBox { y: up.indicator.y + upAndDown.height / 2 implicitWidth: upAndDown.width implicitHeight: upAndDown.height / 2 + + readonly property bool __ignoreNotCustomizable: true } } diff --git a/src/quicknativestyle/controls/DefaultButton.qml b/src/quicknativestyle/controls/DefaultButton.qml index c47c6fc0de..ee20acce00 100644 --- a/src/quicknativestyle/controls/DefaultButton.qml +++ b/src/quicknativestyle/controls/DefaultButton.qml @@ -27,6 +27,8 @@ T.Button { control: control contentWidth: contentItem.implicitWidth contentHeight: contentItem.implicitHeight + + readonly property bool __ignoreNotCustomizable: true } icon.width: 24 @@ -42,5 +44,7 @@ T.Button { text: control.text font: control.font color: control.palette.buttonText + + readonly property bool __ignoreNotCustomizable: true } } diff --git a/src/quicknativestyle/controls/DefaultCheckBox.qml b/src/quicknativestyle/controls/DefaultCheckBox.qml index e54ee2b24f..3a86ab4368 100644 --- a/src/quicknativestyle/controls/DefaultCheckBox.qml +++ b/src/quicknativestyle/controls/DefaultCheckBox.qml @@ -28,6 +28,8 @@ T.CheckBox { contentWidth: contentItem.implicitWidth contentHeight: contentItem.implicitHeight useNinePatchImage: false + + readonly property bool __ignoreNotCustomizable: true } contentItem: CheckLabel { @@ -55,5 +57,7 @@ T.CheckBox { else indicator && mirrored ? indicator.width + spacing : 0 } + + readonly property bool __ignoreNotCustomizable: true } } diff --git a/src/quicknativestyle/controls/DefaultComboBox.qml b/src/quicknativestyle/controls/DefaultComboBox.qml index 2663bbc807..a9a820a2d1 100644 --- a/src/quicknativestyle/controls/DefaultComboBox.qml +++ b/src/quicknativestyle/controls/DefaultComboBox.qml @@ -43,12 +43,16 @@ T.ComboBox { selectionColor: control.palette.highlight selectedTextColor: control.palette.highlightedText verticalAlignment: Text.AlignVCenter + + readonly property bool __ignoreNotCustomizable: true } background: NativeStyle.ComboBox { control: control contentWidth: contentItem.implicitWidth contentHeight: contentItem.implicitHeight + + readonly property bool __ignoreNotCustomizable: true } delegate: ItemDelegate { diff --git a/src/quicknativestyle/controls/DefaultDial.qml b/src/quicknativestyle/controls/DefaultDial.qml index 0729ede25f..205be44f12 100644 --- a/src/quicknativestyle/controls/DefaultDial.qml +++ b/src/quicknativestyle/controls/DefaultDial.qml @@ -22,5 +22,7 @@ T.Dial { background: NativeStyle.Dial { control: control useNinePatchImage: false + + readonly property bool __ignoreNotCustomizable: true } } diff --git a/src/quicktemplates/qquickpopup.cpp b/src/quicktemplates/qquickpopup.cpp index d05cb75935..da2f44f85f 100644 --- a/src/quicktemplates/qquickpopup.cpp +++ b/src/quicktemplates/qquickpopup.cpp @@ -1714,6 +1714,9 @@ QQuickItem *QQuickPopup::background() const void QQuickPopup::setBackground(QQuickItem *background) { Q_D(QQuickPopup); + // The __notCustomizable property won't be on "this" when the popup item's setBackground function + // is called, so it won't warn. That's why we do a check here. + QQuickControlPrivate::warnIfCustomizationNotSupported(this, background, QStringLiteral("background")); d->popupItem->setBackground(background); } @@ -1746,6 +1749,8 @@ QQuickItem *QQuickPopup::contentItem() const void QQuickPopup::setContentItem(QQuickItem *item) { Q_D(QQuickPopup); + // See comment in setBackground for why we do this. + QQuickControlPrivate::warnIfCustomizationNotSupported(this, item, QStringLiteral("background")); d->popupItem->setContentItem(item); } diff --git a/tests/auto/quickcontrols/controls/windows/tst_windows.cpp b/tests/auto/quickcontrols/controls/windows/tst_windows.cpp index 57800b70ba..560cec4383 100644 --- a/tests/auto/quickcontrols/controls/windows/tst_windows.cpp +++ b/tests/auto/quickcontrols/controls/windows/tst_windows.cpp @@ -11,8 +11,11 @@ int main(int argc, char *argv[]) // We have tst_customization::override and its controlNotCustomizable check // to ensure that customizing native styles results in warnings, // rather than having to ignore specific warnings for each control we customize in tests. - // We also have the various test_default/test_empty test functions to check - // that a "default-constructed" control doesn't result in any warnings. + // We do have the various test_default/test_empty test functions to check + // that a "default-constructed" control doesn't result in any warnings, but because + // we set this, those won't be useful for ensuring that customization warnings aren't + // issued when default-constructing controls. For that we have + // tst_customization::noCustomizationWarningsForDefaultControls. qputenv("QT_QUICK_CONTROLS_IGNORE_CUSTOMIZATION_WARNINGS", "1"); QQuickStyle::setStyle("Windows"); return quick_test_main(argc, argv, "tst_controls::Windows", TST_CONTROLS_DATA); diff --git a/tests/auto/quickcontrols/customization/tst_customization.cpp b/tests/auto/quickcontrols/customization/tst_customization.cpp index ad82ed4c20..8e5ac2a95a 100644 --- a/tests/auto/quickcontrols/customization/tst_customization.cpp +++ b/tests/auto/quickcontrols/customization/tst_customization.cpp @@ -76,6 +76,8 @@ static const ControlInfo ControlInfos[] = { { "Tumbler", QStringList() << "background" << "contentItem" } }; +static const QString nonCustomizableWarning = ".*The current style does not support customization of this control.*"; + class tst_customization : public QQmlDataTest { Q_OBJECT @@ -98,6 +100,11 @@ private slots: void comboPopup(); +#if defined(Q_OS_MACOS) || defined(Q_OS_WINDOWS) + void noCustomizationWarningsForDefaultControls_data(); + void noCustomizationWarningsForDefaultControls(); +#endif + private: void reset(); void addHooks(); @@ -403,7 +410,6 @@ void tst_customization::override() } for (int i = 0; i < delegates.size(); ++i) { - static const QString nonCustomizableWarning = ".*The current style does not support customization of this control.*"; if (controlNotCustomizable) { // If the control can't be customized, ensure that we inform the user of that by checking that a warning is issued. QTest::ignoreMessage(QtWarningMsg, QRegularExpression(nonCustomizableWarning)); @@ -551,6 +557,34 @@ void tst_customization::comboPopup() } } +#if defined(Q_OS_MACOS) || defined(Q_OS_WINDOWS) +void tst_customization::noCustomizationWarningsForDefaultControls_data() +{ + QTest::addColumn<QString>("style"); + +#ifdef Q_OS_MACOS + QTest::addRow("macOS") << "macOS"; +#elif defined(Q_OS_WINDOWS) + QTest::addRow("Windows") << "Windows"; +#endif +} + +void tst_customization::noCustomizationWarningsForDefaultControls() +{ + QFETCH(QString, style); + + QQuickStyle::setStyle(style); + + QTest::failOnWarning(QRegularExpression(nonCustomizableWarning)); + + for (const ControlInfo &controlInfo : ControlInfos) { + QString errorMessage; + QScopedPointer<QObject> control(createControl(controlInfo.type, {}, &errorMessage)); + QVERIFY2(control, qPrintable(errorMessage)); + } +} +#endif + QTEST_MAIN(tst_customization) #include "tst_customization.moc" |