Commit 0f073e4a authored by Thomas Hartmann's avatar Thomas Hartmann
Browse files

Wizards: avoiding code duplication



I moved setPath(wizardDialogParameters.defaultPath()) into
the constructor of BaseProjectWizardDialog.

I created addExtensionPages() instead of having of having the
foreach everywhere. Moving the call into the constructor of
BaseProjectWizardDialog is not trivial since a lot of derived classes
rely on execution order and the order is often different.
Entangling this is not trivial and easily might break functionality.

Change-Id: I48dddaf72caea84da783dc9e2f42f2c7eff1c0ce
Reviewed-by: default avatarFriedemann Kleint <Friedemann.Kleint@nokia.com>
parent c4b631f9
......@@ -72,6 +72,7 @@ BaseProjectWizardDialog::BaseProjectWizardDialog(QWidget *parent,
Utils::Wizard(parent),
d(new BaseProjectWizardDialogPrivate(new Utils::ProjectIntroPage))
{
setPath(parameters.defaultPath());
setSelectedPlatform(parameters.selectedPlatform());
setRequiredFeatures(parameters.requiredFeatures());
init();
......@@ -84,6 +85,7 @@ BaseProjectWizardDialog::BaseProjectWizardDialog(Utils::ProjectIntroPage *introP
Utils::Wizard(parent),
d(new BaseProjectWizardDialogPrivate(introPage, introId))
{
setPath(parameters.defaultPath());
setSelectedPlatform(parameters.selectedPlatform());
setRequiredFeatures(parameters.requiredFeatures());
init();
......@@ -171,6 +173,12 @@ QString BaseProjectWizardDialog::uniqueProjectName(const QString &path)
return prefix;
}
void BaseProjectWizardDialog::addExtensionPages(const QList<QWizardPage *> &wizardPageList)
{
foreach (QWizardPage *p,wizardPageList)
Core::BaseFileWizard::applyExtensionPageShortTitle(this, addPage(p));
}
QString BaseProjectWizardDialog::selectedPlatform() const
{
return d->selectedPlatform;
......
......@@ -68,6 +68,7 @@ public:
// Generate a new project name (untitled<n>) in path.
static QString uniqueProjectName(const QString &path);
void addExtensionPages(const QList<QWizardPage *> &wizardPageList);
public slots:
void setIntroDescription(const QString &d);
......
......@@ -93,11 +93,9 @@ QWizard *QmlProjectApplicationWizard::createWizardDialog(QWidget *parent,
{
QmlProjectApplicationWizardDialog *wizard = new QmlProjectApplicationWizardDialog(parent, wizardDialogParameters);
wizard->setPath(wizardDialogParameters.defaultPath());
wizard->setProjectName(QmlProjectApplicationWizardDialog::uniqueProjectName(wizardDialogParameters.defaultPath()));
foreach (QWizardPage *p, wizardDialogParameters.extensionPages())
BaseFileWizard::applyExtensionPageShortTitle(wizard, wizard->addPage(p));
wizard->addExtensionPages(wizardDialogParameters.extensionPages());
return wizard;
}
......
......@@ -67,7 +67,6 @@ QWizard *CustomWidgetWizard::createWizardDialog(QWidget *parent,
icon(),
parent,
wizardDialogParameters);
rc->setPath(wizardDialogParameters.defaultPath());
rc->setProjectName(CustomWidgetWizardDialog::uniqueProjectName(wizardDialogParameters.defaultPath()));
rc->setFileNamingParameters(FileNamingParameters(headerSuffix(), sourceSuffix(), QtWizard::lowerCaseFiles()));
return rc;
......
......@@ -61,8 +61,7 @@ CustomWidgetWizardDialog::CustomWidgetWizardDialog(const QString &templateName,
wizardProgress()->item(m_widgetPageId)->setTitle(tr("Custom Widgets"));
wizardProgress()->item(m_pluginPageId)->setTitle(tr("Plugin Details"));
foreach (QWizardPage *p, parameters.extensionPages())
Core::BaseFileWizard::applyExtensionPageShortTitle(this, addPage(p));
addExtensionPages(parameters.extensionPages());
connect(this, SIGNAL(currentIdChanged(int)), this, SLOT(slotCurrentIdChanged(int)));
}
......
......@@ -234,7 +234,6 @@ QWizard *AbstractMobileAppWizard::createWizardDialog(QWidget *parent,
{
AbstractMobileAppWizardDialog * const wdlg
= createWizardDialogInternal(parent, wizardDialogParameters);
wdlg->setPath(wizardDialogParameters.defaultPath());
wdlg->setProjectName(ProjectExplorer::BaseProjectWizardDialog::uniqueProjectName(wizardDialogParameters.defaultPath()));
wdlg->m_genericOptionsPage->setOrientation(app()->orientation());
wdlg->m_symbianOptionsPage->setSvgIcon(app()->symbianSvgIcon());
......@@ -244,8 +243,8 @@ QWizard *AbstractMobileAppWizard::createWizardDialog(QWidget *parent,
wdlg->m_harmattanOptionsPage->setBoosterOptionEnabled(app()->canSupportMeegoBooster());
connect(wdlg, SIGNAL(projectParametersChanged(QString, QString)),
SLOT(useProjectPath(QString, QString)));
foreach (QWizardPage *p, wizardDialogParameters.extensionPages())
BaseFileWizard::applyExtensionPageShortTitle(wdlg, wdlg->addPage(p));
wdlg->addExtensionPages(wizardDialogParameters.extensionPages());
return wdlg;
}
......
......@@ -72,7 +72,6 @@ QWizard *ConsoleAppWizard::createWizardDialog(QWidget *parent,
{
ConsoleAppWizardDialog *dialog = new ConsoleAppWizardDialog(displayName(), icon(),
showModulesPageForApplications(), parent, wizardDialogParameters);
dialog->setPath(wizardDialogParameters.defaultPath());
dialog->setProjectName(ConsoleAppWizardDialog::uniqueProjectName(wizardDialogParameters.defaultPath()));
return dialog;
}
......
......@@ -57,8 +57,7 @@ ConsoleAppWizardDialog::ConsoleAppWizardDialog(const QString &templateName,
addModulesPage();
addTargetSetupPage();
foreach (QWizardPage *p, parameters.extensionPages())
Core::BaseFileWizard::applyExtensionPageShortTitle(this, addPage(p));
addExtensionPages(parameters.extensionPages());
}
QtProjectParameters ConsoleAppWizardDialog::parameters() const
......
......@@ -61,7 +61,6 @@ QWizard *EmptyProjectWizard::createWizardDialog(QWidget *parent,
const Core::WizardDialogParameters &wizardDialogParameters) const
{
EmptyProjectWizardDialog *dialog = new EmptyProjectWizardDialog(displayName(), icon(), parent, wizardDialogParameters);
dialog->setPath(wizardDialogParameters.defaultPath());
dialog->setProjectName(EmptyProjectWizardDialog::uniqueProjectName(wizardDialogParameters.defaultPath()));
return dialog;
}
......
......@@ -49,8 +49,7 @@ EmptyProjectWizardDialog::EmptyProjectWizardDialog(const QString &templateName,
addTargetSetupPage();
foreach (QWizardPage *p, parameters.extensionPages())
Core::BaseFileWizard::applyExtensionPageShortTitle(this, addPage(p));
addExtensionPages(parameters.extensionPages());
}
QtProjectParameters EmptyProjectWizardDialog::parameters() const
......
......@@ -120,7 +120,6 @@ QWizard *GuiAppWizard::createWizardDialog(QWidget *parent,
showModulesPageForApplications(),
m_createMobileProject,
parent, wizardDialogParameters);
dialog->setPath(wizardDialogParameters.defaultPath());
dialog->setProjectName(GuiAppWizardDialog::uniqueProjectName(wizardDialogParameters.defaultPath()));
// Order! suffixes first to generate files correctly
dialog->setLowerCaseFiles(QtWizard::lowerCaseFiles());
......
......@@ -73,8 +73,7 @@ GuiAppWizardDialog::GuiAppWizardDialog(const QString &templateName,
const int filesPageId = addPage(m_filesPage);
wizardProgress()->item(filesPageId)->setTitle(tr("Details"));
foreach (QWizardPage *p, parameters.extensionPages())
Core::BaseFileWizard::applyExtensionPageShortTitle(this, addPage(p));
addExtensionPages(parameters.extensionPages());
}
void GuiAppWizardDialog::setBaseClasses(const QStringList &baseClasses)
......
......@@ -71,7 +71,6 @@ QWizard *LibraryWizard::createWizardDialog(QWidget *parent, const Core::WizardDi
parent,
wizardDialogParameters);
dialog->setLowerCaseFiles(QtWizard::lowerCaseFiles());
dialog->setPath(wizardDialogParameters.defaultPath());
dialog->setProjectName(LibraryWizardDialog::uniqueProjectName(wizardDialogParameters.defaultPath()));
dialog->setSuffixes(headerSuffix(), sourceSuffix(), formSuffix());
return dialog;
......
......@@ -191,8 +191,7 @@ LibraryWizardDialog::LibraryWizardDialog(const QString &templateName,
connect(this, SIGNAL(currentIdChanged(int)), this, SLOT(slotCurrentIdChanged(int)));
foreach (QWizardPage *p, parameters.extensionPages())
Core::BaseFileWizard::applyExtensionPageShortTitle(this, addPage(p));
addExtensionPages(parameters.extensionPages());
}
void LibraryWizardDialog::setSuffixes(const QString &header, const QString &source, const QString &form)
......
......@@ -320,6 +320,12 @@ bool BaseQt4ProjectWizardDialog::isTargetSelected(const QString &targetid) const
return m_targetSetupPage->isTargetSelected(targetid);
}
void BaseQt4ProjectWizardDialog::addExtensionPages(const QList<QWizardPage *> &wizardPageList)
{
foreach (QWizardPage *p,wizardPageList)
Core::BaseFileWizard::applyExtensionPageShortTitle(this, addPage(p));
}
void BaseQt4ProjectWizardDialog::generateProfileName(const QString &name, const QString &path)
{
const QString proFile =
......
......@@ -144,6 +144,8 @@ public:
bool setupProject(Qt4Project *project) const;
bool isTargetSelected(const QString &targetid) const;
void addExtensionPages(const QList<QWizardPage *> &wizardPageList);
private slots:
void generateProfileName(const QString &name, const QString &path);
......
......@@ -57,7 +57,7 @@ QWizard *SubdirsProjectWizard::createWizardDialog(QWidget *parent,
const Core::WizardDialogParameters &wizardDialogParameters) const
{
SubdirsProjectWizardDialog *dialog = new SubdirsProjectWizardDialog(displayName(), icon(), parent, wizardDialogParameters);
dialog->setPath(wizardDialogParameters.defaultPath());
dialog->setProjectName(SubdirsProjectWizardDialog::uniqueProjectName(wizardDialogParameters.defaultPath()));
const QString buttonText = dialog->wizardStyle() == QWizard::MacStyle
? tr("Done && Add Subproject") : tr("Finish && Add Subproject");
......
......@@ -50,8 +50,7 @@ SubdirsProjectWizardDialog::SubdirsProjectWizardDialog(const QString &templateNa
addTargetSetupPage();
foreach (QWizardPage *p, parameters.extensionPages())
Core::BaseFileWizard::applyExtensionPageShortTitle(this, addPage(p));
addExtensionPages(parameters.extensionPages());
}
QtProjectParameters SubdirsProjectWizardDialog::parameters() const
......
......@@ -63,7 +63,6 @@ QWizard *TestWizard::createWizardDialog(QWidget *parent,
const Core::WizardDialogParameters &wizardDialogParameters) const
{
TestWizardDialog *dialog = new TestWizardDialog(displayName(), icon(), parent, wizardDialogParameters);
dialog->setPath(wizardDialogParameters.defaultPath());
dialog->setProjectName(TestWizardDialog::uniqueProjectName(wizardDialogParameters.defaultPath()));
return dialog;
}
......
......@@ -67,8 +67,7 @@ TestWizardDialog::TestWizardDialog(const QString &templateName,
m_modulesPageId = addModulesPage();
m_testPageId = addPage(m_testPage);
wizardProgress()->item(m_testPageId)->setTitle(tr("Details"));
foreach (QWizardPage *p, parameters.extensionPages())
Core::BaseFileWizard::applyExtensionPageShortTitle(this, addPage(p));
addExtensionPages(parameters.extensionPages());
connect(this, SIGNAL(currentIdChanged(int)), this, SLOT(slotCurrentIdChanged(int)));
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment