From af5ccb7f8c91591ef9dec1ccf0ca211962002a94 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sun, 7 Aug 2016 15:32:40 +0300 Subject: tst_QStyleSheetStyle: Extract Method sample_widgets() The only difference between the sample widget sets was: - widgets << new QLabel("TESTING TESTING"); + widgets << new QLabel("TESTING TESTING"); I chose the latter, because it's the more complex example and neither the hoverColors nor focusColors tests suggest the boldness of the text matters. Part of port away from Q_FOREACH. Change-Id: I9a928de4e781b96ad00a8c9515977c35ebfa6c24 Reviewed-by: Olivier Goffart (Woboq GmbH) --- .../qstylesheetstyle/tst_qstylesheetstyle.cpp | 48 +++++++++------------- 1 file changed, 20 insertions(+), 28 deletions(-) (limited to 'tests') diff --git a/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp b/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp index 8d84addedb..b95a17bd4e 100644 --- a/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp +++ b/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp @@ -817,6 +817,24 @@ static bool testForColors(const QImage& image, const QColor& color, bool ensureP return false; } +static const QList sample_widgets() // returning const to avoid detaching when passing to range-for +{ + QList widgets; + widgets << new QPushButton("TESTING TESTING"); + widgets << new QLineEdit("TESTING TESTING"); + widgets << new QLabel("TESTING TESTING"); + QSpinBox *spinbox = new QSpinBox; + spinbox->setMaximum(1000000000); + spinbox->setValue(123456789); + widgets << spinbox; + QComboBox *combobox = new QComboBox; + combobox->setEditable(true); + combobox->addItems(QStringList() << "TESTING TESTING"); + widgets << combobox; + widgets << new QLabel("TESTING TESTING"); + return widgets; +} + void tst_QStyleSheetStyle::focusColors() { // Tests if colors can be changed by altering the focus of the widget. @@ -833,22 +851,9 @@ void tst_QStyleSheetStyle::focusColors() " (for example, QTBUG-33959)." "That doesn't mean that the feature doesn't work in practice."); #endif - QList widgets; - widgets << new QPushButton("TESTING TESTING"); - widgets << new QLineEdit("TESTING TESTING"); - widgets << new QLabel("TESTING TESTING"); - QSpinBox *spinbox = new QSpinBox; - spinbox->setMaximum(1000000000); - spinbox->setValue(123456789); - widgets << spinbox; - QComboBox *combobox = new QComboBox; - combobox->setEditable(true); - combobox->addItems(QStringList() << "TESTING TESTING"); - widgets << combobox; - widgets << new QLabel("TESTING TESTING"); - foreach (QWidget *widget, widgets) { + for (QWidget *widget : sample_widgets()) { QDialog frame; QLayout* layout = new QGridLayout; @@ -891,21 +896,8 @@ void tst_QStyleSheetStyle::hoverColors() #ifdef Q_OS_OSX QSKIP("This test is fragile on Mac, most likely due to QTBUG-33959."); #endif - QList widgets; - widgets << new QPushButton("TESTING TESTING"); - widgets << new QLineEdit("TESTING TESTING"); - widgets << new QLabel("TESTING TESTING"); - QSpinBox *spinbox = new QSpinBox; - spinbox->setMaximum(1000000000); - spinbox->setValue(123456789); - widgets << spinbox; - QComboBox *combobox = new QComboBox; - combobox->setEditable(true); - combobox->addItems(QStringList() << "TESTING TESTING"); - widgets << combobox; - widgets << new QLabel("TESTING TESTING"); - foreach (QWidget *widget, widgets) { + for (QWidget *widget : sample_widgets()) { //without Qt::X11BypassWindowManagerHint the window manager may move the window after we moved the cursor QDialog frame(0, Qt::X11BypassWindowManagerHint); QLayout* layout = new QGridLayout; -- cgit v1.2.3