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

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

Protected Functions

virtual Core::GeneratedFiles generateFiles(const QWizard *w, QString *errorMessage) 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 Add wizards and 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::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] 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 errorMessage if the file cannot 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.

Copyright © The Qt Company Ltd. and other contributors. 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.