diff options
Diffstat (limited to 'src/widgets/dialogs/qwizard.cpp')
-rw-r--r-- | src/widgets/dialogs/qwizard.cpp | 85 |
1 files changed, 64 insertions, 21 deletions
diff --git a/src/widgets/dialogs/qwizard.cpp b/src/widgets/dialogs/qwizard.cpp index a667f299e8..1cd294e5ea 100644 --- a/src/widgets/dialogs/qwizard.cpp +++ b/src/widgets/dialogs/qwizard.cpp @@ -129,22 +129,41 @@ static bool objectInheritsXAndXIsCloserThanY(const QObject *object, const QByteA return false; } -const int NFallbackDefaultProperties = 7; - const struct { - const char *className; - const char *property; - const char *changedSignal; -} fallbackProperties[NFallbackDefaultProperties] = { + const char className[16]; + const char property[13]; +} fallbackProperties[] = { // If you modify this list, make sure to update the documentation (and the auto test) - { "QAbstractButton", "checked", SIGNAL(toggled(bool)) }, - { "QAbstractSlider", "value", SIGNAL(valueChanged(int)) }, - { "QComboBox", "currentIndex", SIGNAL(currentIndexChanged(int)) }, - { "QDateTimeEdit", "dateTime", SIGNAL(dateTimeChanged(QDateTime)) }, - { "QLineEdit", "text", SIGNAL(textChanged(QString)) }, - { "QListWidget", "currentRow", SIGNAL(currentRowChanged(int)) }, - { "QSpinBox", "value", SIGNAL(valueChanged(int)) } + { "QAbstractButton", "checked" }, + { "QAbstractSlider", "value" }, + { "QComboBox", "currentIndex" }, + { "QDateTimeEdit", "dateTime" }, + { "QLineEdit", "text" }, + { "QListWidget", "currentRow" }, + { "QSpinBox", "value" }, }; +const size_t NFallbackDefaultProperties = sizeof fallbackProperties / sizeof *fallbackProperties; + +static const char *changed_signal(int which) +{ + // since it might expand to a runtime function call (to + // qFlagLocations()), we cannot store the result of SIGNAL() in a + // character array and expect it to be statically initialized. To + // avoid the relocations caused by a char pointer table, use a + // switch statement: + switch (which) { + case 0: return SIGNAL(toggled(bool)); + case 1: return SIGNAL(valueChanged(int)); + case 2: return SIGNAL(currentIndexChanged(int)); + case 3: return SIGNAL(dateTimeChanged(QDateTime)); + case 4: return SIGNAL(textChanged(QString)); + case 5: return SIGNAL(currentRowChanged(int)); + case 6: return SIGNAL(valueChanged(int)); + }; + Q_STATIC_ASSERT(7 == NFallbackDefaultProperties); + Q_UNREACHABLE(); + return 0; +} class QWizardDefaultProperty { @@ -737,10 +756,10 @@ void QWizardPrivate::init() updateButtonLayout(); - for (int i = 0; i < NFallbackDefaultProperties; ++i) + for (uint i = 0; i < NFallbackDefaultProperties; ++i) defaultPropertyTable.append(QWizardDefaultProperty(fallbackProperties[i].className, fallbackProperties[i].property, - fallbackProperties[i].changedSignal)); + changed_signal(i))); } void QWizardPrivate::reset() @@ -887,9 +906,28 @@ void QWizardPrivate::switchToPage(int newId, Direction direction) } // keep in sync with QWizard::WizardButton -static const char * const buttonSlots[QWizard::NStandardButtons] = { - SLOT(back()), SLOT(next()), SLOT(next()), SLOT(accept()), SLOT(reject()), - SIGNAL(helpRequested()) +static const char * buttonSlots(QWizard::WizardButton which) +{ + switch (which) { + case QWizard::BackButton: + return SLOT(back()); + case QWizard::NextButton: + case QWizard::CommitButton: + return SLOT(next()); + case QWizard::FinishButton: + return SLOT(accept()); + case QWizard::CancelButton: + return SLOT(reject()); + case QWizard::HelpButton: + return SIGNAL(helpRequested()); + case QWizard::CustomButton1: + case QWizard::CustomButton2: + case QWizard::CustomButton3: + case QWizard::Stretch: + case QWizard::NoButton: + Q_UNREACHABLE(); + }; + return 0; }; QWizardLayoutInfo QWizardPrivate::layoutInfoForCurrentPage() @@ -1405,7 +1443,7 @@ void QWizardPrivate::connectButton(QWizard::WizardButton which) const { Q_Q(const QWizard); if (which < QWizard::NStandardButtons) { - QObject::connect(btns[which], SIGNAL(clicked()), q, buttonSlots[which]); + QObject::connect(btns[which], SIGNAL(clicked()), q, buttonSlots(which)); } else { QObject::connect(btns[which], SIGNAL(clicked()), q, SLOT(_q_emitCustomButtonClicked())); } @@ -1576,7 +1614,7 @@ bool QWizardPrivate::handleAeroStyleChange() if (isWindow) vistaHelper->setTitleBarIconAndCaptionVisible(false); QObject::connect( - vistaHelper->backButton(), SIGNAL(clicked()), q, buttonSlots[QWizard::BackButton]); + vistaHelper->backButton(), SIGNAL(clicked()), q, buttonSlots(QWizard::BackButton)); vistaHelper->backButton()->show(); } else { q->setMouseTracking(true); // ### original value possibly different @@ -1666,6 +1704,10 @@ void QWizardPrivate::_q_updateButtonStates() btn.finish->setVisible(buttonLayoutContains(QWizard::FinishButton) && (canFinish || (opts & QWizard::HaveFinishButtonOnEarlyPages))); + if (!(opts & QWizard::NoCancelButton)) + btn.cancel->setVisible(buttonLayoutContains(QWizard::CancelButton) + && (canContinue || !(opts & QWizard::NoCancelButtonOnLastPage))); + bool useDefault = !(opts & QWizard::NoDefaultButton); if (QPushButton *nextPush = qobject_cast<QPushButton *>(btn.next)) nextPush->setDefault(canContinue && useDefault && !commitPage); @@ -2150,6 +2192,7 @@ void QWizardAntiFlickerWidget::paintEvent(QPaintEvent *) \value HaveCustomButton1 Show the first user-defined button (CustomButton1). \value HaveCustomButton2 Show the second user-defined button (CustomButton2). \value HaveCustomButton3 Show the third user-defined button (CustomButton3). + \value NoCancelButtonOnLastPage Don't show the \uicontrol Cancel button on the last page. \sa setOptions(), setOption(), testOption() */ @@ -2604,7 +2647,7 @@ void QWizard::setOptions(WizardOptions options) d->updateButtonLayout(); } else if (changed & (NoBackButtonOnStartPage | NoBackButtonOnLastPage | HaveNextButtonOnLastPage | HaveFinishButtonOnEarlyPages - | DisabledBackButtonOnLastPage)) { + | DisabledBackButtonOnLastPage | NoCancelButtonOnLastPage)) { d->_q_updateButtonStates(); } |