Skip to content

Commit

Permalink
Add setCurrentId in QWizard
Browse files Browse the repository at this point in the history
setCurrentId(int id) implemented incl. forward skip warning
respective test added in tst_qwizard

Fixes: QTBUG-99488
Change-Id: Ieaf31698baf1e8ec97484b4a221c8587385c9fb3
Reviewed-by: Volker Hilsheimer <[email protected]>
  • Loading branch information
ASpoerl committed Mar 12, 2022
1 parent 297fdca commit 2140eda
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/widgets/dialogs/qwizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3141,6 +3141,42 @@ void QWizard::next()
}
}

/*!
Sets currentId to \a id, without visiting the pages between currentId and \a id.
Returns without page change, if
\list
\li wizard holds no pages
\li current page is invalid
\li given page equals currentId()
\li given page is out of range
\endlist
Note: If pages have been forward skipped and \a id is 0, page visiting history
will be deleted
*/

void QWizard::setCurrentId(int id)
{
Q_D(QWizard);

if (d->current == -1)
return;

if (currentId() == id)
return;

if (!validateCurrentPage())
return;

if (id < 0 || Q_UNLIKELY(!d->pageMap.contains(id))) {
qWarning("QWizard::setCurrentId: No such page: %d", id);
return;
}

d->switchToPage(id, (id < currentId()) ? QWizardPrivate::Backward : QWizardPrivate::Forward);
}

/*!
Restarts the wizard at the start page. This function is called automatically when the
wizard is shown.
Expand Down
1 change: 1 addition & 0 deletions src/widgets/dialogs/qwizard.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ class Q_WIDGETS_EXPORT QWizard : public QDialog
public Q_SLOTS:
void back();
void next();
void setCurrentId(int id);
void restart();

protected:
Expand Down
40 changes: 40 additions & 0 deletions tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ private slots:
void sideWidget();
void objectNames_data();
void objectNames();
void changePages();

// task-specific tests below me:
void task177716_disableCommitButton();
Expand Down Expand Up @@ -2720,6 +2721,45 @@ void tst_QWizard::taskQTBUG_46894_nextButtonShortcut()
}
}

/* setCurrentId(int) method was added in QTBUG99488 */
void tst_QWizard::changePages()
{
QWizard wizard;

QList<QWizardPage*> pages;
for (int i = 0; i < 4; ++i) {
QWizardPage *page = new QWizardPage;
wizard.addPage(page);
pages.append(page);
}

wizard.show();
QVERIFY(QTest::qWaitForWindowExposed(&wizard));

// Verify default page
QCOMPARE(wizard.currentPage(), pages.at(0));

wizard.next();
QVERIFY(wizard.currentId() == 1);
wizard.back();
QVERIFY(wizard.currentId() == 0);

// Test illegal page
QTest::ignoreMessage(QtMsgType::QtWarningMsg, "QWizard::setCurrentId: No such page: 5");
wizard.setCurrentId(5);
QCOMPARE(wizard.currentId(), 0);

for (int i = 0; i < 4; ++i) {
wizard.setCurrentId(i);
QCOMPARE(wizard.currentPage(), pages.at(i));
}

for (int i = 3; i >= 0; --i) {
wizard.setCurrentId(i);
QCOMPARE(wizard.currentPage(), pages.at(i));
}
}

#endif // QT_CONFIG(shortcut)

QTEST_MAIN(tst_QWizard)
Expand Down

0 comments on commit 2140eda

Please sign in to comment.