From 64bf3ef1d224021592292a76d808605a115bc325 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint <Friedemann.Kleint@nokia.com> Date: Wed, 17 Mar 2010 15:17:03 +0100 Subject: [PATCH] Custom wizards: Add option -customwizard-verbose. --- share/qtcreator/templates/wizards/README.txt | 3 ++ .../ProjectExplorer.pluginspec | 3 ++ .../customwizard/customwizard.cpp | 40 ++++++++++++----- .../customwizard/customwizard.h | 3 ++ .../customwizard/customwizardpage.cpp | 2 +- .../customwizard/customwizardparameters.cpp | 45 +++++++++---------- .../customwizard/customwizardparameters.h | 5 +-- .../projectexplorer/projectexplorer.cpp | 10 ++++- src/plugins/projectexplorer/projectexplorer.h | 1 + 9 files changed, 70 insertions(+), 42 deletions(-) diff --git a/share/qtcreator/templates/wizards/README.txt b/share/qtcreator/templates/wizards/README.txt index 891ad644062..695c1ef7e96 100644 --- a/share/qtcreator/templates/wizards/README.txt +++ b/share/qtcreator/templates/wizards/README.txt @@ -3,3 +3,6 @@ Qt Creator custom wizard are located in this directory. The subdirectories 'helloworld' and 'listmodel' are provided as examples. To see how they work in Qt Creator, rename the 'wizard_sample.xml' files to 'wizard.xml'. + +The command line option -customwizard-verbose can be used to obtain +verbose information while loading the custom wizards. diff --git a/src/plugins/projectexplorer/ProjectExplorer.pluginspec b/src/plugins/projectexplorer/ProjectExplorer.pluginspec index 772f357b4e1..a234f76671c 100644 --- a/src/plugins/projectexplorer/ProjectExplorer.pluginspec +++ b/src/plugins/projectexplorer/ProjectExplorer.pluginspec @@ -19,4 +19,7 @@ Alternatively, this plugin may be used under the terms of the GNU Lesser General <dependency name="Locator" version="1.3.82"/> <dependency name="TextEditor" version="1.3.82"/> </dependencyList> + <argumentList> + <argument name="-customwizard-verbose">Verbose loading of custom wizards</argument> + </argumentList> </plugin> diff --git a/src/plugins/projectexplorer/customwizard/customwizard.cpp b/src/plugins/projectexplorer/customwizard/customwizard.cpp index 7f36a7a450d..0a7e90edb30 100644 --- a/src/plugins/projectexplorer/customwizard/customwizard.cpp +++ b/src/plugins/projectexplorer/customwizard/customwizard.cpp @@ -44,8 +44,6 @@ #include <QtCore/QDir> #include <QtCore/QFileInfo> -enum { debug = 0 }; - static const char templatePathC[] = "templates/wizards"; static const char configFileC[] = "wizard.xml"; @@ -53,8 +51,11 @@ namespace ProjectExplorer { struct CustomWizardPrivate { QSharedPointer<Internal::CustomWizardParameters> m_parameters; + static int verbose; }; +int CustomWizardPrivate::verbose = 0; + CustomWizard::CustomWizard(const Core::BaseFileWizardParameters& baseFileParameters, QObject *parent) : Core::BaseFileWizard(baseFileParameters, parent), @@ -67,6 +68,16 @@ CustomWizard::~CustomWizard() delete d; } +void CustomWizard::setVerbose(int v) +{ + CustomWizardPrivate::verbose = v; +} + +int CustomWizard::verbose() +{ + return CustomWizardPrivate::verbose; +} + void CustomWizard::setParameters(const CustomWizardParametersPtr &p) { d->m_parameters = p; @@ -100,7 +111,7 @@ void CustomWizard::initWizardDialog(QWizard *wizard, const QString &defaultPath, foreach(QWizardPage *ep, extensionPages) wizard->addPage(ep); Core::BaseFileWizard::setupWizard(wizard); - if (debug) + if (CustomWizardPrivate::verbose) qDebug() << "initWizardDialog" << wizard << wizard->pageIds(); } @@ -177,7 +188,7 @@ static inline bool createFile(Internal::CustomWizardFile cwFile, const QString sourcePath = sourceDirectory + slash + cwFile.source; replaceFields(fm, &cwFile.target); const QString targetPath = QDir::toNativeSeparators(targetDirectory + slash + cwFile.target); - if (debug) + if (CustomWizardPrivate::verbose) qDebug() << "generating " << targetPath << sourcePath << fm; QFile file(sourcePath); if (!file.open(QIODevice::ReadOnly|QIODevice::Text)) { @@ -211,7 +222,7 @@ Core::GeneratedFiles CustomWizard::generateFiles(const QWizard *dialog, QString QTC_ASSERT(cwp, return Core::GeneratedFiles()) QString path = cwp->path(); const FieldReplacementMap fieldMap = defaultReplacementMap(dialog); - if (debug) + if (CustomWizardPrivate::verbose) qDebug() << "CustomWizard::generateFiles" << dialog << path << fieldMap; return generateWizardFiles(path, fieldMap, errorMessage); } @@ -220,7 +231,7 @@ Core::GeneratedFiles CustomWizard::generateWizardFiles(const QString &targetPath const FieldReplacementMap &fieldReplacementMap, QString *errorMessage) const { - if (debug) + if (CustomWizardPrivate::verbose) qDebug() << "Replacements" << fieldReplacementMap; // Create files Core::GeneratedFiles rc; @@ -299,7 +310,7 @@ QList<CustomWizard*> CustomWizard::createWizards() QLatin1Char('/') + QLatin1String(templatePathC); const QDir templateDir(templateDirName); if (!templateDir.exists()) { - if (debug) + if (CustomWizardPrivate::verbose) qWarning("Custom project template path %s does not exist.", qPrintable(templateDir.absolutePath())); return rc; } @@ -311,19 +322,24 @@ QList<CustomWizard*> CustomWizard::createWizards() foreach(const QFileInfo &dirFi, dirs) { const QDir dir(dirFi.absoluteFilePath()); + if (CustomWizardPrivate::verbose) + qDebug("CustomWizard: Scanning %s", qPrintable(dirFi.absoluteFilePath())); if (dir.exists(configFile)) { CustomWizardParametersPtr parameters(new Internal::CustomWizardParameters); Core::BaseFileWizardParameters baseFileParameters; if (parameters->parse(dir.absoluteFilePath(configFile), &baseFileParameters, &errorMessage)) { parameters->directory = dir.absolutePath(); - if (debug) - qDebug() << (*parameters); + if (CustomWizardPrivate::verbose) + qDebug("%s\n", qPrintable(parameters->toString())); if (CustomWizard *w = createWizard(parameters, baseFileParameters)) rc.push_back(w); } else { qWarning("Failed to initialize custom project wizard in %s: %s", qPrintable(dir.absolutePath()), qPrintable(errorMessage)); } + } else { + if (CustomWizardPrivate::verbose) + qDebug("CustomWizard: '%s' not found\n", qPrintable(configFile)); } } return rc; @@ -362,7 +378,7 @@ void CustomProjectWizard::initProjectWizardDialog(BaseProjectWizardDialog *w, w->addPage(ep); w->setPath(defaultPath); w->setProjectName(BaseProjectWizardDialog::uniqueProjectName(defaultPath)); - if (debug) + if (CustomWizardPrivate::verbose) qDebug() << "initProjectWizardDialog" << w << w->pageIds(); } @@ -374,7 +390,7 @@ Core::GeneratedFiles CustomProjectWizard::generateFiles(const QWizard *w, QStrin // Add project name as macro. FieldReplacementMap fieldReplacementMap = defaultReplacementMap(dialog); fieldReplacementMap.insert(QLatin1String("ProjectName"), dialog->projectName()); - if (debug) + if (CustomWizardPrivate::verbose) qDebug() << "CustomProjectWizard::generateFiles" << dialog << targetPath << fieldReplacementMap; return generateWizardFiles(targetPath, fieldReplacementMap, errorMessage); } @@ -384,7 +400,7 @@ bool CustomProjectWizard::postGenerateFiles(const QWizard *, const Core::Generat // Post-Generate: Open the project const QString proFileName = l.back().path(); const bool opened = ProjectExplorer::ProjectExplorerPlugin::instance()->openProject(proFileName); - if (debug) + if (CustomWizardPrivate::verbose) qDebug() << "CustomProjectWizard::postGenerateFiles: opened " << proFileName << opened; if (opened) { *errorMessage = tr("The project %1 could not be opened.").arg(proFileName); diff --git a/src/plugins/projectexplorer/customwizard/customwizard.h b/src/plugins/projectexplorer/customwizard/customwizard.h index 2b14e404354..de910b04fe3 100644 --- a/src/plugins/projectexplorer/customwizard/customwizard.h +++ b/src/plugins/projectexplorer/customwizard/customwizard.h @@ -99,6 +99,9 @@ public: // classes, call it in extensionsInitialized(). static QList<CustomWizard*> createWizards(); + static void setVerbose(int); + static int verbose(); + protected: typedef QSharedPointer<Internal::CustomWizardParameters> CustomWizardParametersPtr; diff --git a/src/plugins/projectexplorer/customwizard/customwizardpage.cpp b/src/plugins/projectexplorer/customwizard/customwizardpage.cpp index 5c63f30717e..716b843c3a3 100644 --- a/src/plugins/projectexplorer/customwizard/customwizardpage.cpp +++ b/src/plugins/projectexplorer/customwizard/customwizardpage.cpp @@ -68,7 +68,7 @@ CustomWizardFieldPage::CustomWizardFieldPage(const FieldList &fields, m_formLayout(new QFormLayout) { if (debug) - qDebug() << Q_FUNC_INFO << fields; + qDebug() << Q_FUNC_INFO << fields.size(); foreach(const CustomWizardField &f, fields) addField(f); setLayout(m_formLayout); diff --git a/src/plugins/projectexplorer/customwizard/customwizardparameters.cpp b/src/plugins/projectexplorer/customwizard/customwizardparameters.cpp index bc9bcc2acbc..bf89b9fe902 100644 --- a/src/plugins/projectexplorer/customwizard/customwizardparameters.cpp +++ b/src/plugins/projectexplorer/customwizard/customwizardparameters.cpp @@ -442,30 +442,29 @@ bool CustomWizardParameters::parse(const QString &configFileFullPath, return parse(configFile, configFileFullPath, bp, errorMessage); } -QDebug operator<<(QDebug d, const CustomWizardField &m) +QString CustomWizardParameters::toString() const { - QDebug nsp = d.nospace(); - nsp << "Name: " << m.name; - if (m.mandatory) - nsp << '*'; - nsp << " Desc: " << m.description << " Control: " << m.controlAttributes; - return d; -} - -QDebug operator<<(QDebug d, const CustomWizardFile &f) -{ - d.nospace() << "source: " << f.source << " target: " << f.target; - return d; -} - -QDebug operator<<(QDebug d, const CustomWizardParameters &p) -{ - QDebug nsp = d.nospace(); - nsp << "Dir: " << p.directory << " klass:" << p.klass << " Files: " << p.files; - if (!p.fields.isEmpty()) - nsp << " Fields: " << p.fields; - nsp << "First page: " << p.firstPageId; - return d; + QString rc; + QTextStream str(&rc); + str << "Directory: " << directory << " Klass: '" << klass << "'\n"; + foreach(const CustomWizardFile &f, files) { + str << " File source: " << f.source << " Target: " << f.target << '\n'; + } + foreach(const CustomWizardField &f, fields) { + str << " Field name: " << f.name; + if (f.mandatory) + str << '*'; + str << " Description: '" << f.description << '\''; + if (!f.controlAttributes.isEmpty()) { + typedef CustomWizardField::ControlAttributeMap::const_iterator AttrMapConstIt; + str << " Control: "; + const AttrMapConstIt cend = f.controlAttributes.constEnd(); + for (AttrMapConstIt it = f.controlAttributes.constBegin(); it != cend; ++it) + str << '\'' << it.key() << "' -> '" << it.value() << "' "; + } + str << '\n'; + } + return rc; } } // namespace Internal diff --git a/src/plugins/projectexplorer/customwizard/customwizardparameters.h b/src/plugins/projectexplorer/customwizard/customwizardparameters.h index e526da0d0f1..3ee6a19b23d 100644 --- a/src/plugins/projectexplorer/customwizard/customwizardparameters.h +++ b/src/plugins/projectexplorer/customwizard/customwizardparameters.h @@ -69,6 +69,7 @@ public: Core::BaseFileWizardParameters *bp, QString *errorMessage); bool parse(const QString &configFileFullPath, Core::BaseFileWizardParameters *bp, QString *errorMessage); + QString toString() const; QString directory; QString klass; @@ -78,10 +79,6 @@ public: int firstPageId; }; -QDebug operator<<(QDebug d, const CustomWizardField &); -QDebug operator<<(QDebug d, const CustomWizardFile &); -QDebug operator<<(QDebug d, const CustomWizardParameters &); - } // namespace Internal } // namespace ProjectExplorer diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index 8ac706e4502..144f2b19484 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -226,10 +226,16 @@ ProjectExplorerPlugin *ProjectExplorerPlugin::instance() return m_instance; } +bool ProjectExplorerPlugin::parseArguments(const QStringList &arguments, QString * /* error */) +{ + CustomWizard::setVerbose(arguments.count(QLatin1String("-customwizard-verbose"))); + return true; +} + bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *error) { - Q_UNUSED(arguments) - Q_UNUSED(error) + if (!parseArguments(arguments, error)) + return false; Core::ICore *core = Core::ICore::instance(); Core::ActionManager *am = core->actionManager(); diff --git a/src/plugins/projectexplorer/projectexplorer.h b/src/plugins/projectexplorer/projectexplorer.h index bc4e7ff3512..43b541cd941 100644 --- a/src/plugins/projectexplorer/projectexplorer.h +++ b/src/plugins/projectexplorer/projectexplorer.h @@ -231,6 +231,7 @@ private slots: #endif private: + bool parseArguments(const QStringList &arguments, QString *error); void runProjectImpl(Project *pro, QString mode); void executeRunConfiguration(RunConfiguration *, const QString &mode); bool showBuildConfigDialog(); -- GitLab