JsonWizard: Add a polish phase

Add a signal/method to polish the generated files: This phase happens after all files
are written to disk and are ready. It is intended for tasks not directly related to
the project setup: E.g. generation of config files, etc.

Use this to generate our config files.

Change-Id: I9bb5d296bec19f163b70c5ec8d43d5b8e3a52d79
Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
This commit is contained in:
Tobias Hunger
2015-04-23 15:02:59 +02:00
parent ad49b68605
commit 35aafdcdd9
7 changed files with 28 additions and 2 deletions

View File

@@ -55,7 +55,7 @@ void JsonKitsPage::initializePage()
JsonWizard *wiz = qobject_cast<JsonWizard *>(wizard());
QTC_ASSERT(wiz, return);
connect(wiz, &JsonWizard::allDone, this, &JsonKitsPage::setupProjectFiles);
connect(wiz, &JsonWizard::filesPolished, this, &JsonKitsPage::setupProjectFiles);
const QString platform = wiz->stringValue(QLatin1String("Platform"));
const Core::FeatureSet preferred = Core::FeatureSet::fromStringList(wiz->value(QLatin1String("PreferredFeatures")).toStringList());

View File

@@ -209,12 +209,17 @@ void JsonWizard::accept()
return;
}
emit filesReady(m_files);
if (!JsonWizardGenerator::polish(this, &m_files, &errorMessage)) {
if (!errorMessage.isEmpty())
QMessageBox::warning(this, tr("Failed to polish Files"), errorMessage);
return;
}
emit filesPolished(m_files);
if (!JsonWizardGenerator::allDone(this, &m_files, &errorMessage)) {
if (!errorMessage.isEmpty())
QMessageBox::warning(this, tr("Failed to Open Files"), errorMessage);
return;
}
emit allDone(m_files);
}

View File

@@ -90,6 +90,7 @@ signals:
void preWriteFiles(const JsonWizard::GeneratorFiles &files); // emitted before files are written to disk.
void postProcessFiles(const JsonWizard::GeneratorFiles &files); // emitted before files are post-processed.
void filesReady(const JsonWizard::GeneratorFiles &files); // emitted just after files are in final state on disk.
void filesPolished(const JsonWizard::GeneratorFiles &files); // emitted just after additional files (e.g. settings) not directly related to the project were created.
void allDone(const JsonWizard::GeneratorFiles &files); // emitted just after the wizard is done with the files. They are ready to be opened.
public slots:

View File

@@ -199,6 +199,14 @@ bool JsonWizardFileGenerator::postWrite(const JsonWizard *wizard, Core::Generate
return true;
}
bool JsonWizardFileGenerator::polish(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage)
{
Q_UNUSED(wizard);
Q_UNUSED(file);
Q_UNUSED(errorMessage);
return true;
}
bool JsonWizardFileGenerator::allDone(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage)
{
Q_UNUSED(wizard);

View File

@@ -50,6 +50,7 @@ public:
bool writeFile(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage);
bool postWrite(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage);
bool polish(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage);
bool allDone(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage);
private:

View File

@@ -227,6 +227,15 @@ bool JsonWizardGenerator::postWrite(const JsonWizard *wizard, JsonWizard::Genera
return true;
}
bool JsonWizardGenerator::polish(const JsonWizard *wizard, JsonWizard::GeneratorFiles *files, QString *errorMessage)
{
for (auto i = files->begin(); i != files->end(); ++i) {
if (!i->generator->polish(wizard, &(i->file), errorMessage))
return false;
}
return true;
}
bool JsonWizardGenerator::allDone(const JsonWizard *wizard, JsonWizard::GeneratorFiles *files, QString *errorMessage)
{
for (auto i = files->begin(); i != files->end(); ++i) {

View File

@@ -55,6 +55,7 @@ public:
virtual bool formatFile(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage);
virtual bool writeFile(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage) = 0;
virtual bool postWrite(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage) = 0;
virtual bool polish(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage) = 0;
virtual bool allDone(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage) = 0;
virtual bool canKeepExistingFiles() const { return true; }
@@ -65,6 +66,7 @@ public:
static bool formatFiles(const JsonWizard *wizard, QList<JsonWizard::GeneratorFile> *files, QString *errorMessage);
static bool writeFiles(const JsonWizard *wizard, JsonWizard::GeneratorFiles *files, QString *errorMessage);
static bool postWrite(const JsonWizard *wizard, JsonWizard::GeneratorFiles *files, QString *errorMessage);
static bool polish(const JsonWizard *wizard, JsonWizard::GeneratorFiles *files, QString *errorMessage);
static bool allDone(const JsonWizard *wizard, JsonWizard::GeneratorFiles *files, QString *errorMessage);
};