BaseFileWizardFactory Class | Extending Qt Creator Manual

Extending Qt Creator Manual | BaseFileWizardFactory

Extending Qt Creator Manual 4.12.0

# BaseFileWizardFactory Class

(Core::BaseFileWizardFactory)

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

Header: | #include <BaseFileWizardFactory>
Inherits: | Core::IWizardFactory

- List of all members, including inherited members

## 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:

- create(): Called to create the QWizard dialog to be shown.
- generateFiles(): Generates file content.

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.