1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include "qmlprojecttarget.h"
36 #include "qmlproject.h"
37 #include "qmlprojectmanagerconstants.h"
38 #include "qmlprojectrunconfiguration.h"
40 #include <QtCore/QDebug>
41 #include <QtGui/QApplication>
42 #include <QtGui/QStyle>
44 namespace QmlProjectManager {
47 QmlProjectTarget::QmlProjectTarget(QmlProject *parent) :
48 ProjectExplorer::Target(parent, QLatin1String(Constants::QML_VIEWER_TARGET_ID))
50 setDisplayName(QApplication::translate("QmlProjectManager::QmlTarget",
51 Constants::QML_VIEWER_TARGET_DISPLAY_NAME,
52 "QML Viewer target display name"));
53 setIcon(qApp->style()->standardIcon(QStyle::SP_ComputerIcon));
56 QmlProjectTarget::~QmlProjectTarget()
60 ProjectExplorer::BuildConfigWidget *QmlProjectTarget::createConfigWidget()
65 QmlProject *QmlProjectTarget::qmlProject() const
67 return static_cast<QmlProject *>(project());
70 ProjectExplorer::IBuildConfigurationFactory *QmlProjectTarget::buildConfigurationFactory(void) const
75 ProjectExplorer::DeployConfigurationFactory *QmlProjectTarget::deployConfigurationFactory() const
80 bool QmlProjectTarget::fromMap(const QVariantMap &map)
82 if (!Target::fromMap(map))
85 if (runConfigurations().isEmpty()) {
86 qWarning() << "Failed to restore run configuration of QML project!";
90 setDisplayName(QApplication::translate("QmlProjectManager::QmlTarget",
91 Constants::QML_VIEWER_TARGET_DISPLAY_NAME,
92 "QML Viewer target display name"));
97 QmlProjectTargetFactory::QmlProjectTargetFactory(QObject *parent) :
98 ITargetFactory(parent)
102 QmlProjectTargetFactory::~QmlProjectTargetFactory()
106 bool QmlProjectTargetFactory::supportsTargetId(const QString &id) const
108 return id == QLatin1String(Constants::QML_VIEWER_TARGET_ID);
111 QStringList QmlProjectTargetFactory::supportedTargetIds(ProjectExplorer::Project *parent) const
113 if (!qobject_cast<QmlProject *>(parent))
114 return QStringList();
115 return QStringList() << QLatin1String(Constants::QML_VIEWER_TARGET_ID);
118 QString QmlProjectTargetFactory::displayNameForId(const QString &id) const
120 if (id == QLatin1String(Constants::QML_VIEWER_TARGET_ID))
121 return QCoreApplication::translate("QmlProjectManager::QmlTarget",
122 Constants::QML_VIEWER_TARGET_DISPLAY_NAME,
123 "QML Viewer target display name");
127 bool QmlProjectTargetFactory::canCreate(ProjectExplorer::Project *parent, const QString &id) const
129 if (!qobject_cast<QmlProject *>(parent))
131 return id == QLatin1String(Constants::QML_VIEWER_TARGET_ID);
134 QmlProjectTarget *QmlProjectTargetFactory::create(ProjectExplorer::Project *parent, const QString &id)
136 if (!canCreate(parent, id))
138 QmlProject *qmlproject(static_cast<QmlProject *>(parent));
139 QmlProjectTarget *target = new QmlProjectTarget(qmlproject);
141 // Add RunConfiguration (QML does not have BuildConfigurations)
142 QmlProjectRunConfiguration *runConf = new QmlProjectRunConfiguration(target);
143 target->addRunConfiguration(runConf);
148 bool QmlProjectTargetFactory::canRestore(ProjectExplorer::Project *parent, const QVariantMap &map) const
150 return canCreate(parent, ProjectExplorer::idFromMap(map));
153 QmlProjectTarget *QmlProjectTargetFactory::restore(ProjectExplorer::Project *parent, const QVariantMap &map)
155 if (!canRestore(parent, map))
157 QmlProject *qmlproject(static_cast<QmlProject *>(parent));
158 QmlProjectTarget *target(new QmlProjectTarget(qmlproject));
159 if (target->fromMap(map))
165 } // namespace Internal
166 } // namespace QmlProjectManager