- Extending Qt Creator Manual
- QtCreator
- BaseFileWizardFactory
- Extending Qt Creator Manual 20.0.0-beta1

# Core::BaseFileWizardFactory Class

class Core::BaseFileWizardFactory

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

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

- List of all members, including inherited members

## Static Public Members

Utils::FilePath | buildFileName(const Utils::FilePath &path, const QString &baseName, const QString &extension)

## Protected Functions

virtual Core::BaseFileWizard * | create(const Core::WizardDialogParameters &parameters) const = 0
virtual Utils::Result<> | postGenerateFiles(const QWizard *w, const Core::GeneratedFiles &l) const
virtual Utils::Result<> | writeFiles(const Core::GeneratedFiles &files) const

## Static Protected Members

Utils::Result<> | postGenerateOpenEditors(const Core::GeneratedFiles &l)
QString | preferredSuffix(const QString &mimeType)
Utils::Result<Core::BaseFileWizardFactory::OverwriteResult> | promptOverwrite(Core::GeneratedFiles *files)

## 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 Qt Creator: Add wizards and Qt Creator: Custom wizards.

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

## Member Function Documentation

### `[static]` Utils::FilePath BaseFileWizardFactory::buildFileName(const Utils::FilePath &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(const Core::WizardDialogParameters &parameters) const

Creates the wizard with the parameters.

### `[virtual protected]` Utils::Result<> BaseFileWizardFactory::postGenerateFiles(const QWizard *w, const Core::GeneratedFiles &l) 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.

### `[static protected]` Utils::Result<> BaseFileWizardFactory::postGenerateOpenEditors(const Core::GeneratedFiles &l)

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

If the editors cannot be opened, returns `Utils::ResultError`.

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

Returns the preferred suffix for mimeType.

### `[static protected]` Utils::Result<Core::BaseFileWizardFactory::OverwriteResult> BaseFileWizardFactory::promptOverwrite(Core::GeneratedFiles *files)

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 whether the file can be overwritten.

### `[virtual protected]` Utils::Result<> BaseFileWizardFactory::writeFiles(const Core::GeneratedFiles &files) const

Physically writes files.

If the files cannot be written, returns `Utils::ResultError`.

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