2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-02-16 13:39:13 +01:00
|
|
|
**
|
2013-01-28 17:12:19 +01:00
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2010-02-16 13:39:13 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-02-16 13:39:13 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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.
|
2010-02-16 13:39:13 +01:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-02-16 13:39:13 +01:00
|
|
|
|
2013-03-12 12:16:49 +01:00
|
|
|
#include "qmlprojectrunconfigurationfactory.h"
|
2010-02-16 13:39:13 +01:00
|
|
|
#include "qmlprojectmanagerconstants.h"
|
2012-04-24 15:49:09 +02:00
|
|
|
#include "qmlproject.h"
|
2010-02-16 13:39:13 +01:00
|
|
|
#include "qmlprojectrunconfiguration.h"
|
|
|
|
|
|
2012-09-03 18:31:44 +02:00
|
|
|
#include <projectexplorer/kitinformation.h>
|
2010-02-16 13:39:13 +01:00
|
|
|
#include <projectexplorer/projectconfiguration.h>
|
|
|
|
|
#include <projectexplorer/runconfiguration.h>
|
2012-04-24 15:49:09 +02:00
|
|
|
#include <projectexplorer/target.h>
|
2012-09-03 18:31:44 +02:00
|
|
|
#include <qtsupport/qtkitinformation.h>
|
2010-02-16 13:39:13 +01:00
|
|
|
|
|
|
|
|
namespace QmlProjectManager {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
QmlProjectRunConfigurationFactory::QmlProjectRunConfigurationFactory(QObject *parent) :
|
|
|
|
|
ProjectExplorer::IRunConfigurationFactory(parent)
|
2012-08-03 15:24:33 +02:00
|
|
|
{
|
|
|
|
|
setObjectName(QLatin1String("QmlProjectRunConfigurationFactory"));
|
|
|
|
|
}
|
2010-02-16 13:39:13 +01:00
|
|
|
|
|
|
|
|
QmlProjectRunConfigurationFactory::~QmlProjectRunConfigurationFactory()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-15 17:17:40 +01:00
|
|
|
QList<Core::Id> QmlProjectRunConfigurationFactory::availableCreationIds(ProjectExplorer::Target *parent) const
|
2010-02-16 13:39:13 +01:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
if (!canHandle(parent))
|
2012-03-15 17:17:40 +01:00
|
|
|
return QList<Core::Id>();
|
2012-08-23 14:53:03 +02:00
|
|
|
|
|
|
|
|
QtSupport::BaseQtVersion *version
|
2012-09-03 18:31:44 +02:00
|
|
|
= QtSupport::QtKitInformation::qtVersion(parent->kit());
|
2012-08-23 14:53:03 +02:00
|
|
|
|
2013-01-21 13:54:20 +01:00
|
|
|
// First id will be the default run configuration
|
2012-08-23 14:53:03 +02:00
|
|
|
QList<Core::Id> list;
|
2013-01-21 13:54:20 +01:00
|
|
|
if (version && version->qtVersion() >= QtSupport::QtVersionNumber(5, 0, 0)) {
|
|
|
|
|
QmlProject *project = static_cast<QmlProject*>(parent->project());
|
|
|
|
|
switch (project->defaultImport()) {
|
|
|
|
|
case QmlProject::QtQuick1Import:
|
|
|
|
|
list << Core::Id(Constants::QML_VIEWER_RC_ID);
|
|
|
|
|
break;
|
|
|
|
|
case QmlProject::QtQuick2Import:
|
|
|
|
|
list << Core::Id(Constants::QML_SCENE_RC_ID);
|
|
|
|
|
break;
|
|
|
|
|
case QmlProject::UnknownImport:
|
|
|
|
|
default:
|
|
|
|
|
list << Core::Id(Constants::QML_SCENE_RC_ID);
|
|
|
|
|
list << Core::Id(Constants::QML_VIEWER_RC_ID);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
list << Core::Id(Constants::QML_VIEWER_RC_ID);
|
|
|
|
|
}
|
2012-08-23 14:53:03 +02:00
|
|
|
|
|
|
|
|
return list;
|
2010-02-16 13:39:13 +01:00
|
|
|
}
|
|
|
|
|
|
2012-03-15 17:17:40 +01:00
|
|
|
QString QmlProjectRunConfigurationFactory::displayNameForId(const Core::Id id) const
|
2010-02-16 13:39:13 +01:00
|
|
|
{
|
2012-08-23 14:53:03 +02:00
|
|
|
if (id == Constants::QML_VIEWER_RC_ID)
|
|
|
|
|
return tr("QML Viewer");
|
|
|
|
|
if (id == Constants::QML_SCENE_RC_ID)
|
|
|
|
|
return tr("QML Scene");
|
2010-02-16 13:39:13 +01:00
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-23 14:53:03 +02:00
|
|
|
bool QmlProjectRunConfigurationFactory::canCreate(ProjectExplorer::Target *parent,
|
|
|
|
|
const Core::Id id) const
|
2010-02-16 13:39:13 +01:00
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
if (!canHandle(parent))
|
2010-02-16 13:39:13 +01:00
|
|
|
return false;
|
2012-08-23 14:53:03 +02:00
|
|
|
|
|
|
|
|
if (id == Constants::QML_VIEWER_RC_ID)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (id == Constants::QML_SCENE_RC_ID) {
|
|
|
|
|
// only support qmlscene if it's Qt5
|
|
|
|
|
QtSupport::BaseQtVersion *version
|
2012-09-03 18:31:44 +02:00
|
|
|
= QtSupport::QtKitInformation::qtVersion(parent->kit());
|
2012-08-23 14:53:03 +02:00
|
|
|
return version && version->qtVersion() >= QtSupport::QtVersionNumber(5, 0, 0);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2010-02-16 13:39:13 +01:00
|
|
|
}
|
|
|
|
|
|
2012-03-15 17:17:40 +01:00
|
|
|
ProjectExplorer::RunConfiguration *QmlProjectRunConfigurationFactory::create(ProjectExplorer::Target *parent, const Core::Id id)
|
2010-02-16 13:39:13 +01:00
|
|
|
{
|
|
|
|
|
if (!canCreate(parent, id))
|
|
|
|
|
return 0;
|
2012-08-23 14:53:03 +02:00
|
|
|
return new QmlProjectRunConfiguration(parent, id);
|
2010-02-16 13:39:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool QmlProjectRunConfigurationFactory::canRestore(ProjectExplorer::Target *parent, const QVariantMap &map) const
|
|
|
|
|
{
|
2012-08-23 14:53:03 +02:00
|
|
|
return parent && canCreate(parent, ProjectExplorer::idFromMap(map));
|
2010-02-16 13:39:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProjectExplorer::RunConfiguration *QmlProjectRunConfigurationFactory::restore(ProjectExplorer::Target *parent, const QVariantMap &map)
|
|
|
|
|
{
|
|
|
|
|
if (!canRestore(parent, map))
|
|
|
|
|
return 0;
|
2012-08-23 14:53:03 +02:00
|
|
|
|
2012-08-23 16:32:49 +02:00
|
|
|
Core::Id id = ProjectExplorer::idFromMap(map);
|
2012-08-23 14:53:03 +02:00
|
|
|
QmlProjectRunConfiguration *rc = new QmlProjectRunConfiguration(parent, id);
|
2010-02-16 13:39:13 +01:00
|
|
|
if (rc->fromMap(map))
|
|
|
|
|
return rc;
|
|
|
|
|
delete rc;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool QmlProjectRunConfigurationFactory::canClone(ProjectExplorer::Target *parent, ProjectExplorer::RunConfiguration *source) const
|
|
|
|
|
{
|
|
|
|
|
return canCreate(parent, source->id());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProjectExplorer::RunConfiguration *QmlProjectRunConfigurationFactory::clone(ProjectExplorer::Target *parent,
|
|
|
|
|
ProjectExplorer::RunConfiguration *source)
|
|
|
|
|
{
|
|
|
|
|
if (!canClone(parent, source))
|
|
|
|
|
return 0;
|
2012-04-24 15:49:09 +02:00
|
|
|
return new QmlProjectRunConfiguration(parent, qobject_cast<QmlProjectRunConfiguration *>(source));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool QmlProjectRunConfigurationFactory::canHandle(ProjectExplorer::Target *parent) const
|
|
|
|
|
{
|
2012-09-03 18:31:44 +02:00
|
|
|
if (!parent->project()->supportsKit(parent->kit()))
|
2012-04-24 15:49:09 +02:00
|
|
|
return false;
|
|
|
|
|
if (!qobject_cast<QmlProject *>(parent->project()))
|
|
|
|
|
return false;
|
2012-09-03 18:31:44 +02:00
|
|
|
Core::Id deviceType = ProjectExplorer::DeviceTypeKitInformation::deviceTypeId(parent->kit());
|
2012-08-03 15:24:33 +02:00
|
|
|
return deviceType == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE;
|
2010-02-16 13:39:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace QmlProjectManager
|
|
|
|
|
|