Documentation: BaseFileWizard.

This commit is contained in:
Friedemann Kleint
2011-04-01 12:18:25 +02:00
parent dec9622cfa
commit deb13f7c5e
2 changed files with 130 additions and 58 deletions

View File

@@ -61,11 +61,6 @@ class BaseFileWizardParameterData;
struct BaseFileWizardPrivate;
class GeneratedFilePrivate;
/*!
* Represents a file generated by a wizard. The Wizard class will check for
* each file whether it already exists and will report any errors that may
* occur during creation of the files.
*/
class CORE_EXPORT GeneratedFile
{
public:
@@ -115,9 +110,6 @@ private:
typedef QList<GeneratedFile> GeneratedFiles;
/* Parameter class for passing parameters to instances of class Wizard
* containing name, icon and such. */
class CORE_EXPORT BaseFileWizardParameters
{
public:
@@ -155,18 +147,6 @@ private:
CORE_EXPORT QDebug operator<<(QDebug d, const BaseFileWizardParameters &);
/* A generic wizard for creating files.
*
* The abstract methods:
*
* createWizardDialog() : Called to create the QWizard dialog to be shown
* generateFiles() : Generate file content
*
* must be implemented. The behaviour can be further customized by overwriting
* the virtual method:
* postGenerateFiles() : Called after generating the files.
*/
class CORE_EXPORT BaseFileWizard : public IWizard
{
Q_DISABLE_COPY(BaseFileWizard)
@@ -187,13 +167,8 @@ public:
virtual void runWizard(const QString &path, QWidget *parent);
// Build a file name, adding the extension unless baseName already has one
static QString buildFileName(const QString &path, const QString &baseName, const QString &extension);
// Sets some standard options on a QWizard
static void setupWizard(QWizard *);
// Read "shortTitle" dynamic property of the pageId and apply it as the title of corresponding progress item
static void applyExtensionPageShortTitle(Utils::Wizard *wizard, int pageId);
protected:
@@ -201,44 +176,27 @@ protected:
explicit BaseFileWizard(const BaseFileWizardParameters &parameters, QObject *parent = 0);
// Overwrite to create the wizard dialog on the parent, adding
// the extension pages.
virtual QWizard *createWizardDialog(QWidget *parent,
const QString &defaultPath,
const WizardPageList &extensionPages) const = 0;
// Overwrite to query the parameters from the dialog and generate the files.
virtual GeneratedFiles generateFiles(const QWizard *w,
QString *errorMessage) const = 0;
/* Physically write files. Re-implement (calling the base implementation)
* to create files with CustomGeneratorAttribute set. */
virtual bool writeFiles(const GeneratedFiles &files, QString *errorMessage);
/* Overwrite to perform steps to be done after files are actually created.
* The default implementation opens editors with the newly generated files. */
virtual bool postGenerateFiles(const QWizard *w, const GeneratedFiles &l, QString *errorMessage);
// Utility that returns the preferred suffix for a mime type
static QString preferredSuffix(const QString &mimeType);
// Utility that performs an overwrite check on a set of files. It checks if
// the file exists, can be overwritten at all and prompts the user.
enum OverwriteResult { OverwriteOk, OverwriteError, OverwriteCanceled };
OverwriteResult promptOverwrite(const QStringList &files,
QString *errorMessage) const;
// Utility to open the editors for the files whose attribute is set accordingly.
static bool postGenerateOpenEditors(const GeneratedFiles &l, QString *errorMessage = 0);
private:
BaseFileWizardPrivate *m_d;
};
// StandardFileWizard convenience class for creating one file. It uses
// Utils::FileWizardDialog and introduces a new virtual to generate the
// files from path and name.
class CORE_EXPORT StandardFileWizard : public BaseFileWizard
{
Q_DISABLE_COPY(StandardFileWizard)
@@ -246,18 +204,11 @@ class CORE_EXPORT StandardFileWizard : public BaseFileWizard
protected:
explicit StandardFileWizard(const BaseFileWizardParameters &parameters, QObject *parent = 0);
// Implemented to create a Utils::FileWizardDialog
virtual QWizard *createWizardDialog(QWidget *parent,
const QString &defaultPath,
const WizardPageList &extensionPages) const;
// Implemented to retrieve path and name and call generateFilesFromPath()
virtual GeneratedFiles generateFiles(const QWizard *w,
QString *errorMessage) const;
// Newly introduced virtual that creates a file from a path
virtual GeneratedFiles generateFilesFromPath(const QString &path,
const QString &name,
virtual GeneratedFiles generateFiles(const QWizard *w, QString *errorMessage) const;
virtual GeneratedFiles generateFilesFromPath(const QString &path, const QString &name,
QString *errorMessage) const = 0;
};