From a0d379bc9a76dfcce08c69abb30d1fea821fd7d7 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Tue, 27 Nov 2012 18:31:06 +0100 Subject: Style auto tests: kill QWindowsStyle dependencies Change-Id: I135fe2b0aae81c73c1cca6272f71db07ecb3fa6b Reviewed-by: Lars Knoll --- tests/auto/widgets/styles/qstyle/tst_qstyle.cpp | 40 ++++++++------- .../qstylesheetstyle/tst_qstylesheetstyle.cpp | 57 +++++++++++----------- 2 files changed, 51 insertions(+), 46 deletions(-) diff --git a/tests/auto/widgets/styles/qstyle/tst_qstyle.cpp b/tests/auto/widgets/styles/qstyle/tst_qstyle.cpp index 7cbd30ebb3..d266692096 100644 --- a/tests/auto/widgets/styles/qstyle/tst_qstyle.cpp +++ b/tests/auto/widgets/styles/qstyle/tst_qstyle.cpp @@ -55,7 +55,6 @@ #include #include -#include #include #include #include @@ -212,7 +211,7 @@ void tst_QStyle::testProxyStyle() { QProxyStyle *proxyStyle = new QProxyStyle(); QVERIFY(proxyStyle->baseStyle()); - QStyle *style = new QWindowsStyle; + QStyle *style = QStyleFactory::create("Windows"); QVERIFY(style->proxy() == style); proxyStyle->setBaseStyle(style); @@ -225,7 +224,7 @@ void tst_QStyle::testProxyStyle() QVERIFY(proxyStyle->baseStyle()); qApp->setStyle(proxyStyle); - QProxyStyle doubleProxy(new QProxyStyle(new QWindowsStyle())); + QProxyStyle doubleProxy(new QProxyStyle(QStyleFactory::create("Windows"))); QVERIFY(testAllFunctions(&doubleProxy)); CustomProxy customStyle; @@ -363,16 +362,17 @@ void tst_QStyle::testFusionStyle() void tst_QStyle::testWindowsStyle() { - QWindowsStyle wstyle; - QVERIFY(testAllFunctions(&wstyle)); - lineUpLayoutTest(&wstyle); + QStyle *wstyle = QStyleFactory::create("Windows"); + QVERIFY(testAllFunctions(wstyle)); + lineUpLayoutTest(wstyle); // Tests drawing indeterminate progress with 0 size: QTBUG-15973 QStyleOptionProgressBar pb; pb.rect = QRect(0,0,-9,0); QPixmap surface(QSize(200, 200)); QPainter painter(&surface); - wstyle.drawControl(QStyle::CE_ProgressBar, &pb, &painter, 0); + wstyle->drawControl(QStyle::CE_ProgressBar, &pb, &painter, 0); + delete wstyle; } #if defined(Q_OS_WIN) && !defined(QT_NO_STYLE_WINDOWSXP) @@ -566,11 +566,11 @@ void MyWidget::paintEvent( QPaintEvent* ) } -class Qt42Style : public QWindowsStyle +class Qt42Style : public QCommonStyle { Q_OBJECT public: - Qt42Style() : QWindowsStyle() + Qt42Style() : QCommonStyle() { margin_toplevel = 10; margin = 5; @@ -602,7 +602,7 @@ int Qt42Style::pixelMetric(PixelMetric metric, const QStyleOption * option /*= 0 default: break; } - return QWindowsStyle::pixelMetric(metric, option, widget); + return -1; } @@ -636,11 +636,11 @@ void tst_QStyle::progressBarChangeStyle() //test a crashing situation (task 143530) //where changing the styles and deleting a progressbar would crash - QWindowsStyle style1; + QStyle *style1 = QStyleFactory::create("Windows"); QStyle *style2 = QStyleFactory::create("Fusion"); QProgressBar *progress=new QProgressBar; - progress->setStyle(&style1); + progress->setStyle(style1); progress->show(); @@ -652,6 +652,7 @@ void tst_QStyle::progressBarChangeStyle() QTest::qWait(100); //before the correction, there would be a crash here + delete style1; delete style2; } #endif @@ -746,17 +747,19 @@ void tst_QStyle::testDrawingShortcuts() #define SCROLLBAR_SPACING 33 -class FrameTestStyle : public QWindowsStyle { +class FrameTestStyle : public QProxyStyle { +public: + FrameTestStyle() : QProxyStyle(QStyleFactory::create("Windows")) { } int styleHint(StyleHint hint, const QStyleOption *opt, const QWidget *widget, QStyleHintReturn *returnData) const { if (hint == QStyle::SH_ScrollView_FrameOnlyAroundContents) return 1; - return QWindowsStyle ::styleHint(hint, opt, widget, returnData); + return QProxyStyle ::styleHint(hint, opt, widget, returnData); } int pixelMetric(PixelMetric pm, const QStyleOption *option, const QWidget *widget) const { if (pm == QStyle::PM_ScrollView_ScrollBarSpacing) return SCROLLBAR_SPACING; - return QWindowsStyle ::pixelMetric(pm, option ,widget); + return QProxyStyle ::pixelMetric(pm, option ,widget); } }; @@ -764,12 +767,12 @@ void tst_QStyle::testFrameOnlyAroundContents() { QScrollArea area; area.setGeometry(0, 0, 200, 200); - QWindowsStyle winStyle; + QStyle *winStyle = QStyleFactory::create("Windows"); FrameTestStyle frameStyle; QWidget *widget = new QWidget(&area); widget->setGeometry(0, 0, 400, 400); - area.setStyle(&winStyle); - area.verticalScrollBar()->setStyle(&winStyle); + area.setStyle(winStyle); + area.verticalScrollBar()->setStyle(winStyle); area.setWidget(widget); area.setVisible(true); int viewPortWidth = area.viewport()->width(); @@ -777,6 +780,7 @@ void tst_QStyle::testFrameOnlyAroundContents() area.setStyle(&frameStyle); // Test that we reserve space for scrollbar spacing QVERIFY(viewPortWidth == area.viewport()->width() + SCROLLBAR_SPACING); + delete winStyle; } diff --git a/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp b/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp index 5f2c9a62b9..e39757b980 100644 --- a/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp +++ b/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp @@ -357,9 +357,8 @@ void tst_QStyleSheetStyle::widgetStyle() widget1->ensurePolished(); widget2->ensurePolished(); - QWindowsStyle style1, style2; - QPointer pstyle1 = &style1; - QPointer pstyle2 = &style2; + QPointer style1 = QStyleFactory::create("Windows"); + QPointer style2 = QStyleFactory::create("Windows"); QStyle *appStyle = qApp->style(); @@ -367,19 +366,19 @@ void tst_QStyleSheetStyle::widgetStyle() QCOMPARE(appStyle, window1->style()); // Setting a custom style on a widget - window1->setStyle(&style1); - QCOMPARE(static_cast(&style1), window1->style()); + window1->setStyle(style1); + QCOMPARE(style1.data(), window1->style()); // Setting another style must not delete the older style - window1->setStyle(&style2); - QCOMPARE(static_cast(&style2), window1->style()); - QVERIFY(!pstyle1.isNull()); // case we have not already crashed + window1->setStyle(style2); + QCOMPARE(style2.data(), window1->style()); + QVERIFY(!style1.isNull()); // case we have not already crashed // Setting null style must make it follow the qApp style window1->setStyle(0); QCOMPARE(window1->style(), appStyle); - QVERIFY(!pstyle2.isNull()); // case we have not already crashed - QVERIFY(!pstyle2.isNull()); // case we have not already crashed + QVERIFY(!style2.isNull()); // case we have not already crashed + QVERIFY(!style2.isNull()); // case we have not already crashed // Sanity: Set the stylesheet window1->setStyleSheet(":x { }"); @@ -390,22 +389,22 @@ void tst_QStyleSheetStyle::widgetStyle() QVERIFY(proxy->base == 0); // and follows the application // Set the stylesheet - window1->setStyle(&style1); + window1->setStyle(style1); QVERIFY(proxy.isNull()); // we create a new one each time proxy = (QStyleSheetStyle *)window1->style(); QCOMPARE(proxy->metaObject()->className(), "QStyleSheetStyle"); // it is a proxy - QCOMPARE(proxy->baseStyle(), static_cast(&style1)); // must have been replaced with the new one + QCOMPARE(proxy->baseStyle(), style1.data()); // must have been replaced with the new one // Update the stylesheet and check nothing changes window1->setStyleSheet(":y { }"); QCOMPARE(window1->style()->metaObject()->className(), "QStyleSheetStyle"); // it is a proxy - QCOMPARE(proxy->baseStyle(), static_cast(&style1)); // the same guy + QCOMPARE(proxy->baseStyle(), style1.data()); // the same guy // Remove the stylesheet proxy = (QStyleSheetStyle *)window1->style(); window1->setStyleSheet(""); QVERIFY(proxy.isNull()); // should have disappeared - QCOMPARE(window1->style(), static_cast(&style1)); // its restored + QCOMPARE(window1->style(), style1.data()); // its restored // Style Sheet existing children propagation window1->setStyleSheet(":z { }"); @@ -419,24 +418,24 @@ void tst_QStyleSheetStyle::widgetStyle() QCOMPARE(window1->style(), widget2->style()); // proxy must have propagated // Style Sheet automatic removal from children who abandoned their parents - window2->setStyle(&style2); + window2->setStyle(style2); widget2->setParent(window2); // reparent QCOMPARE(widget2->style(), appStyle); // widget2 is following the app style // Style Sheet propagation on a child widget with a custom style - widget2->setStyle(&style1); + widget2->setStyle(style1); window2->setStyleSheet(":x { }"); proxy = (QStyleSheetStyle *)widget2->style(); QCOMPARE(proxy->metaObject()->className(), "QStyleSheetStyle"); - QCOMPARE(proxy->baseStyle(), static_cast(&style1)); + QCOMPARE(proxy->baseStyle(), style1.data()); // Style Sheet propagation on a child widget with a custom style already set window2->setStyleSheet(""); - QCOMPARE(window2->style(), static_cast(&style2)); - QCOMPARE(widget2->style(), static_cast(&style1)); + QCOMPARE(window2->style(), style2.data()); + QCOMPARE(widget2->style(), style1.data()); widget2->setStyle(0); window2->setStyleSheet(":x { }"); - widget2->setStyle(&style1); + widget2->setStyle(style1); proxy = (QStyleSheetStyle *)widget2->style(); QCOMPARE(proxy->metaObject()->className(), "QStyleSheetStyle"); @@ -457,21 +456,21 @@ void tst_QStyleSheetStyle::widgetStyle() QCOMPARE(window1->style()->metaObject()->className(), "QStyleSheetStyle"); // a new one QCOMPARE(widget1->style(), window1->style()); // child follows... proxy = (QStyleSheetStyle *) window1->style(); - QWindowsStyle *newStyle = new QWindowsStyle; + QStyle *newStyle = QStyleFactory::create("Windows"); qApp->setStyle(newStyle); // set a custom style on app proxy = (QStyleSheetStyle *) window1->style(); - QCOMPARE(proxy->baseStyle(), static_cast(newStyle)); // magic ;) the widget still follows the application + QCOMPARE(proxy->baseStyle(), newStyle); // magic ;) the widget still follows the application QCOMPARE(static_cast(proxy), widget1->style()); // child still follows... window1->setStyleSheet(""); // remove stylesheet QCOMPARE(window1->style(), qApp->style()); // is this cool or what QCOMPARE(widget1->style(), qApp->style()); // annoying child follows... - QWindowsStyle wndStyle; - window1->setStyle(&wndStyle); + QStyle *wndStyle = QStyleFactory::create("Windows"); + window1->setStyle(wndStyle); QCOMPARE(window1->style()->metaObject()->className(), "QStyleSheetStyle"); // auto wraps it QCOMPARE(widget1->style(), window1->style()); // and auto propagates to child qApp->setStyleSheet(""); // remove the app stylesheet - QCOMPARE(window1->style(), static_cast(&wndStyle)); // auto dewrap + QCOMPARE(window1->style(), wndStyle); // auto dewrap QCOMPARE(widget1->style(), qApp->style()); // and child state is restored window1->setStyle(0); // let sanity prevail qApp->setStyle(0); @@ -479,6 +478,8 @@ void tst_QStyleSheetStyle::widgetStyle() delete window1; delete widget2; delete window2; + delete style1; + delete style2; } void tst_QStyleSheetStyle::appStyle() @@ -486,8 +487,8 @@ void tst_QStyleSheetStyle::appStyle() qApp->setStyleSheet(""); // qApp style can never be 0 QVERIFY(QApplication::style() != 0); - QPointer style1 = new QWindowsStyle; - QPointer style2 = new QWindowsStyle; + QPointer style1 = QStyleFactory::create("Windows"); + QPointer style2 = QStyleFactory::create("Windows"); qApp->setStyle(style1); // Basic sanity QVERIFY(qApp->style() == style1); @@ -504,7 +505,7 @@ void tst_QStyleSheetStyle::appStyle() QCOMPARE(sss->metaObject()->className(), "QStyleSheetStyle"); // must be our proxy now QVERIFY(!style2.isNull()); // this should exist as it is the base of the proxy QVERIFY(sss->baseStyle() == style2); - style1 = new QWindowsStyle; + style1 = QStyleFactory::create("Windows"); qApp->setStyle(style1); QVERIFY(style2.isNull()); // should disappear automatically QVERIFY(sss.isNull()); // should disappear automatically -- cgit v1.2.3