BaseFileWizardFactory Class

class Core::BaseFileWizardFactory

The BaseFileWizardFactory class implements a generic wizard for creating files. More...

Header: #include <coreplugin/basefilewizardfactory.h>
Inherits: Core::IWizardFactory

Static Public Members

QString buildFileName(const QString &path, const QString &baseName, const QString &extension)

Protected Functions

virtual Core::BaseFileWizard *create(QWidget *parent, const Core::WizardDialogParameters &parameters) const = 0
virtual Core::GeneratedFiles generateFiles(const QWizard *w, QString *errorMessage) const = 0
virtual bool postGenerateFiles(const QWizard *w, const Core::GeneratedFiles &l, QString *errorMessage) const
Core::BaseFileWizardFactory::OverwriteResult promptOverwrite(Core::GeneratedFiles *files, QString *errorMessage) const
virtual bool writeFiles(const Core::GeneratedFiles &files, QString *errorMessage) const

Static Protected Members

bool postGenerateOpenEditors(const Core::GeneratedFiles &l, QString *errorMessage = nullptr)
QString preferredSuffix(const QString &mimeType)

Detailed Description

The following abstract functions must be implemented:

The behavior can be further customized by overwriting the virtual function postGenerateFiles(), which is called after generating the files.

Note: Instead of using this class, we recommend that you create JSON-based wizards, as instructed in Adding New Custom Wizards.

See also Core::GeneratedFile, Core::WizardDialogParameters, and Core::BaseFileWizard.

Member Function Documentation

[static] QString BaseFileWizardFactory::buildFileName(const QString &path, const QString &baseName, const QString &extension)

Constructs a file name including path, adding the extension unless baseName already has one.

[pure virtual protected] Core::BaseFileWizard *BaseFileWizardFactory::create(QWidget *parent, const Core::WizardDialogParameters &parameters) const

Creates the wizard on the parent with the parameters.

[pure virtual protected] Core::GeneratedFiles BaseFileWizardFactory::generateFiles(const QWizard *w, QString *errorMessage) const

Overwrite to query the parameters from the wizard w and generate the files.

Possible errors are held in errorMessage.

Note: This does not generate physical files, but merely the list of Core::GeneratedFile.

[virtual protected] bool BaseFileWizardFactory::postGenerateFiles(const QWizard *w, const Core::GeneratedFiles &l, QString *errorMessage) const

Overwrite to perform steps to be done by the wizard w after the files specified by l are actually created.

The default implementation opens editors with the newly generated files that have GeneratedFile::OpenEditorAttribute set.

Returns errorMessage if errors occur.

[static protected] bool BaseFileWizardFactory::postGenerateOpenEditors(const Core::GeneratedFiles &l, QString *errorMessage = nullptr)

Opens the editors for the files l if their GeneratedFile::OpenEditorAttribute attribute is set accordingly.

If the editorrs cannot be opened, returns false and dand sets errorMessage to the message that is displayed to users.

[static protected] QString BaseFileWizardFactory::preferredSuffix(const QString &mimeType)

Returns the preferred suffix for mimeType.

[protected] Core::BaseFileWizardFactory::OverwriteResult BaseFileWizardFactory::promptOverwrite(Core::GeneratedFiles *files, QString *errorMessage) const

Performs an overwrite check on a set of files. Checks if the file exists and can be overwritten at all, and then prompts the user with a summary.

Returns errorMessage if the file cannot be overwritten.

[virtual protected] bool BaseFileWizardFactory::writeFiles(const Core::GeneratedFiles &files, QString *errorMessage) const

Physically writes files.

If the files cannot be written, returns false and sets errorMessage to the message that is displayed to users.

Re-implement (calling the base implementation) to create files with GeneratedFile::CustomGeneratorAttribute set.

© 2020 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.