forked from qt-creator/qt-creator
JsonWizard: Make TargetSetupPage available to JsonWizards
Change-Id: I59cf128635c28f5cbc45336bef82f63ee5da4e6c Reviewed-by: Daniel Teske <daniel.teske@digia.com>
This commit is contained in:
116
src/plugins/projectexplorer/jsonwizard/jsonkitspage.cpp
Normal file
116
src/plugins/projectexplorer/jsonwizard/jsonkitspage.cpp
Normal file
@@ -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 <coreplugin/featureprovider.h>
|
||||||
|
#include <coreplugin/mimedatabase.h>
|
||||||
|
|
||||||
|
#include <extensionsystem/pluginmanager.h>
|
||||||
|
|
||||||
|
#include <utils/macroexpander.h>
|
||||||
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
|
namespace ProjectExplorer {
|
||||||
|
|
||||||
|
JsonKitsPage::JsonKitsPage(QWidget *parent) : TargetSetupPage(parent)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
void ProjectExplorer::JsonKitsPage::initializePage()
|
||||||
|
{
|
||||||
|
JsonWizard *wiz = qobject_cast<JsonWizard *>(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<JsonWizard *>(wizard());
|
||||||
|
QTC_ASSERT(wiz, return);
|
||||||
|
|
||||||
|
disconnect(wiz, &JsonWizard::filesReady, this, 0);
|
||||||
|
|
||||||
|
TargetSetupPage::cleanupPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
void JsonKitsPage::setupProjectFiles(const JsonWizard::GeneratorFiles &files)
|
||||||
|
{
|
||||||
|
Project *project = 0;
|
||||||
|
QList<IProjectManager *> managerList = ExtensionSystem::PluginManager::getObjects<IProjectManager>();
|
||||||
|
|
||||||
|
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
|
60
src/plugins/projectexplorer/jsonwizard/jsonkitspage.h
Normal file
60
src/plugins/projectexplorer/jsonwizard/jsonkitspage.h
Normal file
@@ -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
|
@@ -1,5 +1,6 @@
|
|||||||
HEADERS += $$PWD/jsonfieldpage.h \
|
HEADERS += $$PWD/jsonfieldpage.h \
|
||||||
$$PWD/jsonfilepage.h \
|
$$PWD/jsonfilepage.h \
|
||||||
|
$$PWD/jsonkitspage.h \
|
||||||
$$PWD/jsonprojectpage.h \
|
$$PWD/jsonprojectpage.h \
|
||||||
$$PWD/jsonsummarypage.h \
|
$$PWD/jsonsummarypage.h \
|
||||||
$$PWD/jsonwizard.h \
|
$$PWD/jsonwizard.h \
|
||||||
@@ -11,6 +12,7 @@ HEADERS += $$PWD/jsonfieldpage.h \
|
|||||||
|
|
||||||
SOURCES += $$PWD/jsonfieldpage.cpp \
|
SOURCES += $$PWD/jsonfieldpage.cpp \
|
||||||
$$PWD/jsonfilepage.cpp \
|
$$PWD/jsonfilepage.cpp \
|
||||||
|
$$PWD/jsonkitspage.cpp \
|
||||||
$$PWD/jsonprojectpage.cpp \
|
$$PWD/jsonprojectpage.cpp \
|
||||||
$$PWD/jsonsummarypage.cpp \
|
$$PWD/jsonsummarypage.cpp \
|
||||||
$$PWD/jsonwizard.cpp \
|
$$PWD/jsonwizard.cpp \
|
||||||
|
@@ -32,6 +32,7 @@
|
|||||||
|
|
||||||
#include "jsonfieldpage.h"
|
#include "jsonfieldpage.h"
|
||||||
#include "jsonfilepage.h"
|
#include "jsonfilepage.h"
|
||||||
|
#include "jsonkitspage.h"
|
||||||
#include "jsonprojectpage.h"
|
#include "jsonprojectpage.h"
|
||||||
#include "jsonsummarypage.h"
|
#include "jsonsummarypage.h"
|
||||||
#include "jsonwizardfactory.h"
|
#include "jsonwizardfactory.h"
|
||||||
@@ -123,6 +124,46 @@ bool FilePageFactory::validateData(Core::Id typeId, const QVariant &data, QStrin
|
|||||||
return true;
|
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:
|
// ProjectPageFactory:
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
|
@@ -54,6 +54,15 @@ public:
|
|||||||
bool validateData(Core::Id typeId, const QVariant &data, QString *errorMessage);
|
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
|
class ProjectPageFactory : public JsonWizardPageFactory
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@@ -448,6 +448,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
|
|||||||
// For JsonWizard:
|
// For JsonWizard:
|
||||||
JsonWizardFactory::registerPageFactory(new FieldPageFactory);
|
JsonWizardFactory::registerPageFactory(new FieldPageFactory);
|
||||||
JsonWizardFactory::registerPageFactory(new FilePageFactory);
|
JsonWizardFactory::registerPageFactory(new FilePageFactory);
|
||||||
|
JsonWizardFactory::registerPageFactory(new KitsPageFactory);
|
||||||
JsonWizardFactory::registerPageFactory(new ProjectPageFactory);
|
JsonWizardFactory::registerPageFactory(new ProjectPageFactory);
|
||||||
JsonWizardFactory::registerPageFactory(new SummaryPageFactory);
|
JsonWizardFactory::registerPageFactory(new SummaryPageFactory);
|
||||||
|
|
||||||
|
@@ -171,6 +171,7 @@ QtcPlugin {
|
|||||||
files: [
|
files: [
|
||||||
"jsonfieldpage.cpp", "jsonfieldpage.h",
|
"jsonfieldpage.cpp", "jsonfieldpage.h",
|
||||||
"jsonfilepage.cpp", "jsonfilepage.h",
|
"jsonfilepage.cpp", "jsonfilepage.h",
|
||||||
|
"jsonkitspage.cpp", "jsonkitspage.h",
|
||||||
"jsonprojectpage.cpp", "jsonprojectpage.h",
|
"jsonprojectpage.cpp", "jsonprojectpage.h",
|
||||||
"jsonsummarypage.cpp", "jsonsummarypage.h",
|
"jsonsummarypage.cpp", "jsonsummarypage.h",
|
||||||
"jsonwizard.cpp", "jsonwizard.h",
|
"jsonwizard.cpp", "jsonwizard.h",
|
||||||
|
@@ -144,7 +144,7 @@ public:
|
|||||||
using namespace Internal;
|
using namespace Internal;
|
||||||
|
|
||||||
TargetSetupPage::TargetSetupPage(QWidget *parent) :
|
TargetSetupPage::TargetSetupPage(QWidget *parent) :
|
||||||
QWizardPage(parent),
|
Utils::WizardPage(parent),
|
||||||
m_importer(0),
|
m_importer(0),
|
||||||
m_baseLayout(0),
|
m_baseLayout(0),
|
||||||
m_firstWidget(0),
|
m_firstWidget(0),
|
||||||
|
@@ -36,8 +36,9 @@
|
|||||||
#include "projectimporter.h"
|
#include "projectimporter.h"
|
||||||
#include "kitinformation.h"
|
#include "kitinformation.h"
|
||||||
|
|
||||||
|
#include <utils/wizardpage.h>
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QWizardPage>
|
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
|
|
||||||
QT_FORWARD_DECLARE_CLASS(QSpacerItem)
|
QT_FORWARD_DECLARE_CLASS(QSpacerItem)
|
||||||
@@ -57,7 +58,7 @@ class TargetSetupWidget;
|
|||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|
||||||
/// \internal
|
/// \internal
|
||||||
class PROJECTEXPLORER_EXPORT TargetSetupPage : public QWizardPage
|
class PROJECTEXPLORER_EXPORT TargetSetupPage : public Utils::WizardPage
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user