From 3cb4f6dbf383a337df850c91d858b51cdea8e53e Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Wed, 15 Oct 2014 15:09:11 +0200 Subject: JsonWizard: Make TargetSetupPage available to JsonWizards Change-Id: I59cf128635c28f5cbc45336bef82f63ee5da4e6c Reviewed-by: Daniel Teske --- .../projectexplorer/jsonwizard/jsonkitspage.cpp | 116 +++++++++++++++++++++ .../projectexplorer/jsonwizard/jsonkitspage.h | 60 +++++++++++ .../projectexplorer/jsonwizard/jsonwizard.pri | 2 + .../jsonwizard/jsonwizardpagefactory_p.cpp | 41 ++++++++ .../jsonwizard/jsonwizardpagefactory_p.h | 9 ++ src/plugins/projectexplorer/projectexplorer.cpp | 1 + src/plugins/projectexplorer/projectexplorer.qbs | 1 + src/plugins/projectexplorer/targetsetuppage.cpp | 2 +- src/plugins/projectexplorer/targetsetuppage.h | 5 +- 9 files changed, 234 insertions(+), 3 deletions(-) create mode 100644 src/plugins/projectexplorer/jsonwizard/jsonkitspage.cpp create mode 100644 src/plugins/projectexplorer/jsonwizard/jsonkitspage.h diff --git a/src/plugins/projectexplorer/jsonwizard/jsonkitspage.cpp b/src/plugins/projectexplorer/jsonwizard/jsonkitspage.cpp new file mode 100644 index 0000000000..1afca62ed9 --- /dev/null +++ b/src/plugins/projectexplorer/jsonwizard/jsonkitspage.cpp @@ -0,0 +1,116 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "jsonkitspage.h" +#include "jsonwizard.h" + +#include "../iprojectmanager.h" +#include "../kit.h" +#include "../project.h" +#include "../projectexplorer.h" + +#include +#include + +#include + +#include +#include + +namespace ProjectExplorer { + +JsonKitsPage::JsonKitsPage(QWidget *parent) : TargetSetupPage(parent) +{ } + +void ProjectExplorer::JsonKitsPage::initializePage() +{ + JsonWizard *wiz = qobject_cast(wizard()); + QTC_ASSERT(wiz, return); + + connect(wiz, &JsonWizard::filesReady, this, &JsonKitsPage::setupProjectFiles); + + const QString platform = wiz->value(QLatin1String("Platform")).toString(); + const Core::FeatureSet preferred = Core::FeatureSet::fromStringList(wiz->value(QLatin1String("PreferredFeatures")).toStringList()); + const Core::FeatureSet required = Core::FeatureSet::fromStringList(wiz->value(QLatin1String("RequiredFeatures")).toStringList()); + const QString path = Utils::expandMacros(m_projectFilePath, wiz->expander()); + + setProjectPath(path); + + setRequiredKitMatcher(KitMatcher([required](const Kit *k) { return k->hasFeatures(required); })); + setPreferredKitMatcher(KitMatcher([platform, preferred](const Kit *k) { return k->hasPlatform(platform) && k->hasFeatures(preferred); })); + + TargetSetupPage::initializePage(); +} + +void JsonKitsPage::cleanupPage() +{ + JsonWizard *wiz = qobject_cast(wizard()); + QTC_ASSERT(wiz, return); + + disconnect(wiz, &JsonWizard::filesReady, this, 0); + + TargetSetupPage::cleanupPage(); +} + +void JsonKitsPage::setupProjectFiles(const JsonWizard::GeneratorFiles &files) +{ + Project *project = 0; + QList managerList = ExtensionSystem::PluginManager::getObjects(); + + foreach (const JsonWizard::GeneratorFile &f, files) { + if (f.file.attributes() & Core::GeneratedFile::OpenProjectAttribute) { + QString errorMessage; + QString path = f.file.path(); + const QFileInfo fi(path); + + if (fi.exists()) + path = fi.canonicalFilePath(); + + Core::MimeType mt = Core::MimeDatabase::findByFile(fi); + if (mt.isNull()) + continue; + + foreach (IProjectManager *manager, managerList) { + if (manager->mimeType() == mt.type()) { + project = manager->openProject(path, &errorMessage); + break; + } + } + + if (project) { + bool success = setupProject(project); + if (success) + project->saveSettings(); + delete project; + } + } + } +} + +} // namespace ProjectExplorer diff --git a/src/plugins/projectexplorer/jsonwizard/jsonkitspage.h b/src/plugins/projectexplorer/jsonwizard/jsonkitspage.h new file mode 100644 index 0000000000..1e530cbe7a --- /dev/null +++ b/src/plugins/projectexplorer/jsonwizard/jsonkitspage.h @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef JSONKITSPAGE_H +#define JSONKITSPAGE_H + +#include "jsonwizard.h" +#include "../targetsetuppage.h" + +namespace ProjectExplorer { + +// Documentation inside. +class JsonKitsPage : public TargetSetupPage +{ + Q_OBJECT + +public: + JsonKitsPage(QWidget *parent = 0); + + void setProjectFilePath(const QString &path) { m_projectFilePath = path; } + + void initializePage(); + void cleanupPage(); + +private slots: + void setupProjectFiles(const JsonWizard::GeneratorFiles &files); + +private: + QString m_projectFilePath; +}; + +} // namespace ProjectExplorer + +#endif // JSONKITSPAGE_H diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizard.pri b/src/plugins/projectexplorer/jsonwizard/jsonwizard.pri index 69d53e9e37..b9d7fe5136 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonwizard.pri +++ b/src/plugins/projectexplorer/jsonwizard/jsonwizard.pri @@ -1,5 +1,6 @@ HEADERS += $$PWD/jsonfieldpage.h \ $$PWD/jsonfilepage.h \ + $$PWD/jsonkitspage.h \ $$PWD/jsonprojectpage.h \ $$PWD/jsonsummarypage.h \ $$PWD/jsonwizard.h \ @@ -11,6 +12,7 @@ HEADERS += $$PWD/jsonfieldpage.h \ SOURCES += $$PWD/jsonfieldpage.cpp \ $$PWD/jsonfilepage.cpp \ + $$PWD/jsonkitspage.cpp \ $$PWD/jsonprojectpage.cpp \ $$PWD/jsonsummarypage.cpp \ $$PWD/jsonwizard.cpp \ diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizardpagefactory_p.cpp b/src/plugins/projectexplorer/jsonwizard/jsonwizardpagefactory_p.cpp index 8499a10cf0..fd3c0d4f49 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonwizardpagefactory_p.cpp +++ b/src/plugins/projectexplorer/jsonwizard/jsonwizardpagefactory_p.cpp @@ -32,6 +32,7 @@ #include "jsonfieldpage.h" #include "jsonfilepage.h" +#include "jsonkitspage.h" #include "jsonprojectpage.h" #include "jsonsummarypage.h" #include "jsonwizardfactory.h" @@ -123,6 +124,46 @@ bool FilePageFactory::validateData(Core::Id typeId, const QVariant &data, QStrin return true; } +// -------------------------------------------------------------------- +// KitsPageFactory: +// -------------------------------------------------------------------- + +KitsPageFactory::KitsPageFactory() +{ + setTypeIdsSuffix(QLatin1String("Kits")); +} + +Utils::WizardPage *KitsPageFactory::create(JsonWizard *wizard, Core::Id typeId, const QVariant &data) +{ + Q_UNUSED(wizard); + QTC_ASSERT(canCreate(typeId), return 0); + + JsonKitsPage *page = new JsonKitsPage; + page->setProjectFilePath(data.toMap().value(QLatin1String("projectFilePath")).toString()); + + return page; +} + +bool KitsPageFactory::validateData(Core::Id typeId, const QVariant &data, QString *errorMessage) +{ + QTC_ASSERT(canCreate(typeId), return false); + + if (data.isNull() || data.type() != QVariant::Map) { + *errorMessage = QCoreApplication::translate("ProjectExplorer::JsonWizard", + "\"data\" must be a JSON object for \"Kits\" pages."); + return false; + } + + QVariantMap tmp = data.toMap(); + if (tmp.value(QLatin1String("projectFilePath")).toString().isEmpty()) { + *errorMessage = QCoreApplication::translate("ProjectExplorer::JsonWizard", + "\"Kits\" page requires a \"projectFilePath\" set."); + return false; + } + + return true; +} + // -------------------------------------------------------------------- // ProjectPageFactory: // -------------------------------------------------------------------- diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizardpagefactory_p.h b/src/plugins/projectexplorer/jsonwizard/jsonwizardpagefactory_p.h index ce134be731..7cbba7a261 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonwizardpagefactory_p.h +++ b/src/plugins/projectexplorer/jsonwizard/jsonwizardpagefactory_p.h @@ -54,6 +54,15 @@ public: bool validateData(Core::Id typeId, const QVariant &data, QString *errorMessage); }; +class KitsPageFactory : public JsonWizardPageFactory +{ +public: + KitsPageFactory(); + + Utils::WizardPage *create(JsonWizard *wizard, Core::Id typeId, const QVariant &data); + bool validateData(Core::Id typeId, const QVariant &data, QString *errorMessage); +}; + class ProjectPageFactory : public JsonWizardPageFactory { public: diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index 7bf11e8a72..3ba5df6426 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -448,6 +448,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er // For JsonWizard: JsonWizardFactory::registerPageFactory(new FieldPageFactory); JsonWizardFactory::registerPageFactory(new FilePageFactory); + JsonWizardFactory::registerPageFactory(new KitsPageFactory); JsonWizardFactory::registerPageFactory(new ProjectPageFactory); JsonWizardFactory::registerPageFactory(new SummaryPageFactory); diff --git a/src/plugins/projectexplorer/projectexplorer.qbs b/src/plugins/projectexplorer/projectexplorer.qbs index 4a145e57c9..887fa0bfa8 100644 --- a/src/plugins/projectexplorer/projectexplorer.qbs +++ b/src/plugins/projectexplorer/projectexplorer.qbs @@ -171,6 +171,7 @@ QtcPlugin { files: [ "jsonfieldpage.cpp", "jsonfieldpage.h", "jsonfilepage.cpp", "jsonfilepage.h", + "jsonkitspage.cpp", "jsonkitspage.h", "jsonprojectpage.cpp", "jsonprojectpage.h", "jsonsummarypage.cpp", "jsonsummarypage.h", "jsonwizard.cpp", "jsonwizard.h", diff --git a/src/plugins/projectexplorer/targetsetuppage.cpp b/src/plugins/projectexplorer/targetsetuppage.cpp index 47d8f941c0..56738f7aeb 100644 --- a/src/plugins/projectexplorer/targetsetuppage.cpp +++ b/src/plugins/projectexplorer/targetsetuppage.cpp @@ -144,7 +144,7 @@ public: using namespace Internal; TargetSetupPage::TargetSetupPage(QWidget *parent) : - QWizardPage(parent), + Utils::WizardPage(parent), m_importer(0), m_baseLayout(0), m_firstWidget(0), diff --git a/src/plugins/projectexplorer/targetsetuppage.h b/src/plugins/projectexplorer/targetsetuppage.h index 545cf646c0..4b06fea50b 100644 --- a/src/plugins/projectexplorer/targetsetuppage.h +++ b/src/plugins/projectexplorer/targetsetuppage.h @@ -36,8 +36,9 @@ #include "projectimporter.h" #include "kitinformation.h" +#include + #include -#include #include QT_FORWARD_DECLARE_CLASS(QSpacerItem) @@ -57,7 +58,7 @@ class TargetSetupWidget; } // namespace Internal /// \internal -class PROJECTEXPLORER_EXPORT TargetSetupPage : public QWizardPage +class PROJECTEXPLORER_EXPORT TargetSetupPage : public Utils::WizardPage { Q_OBJECT -- cgit v1.2.3