summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2013-10-08 13:31:19 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-10-28 12:05:22 +0100
commit1ea191276ea49ce2334d21b1f4a2c66ee8889466 (patch)
treee054557748a50bdb61daca5e2678faf5e6351bd1
parent862a8d46c3cb0b59100e4fa9bb1e34b517df78ee (diff)
QWizard: give all buttons an objectName
Only Commit, Finish and Cancel didn't have an object name, yet. Also Extract Method on the switch statement, add a test, and use QStringBuilder. Task-number: QTBUG-29924 Reported-by: Leo Arias Change-Id: I8c29606bc53e9d4caab631da2089e971a9da2d75 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
-rw-r--r--src/widgets/dialogs/qwizard.cpp29
-rw-r--r--tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp42
2 files changed, 58 insertions, 13 deletions
diff --git a/src/widgets/dialogs/qwizard.cpp b/src/widgets/dialogs/qwizard.cpp
index 02ad5a3be5..4e82167049 100644
--- a/src/widgets/dialogs/qwizard.cpp
+++ b/src/widgets/dialogs/qwizard.cpp
@@ -1345,6 +1345,21 @@ void QWizardPrivate::updateCurrentPage()
updateButtonTexts();
}
+static QString object_name_for_button(QWizard::WizardButton which)
+{
+ switch (which) {
+ case QWizard::CommitButton:
+ return QLatin1String("qt_wizard_") + QLatin1String("commit");
+ case QWizard::FinishButton:
+ return QLatin1String("qt_wizard_") + QLatin1String("finish");
+ case QWizard::CancelButton:
+ return QLatin1String("qt_wizard_") + QLatin1String("cancel");
+ default:
+ // Make navigation buttons detectable as passive interactor in designer
+ return QLatin1String("__qt__passive_wizardbutton") + QString::number(which);
+ }
+}
+
bool QWizardPrivate::ensureButton(QWizard::WizardButton which) const
{
Q_Q(const QWizard);
@@ -1356,19 +1371,7 @@ bool QWizardPrivate::ensureButton(QWizard::WizardButton which) const
QStyle *style = q->style();
if (style != QApplication::style()) // Propagate style
pushButton->setStyle(style);
- // Make navigation buttons detectable as passive interactor in designer
- switch (which) {
- case QWizard::CommitButton:
- case QWizard::FinishButton:
- case QWizard::CancelButton:
- break;
- default: {
- QString objectName = QLatin1String("__qt__passive_wizardbutton");
- objectName += QString::number(which);
- pushButton->setObjectName(objectName);
- }
- break;
- }
+ pushButton->setObjectName(object_name_for_button(which));
#ifdef Q_OS_MACX
pushButton->setAutoDefault(false);
#endif
diff --git a/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp b/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp
index 4506d0af14..a711bc28e3 100644
--- a/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp
+++ b/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp
@@ -52,6 +52,8 @@
#include <QWizard>
#include <QTreeWidget>
+Q_DECLARE_METATYPE(QWizard::WizardButton);
+
static QImage grabWidget(QWidget *window)
{
return window->grab().toImage();
@@ -100,6 +102,8 @@ private slots:
void setWizardStyle();
void removePage();
void sideWidget();
+ void objectNames_data();
+ void objectNames();
// task-specific tests below me:
void task177716_disableCommitButton();
@@ -2384,6 +2388,44 @@ void tst_QWizard::sideWidget()
QVERIFY(wizard.sideWidget() == 0);
}
+void tst_QWizard::objectNames_data()
+{
+ QTest::addColumn<QWizard::WizardButton>("wizardButton");
+ QTest::addColumn<QString>("buttonName");
+
+ QTest::newRow("BackButton") << QWizard::BackButton << QStringLiteral("__qt__passive_wizardbutton0");
+ QTest::newRow("NextButton") << QWizard::NextButton << QStringLiteral("__qt__passive_wizardbutton1");
+ QTest::newRow("CommitButton") << QWizard::CommitButton << QStringLiteral("qt_wizard_commit");
+ QTest::newRow("FinishButton") << QWizard::FinishButton << QStringLiteral("qt_wizard_finish");
+ QTest::newRow("CancelButton") << QWizard::CancelButton << QStringLiteral("qt_wizard_cancel");
+ QTest::newRow("HelpButton") << QWizard::HelpButton << QStringLiteral("__qt__passive_wizardbutton5");
+ QTest::newRow("CustomButton1") << QWizard::CustomButton1 << QStringLiteral("__qt__passive_wizardbutton6");
+ QTest::newRow("CustomButton2") << QWizard::CustomButton2 << QStringLiteral("__qt__passive_wizardbutton7");
+ QTest::newRow("CustomButton3") << QWizard::CustomButton3 << QStringLiteral("__qt__passive_wizardbutton8");
+}
+
+void tst_QWizard::objectNames()
+{
+ QFETCH(QWizard::WizardButton, wizardButton);
+ QFETCH(QString, buttonName);
+
+ QWizard wizard;
+ QList<QWizard::WizardButton> buttons = QList<QWizard::WizardButton>()
+ << QWizard::BackButton
+ << QWizard::NextButton
+ << QWizard::CommitButton
+ << QWizard::FinishButton
+ << QWizard::CancelButton
+ << QWizard::HelpButton
+ << QWizard::CustomButton1
+ << QWizard::CustomButton2
+ << QWizard::CustomButton3
+ ;
+ QVERIFY(buttons.contains(wizardButton));
+ QVERIFY(wizard.button(wizardButton));
+ QCOMPARE(wizard.button(wizardButton)->objectName(), buttonName);
+}
+
class task177716_CommitPage : public QWizardPage
{
Q_OBJECT