qmlprojectrunconfigurationfactory.cpp 5.72 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
Kai Koehne's avatar
Kai Koehne committed
2
**
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
Kai Koehne's avatar
Kai Koehne committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
Kai Koehne's avatar
Kai Koehne committed
7
**
hjk's avatar
hjk committed
8 9 10 11 12 13 14
** 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.
Kai Koehne's avatar
Kai Koehne committed
15 16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17 18 19 20 21 22 23 24 25
** 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
con's avatar
con committed
26 27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
Kai Koehne's avatar
Kai Koehne committed
29

30
#include "qmlprojectrunconfigurationfactory.h"
Kai Koehne's avatar
Kai Koehne committed
31
#include "qmlprojectmanagerconstants.h"
Tobias Hunger's avatar
Tobias Hunger committed
32
#include "qmlproject.h"
Kai Koehne's avatar
Kai Koehne committed
33 34
#include "qmlprojectrunconfiguration.h"

Tobias Hunger's avatar
Tobias Hunger committed
35
#include <projectexplorer/kitinformation.h>
Kai Koehne's avatar
Kai Koehne committed
36 37
#include <projectexplorer/projectconfiguration.h>
#include <projectexplorer/runconfiguration.h>
Tobias Hunger's avatar
Tobias Hunger committed
38
#include <projectexplorer/target.h>
Tobias Hunger's avatar
Tobias Hunger committed
39
#include <qtsupport/qtkitinformation.h>
Kai Koehne's avatar
Kai Koehne committed
40 41 42 43 44 45

namespace QmlProjectManager {
namespace Internal {

QmlProjectRunConfigurationFactory::QmlProjectRunConfigurationFactory(QObject *parent) :
    ProjectExplorer::IRunConfigurationFactory(parent)
46 47 48
{
    setObjectName(QLatin1String("QmlProjectRunConfigurationFactory"));
}
Kai Koehne's avatar
Kai Koehne committed
49 50 51 52 53

QmlProjectRunConfigurationFactory::~QmlProjectRunConfigurationFactory()
{
}

54
QList<Core::Id> QmlProjectRunConfigurationFactory::availableCreationIds(ProjectExplorer::Target *parent) const
Kai Koehne's avatar
Kai Koehne committed
55
{
Tobias Hunger's avatar
Tobias Hunger committed
56
    if (!canHandle(parent))
57
        return QList<Core::Id>();
58 59

    QtSupport::BaseQtVersion *version
Tobias Hunger's avatar
Tobias Hunger committed
60
            = QtSupport::QtKitInformation::qtVersion(parent->kit());
61

62
    // First id will be the default run configuration
63
    QList<Core::Id> list;
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
    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);
    }
82 83

    return list;
Kai Koehne's avatar
Kai Koehne committed
84 85
}

86
QString QmlProjectRunConfigurationFactory::displayNameForId(const Core::Id id) const
Kai Koehne's avatar
Kai Koehne committed
87
{
88 89 90 91
    if (id == Constants::QML_VIEWER_RC_ID)
        return tr("QML Viewer");
    if (id == Constants::QML_SCENE_RC_ID)
        return tr("QML Scene");
Kai Koehne's avatar
Kai Koehne committed
92 93 94
    return QString();
}

95 96
bool QmlProjectRunConfigurationFactory::canCreate(ProjectExplorer::Target *parent,
                                                  const Core::Id id) const
Kai Koehne's avatar
Kai Koehne committed
97
{
Tobias Hunger's avatar
Tobias Hunger committed
98
    if (!canHandle(parent))
Kai Koehne's avatar
Kai Koehne committed
99
        return false;
100 101 102 103 104 105 106

    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
Tobias Hunger's avatar
Tobias Hunger committed
107
                = QtSupport::QtKitInformation::qtVersion(parent->kit());
108 109 110
        return version && version->qtVersion() >= QtSupport::QtVersionNumber(5, 0, 0);
    }
    return false;
Kai Koehne's avatar
Kai Koehne committed
111 112
}

113
ProjectExplorer::RunConfiguration *QmlProjectRunConfigurationFactory::doCreate(ProjectExplorer::Target *parent, const Core::Id id)
Kai Koehne's avatar
Kai Koehne committed
114
{
115
    return new QmlProjectRunConfiguration(parent, id);
Kai Koehne's avatar
Kai Koehne committed
116 117 118 119
}

bool QmlProjectRunConfigurationFactory::canRestore(ProjectExplorer::Target *parent, const QVariantMap &map) const
{
120
    return parent && canCreate(parent, ProjectExplorer::idFromMap(map));
Kai Koehne's avatar
Kai Koehne committed
121 122
}

123 124
ProjectExplorer::RunConfiguration *QmlProjectRunConfigurationFactory::doRestore(ProjectExplorer::Target *parent,
                                                                                const QVariantMap &map)
Kai Koehne's avatar
Kai Koehne committed
125
{
126
    return new QmlProjectRunConfiguration(parent, ProjectExplorer::idFromMap(map));
Kai Koehne's avatar
Kai Koehne committed
127 128 129 130 131 132 133 134 135 136 137 138
}

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;
Tobias Hunger's avatar
Tobias Hunger committed
139 140 141 142 143
    return new QmlProjectRunConfiguration(parent, qobject_cast<QmlProjectRunConfiguration *>(source));
}

bool QmlProjectRunConfigurationFactory::canHandle(ProjectExplorer::Target *parent) const
{
Tobias Hunger's avatar
Tobias Hunger committed
144
    if (!parent->project()->supportsKit(parent->kit()))
Tobias Hunger's avatar
Tobias Hunger committed
145 146 147
        return false;
    if (!qobject_cast<QmlProject *>(parent->project()))
        return false;
Tobias Hunger's avatar
Tobias Hunger committed
148
    Core::Id deviceType = ProjectExplorer::DeviceTypeKitInformation::deviceTypeId(parent->kit());
149
    return deviceType == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE;
Kai Koehne's avatar
Kai Koehne committed
150 151 152 153 154
}

} // namespace Internal
} // namespace QmlProjectManager