Wizards: Provide mechanism to skip pages

Our wizard infrastructure makes it hard to dynamically remove
or add wizard pages on the fly while using the wizard.
So, instead of removing pages and re-adding them on need
just provide a way to skip pages.
Skipping pages is provided with this patch limited to
wizards which are known to be sub projects.
For now this is just a preparation as no wizard actively
sets the property for being a sub project or makes use
of this mechanism.

Change-Id: I3efd079ccb5be2203d2b17b3765d9f178998d5f4
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Christian Stenger
2024-05-29 12:08:04 +02:00
parent 9bdf8329a0
commit fcadc9a2b2
3 changed files with 35 additions and 0 deletions

View File

@@ -276,6 +276,7 @@ public:
bool m_automaticProgressCreation = true;
WizardProgress *m_wizardProgress = nullptr;
QSet<QString> m_fieldNames;
bool m_skipForSubproject = false;
};
Wizard::Wizard(QWidget *parent, Qt::WindowFlags flags) :
@@ -525,6 +526,32 @@ void Wizard::_q_pageRemoved(int pageId)
d->m_wizardProgress->removeItem(item);
}
void Wizard::setSkipForSubprojects(bool skip)
{
Q_D(Wizard);
d->m_skipForSubproject = skip;
}
int Wizard::nextId() const
{
Q_D(const Wizard);
if (!d->m_skipForSubproject)
return QWizard::nextId();
const QList<int> allIds = pageIds();
int index = allIds.indexOf(currentId());
QTC_ASSERT(index > -1, return QWizard::nextId());
while (++index < allIds.size()) {
if (auto wp = qobject_cast<WizardPage *>(page(index))) {
if (!wp->skipForSubprojects())
return index;
}
}
QTC_CHECK(false); // should not happen
return QWizard::nextId();
}
class WizardProgressPrivate
{
WizardProgress *q_ptr;

View File

@@ -50,6 +50,10 @@ public:
void showVariables();
// allows to skip pages
void setSkipForSubprojects(bool skip);
int nextId() const override;
protected:
virtual QString stringify(const QVariant &v) const;
virtual QString evaluate(const QVariant &v) const;

View File

@@ -74,6 +74,9 @@ public:
void registerFieldWithName(const QString &name, QWidget *widget,
const char *property = nullptr, const char *changedSignal = nullptr);
void setSkipForSubprojects(bool skip) { m_skipForSubproject = skip; }
bool skipForSubprojects() const { return m_skipForSubproject; }
virtual bool handleReject();
virtual bool handleAccept();
@@ -85,6 +88,7 @@ private:
void registerFieldName(const QString &name);
QSet<QString> m_toRegister;
bool m_skipForSubproject = false;
};
} // namespace Utils