Add setCurrentId in QWizard
setCurrentId(int id) implemented incl. forward skip warning respective test added in tst_qwizard Fixes: QTBUG-99488 Change-Id: Ieaf31698baf1e8ec97484b4a221c8587385c9fb3 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>bb10
parent
297fdcaf30
commit
2140edaaab
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -181,6 +181,7 @@ Q_SIGNALS:
|
|||
public Q_SLOTS:
|
||||
void back();
|
||||
void next();
|
||||
void setCurrentId(int id);
|
||||
void restart();
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -89,6 +89,7 @@ private slots:
|
|||
void sideWidget();
|
||||
void objectNames_data();
|
||||
void objectNames();
|
||||
void changePages();
|
||||
|
||||
// task-specific tests below me:
|
||||
void task177716_disableCommitButton();
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue