OSDN Git Service

3144ad3246696934dfe363bb8927587071d8589c
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qmlprojectmanager / qmlprojecttarget.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
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
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
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.
24 **
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.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #include "qmlprojecttarget.h"
35
36 #include "qmlproject.h"
37 #include "qmlprojectmanagerconstants.h"
38 #include "qmlprojectrunconfiguration.h"
39
40 #include <QtCore/QDebug>
41 #include <QtGui/QApplication>
42 #include <QtGui/QStyle>
43
44 namespace QmlProjectManager {
45 namespace Internal {
46
47 QmlProjectTarget::QmlProjectTarget(QmlProject *parent) :
48     ProjectExplorer::Target(parent, QLatin1String(Constants::QML_VIEWER_TARGET_ID))
49 {
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));
54 }
55
56 QmlProjectTarget::~QmlProjectTarget()
57 {
58 }
59
60 ProjectExplorer::BuildConfigWidget *QmlProjectTarget::createConfigWidget()
61 {
62     return 0;
63 }
64
65 QmlProject *QmlProjectTarget::qmlProject() const
66 {
67     return static_cast<QmlProject *>(project());
68 }
69
70 ProjectExplorer::IBuildConfigurationFactory *QmlProjectTarget::buildConfigurationFactory(void) const
71 {
72     return 0;
73 }
74
75 ProjectExplorer::DeployConfigurationFactory *QmlProjectTarget::deployConfigurationFactory() const
76 {
77     return 0;
78 }
79
80 bool QmlProjectTarget::fromMap(const QVariantMap &map)
81 {
82     if (!Target::fromMap(map))
83         return false;
84
85     if (runConfigurations().isEmpty()) {
86         qWarning() << "Failed to restore run configuration of QML project!";
87         return false;
88     }
89
90     setDisplayName(QApplication::translate("QmlProjectManager::QmlTarget",
91                                            Constants::QML_VIEWER_TARGET_DISPLAY_NAME,
92                                            "QML Viewer target display name"));
93
94     return true;
95 }
96
97 QmlProjectTargetFactory::QmlProjectTargetFactory(QObject *parent) :
98     ITargetFactory(parent)
99 {
100 }
101
102 QmlProjectTargetFactory::~QmlProjectTargetFactory()
103 {
104 }
105
106 bool QmlProjectTargetFactory::supportsTargetId(const QString &id) const
107 {
108     return id == QLatin1String(Constants::QML_VIEWER_TARGET_ID);
109 }
110
111 QStringList QmlProjectTargetFactory::supportedTargetIds(ProjectExplorer::Project *parent) const
112 {
113     if (!qobject_cast<QmlProject *>(parent))
114         return QStringList();
115     return QStringList() << QLatin1String(Constants::QML_VIEWER_TARGET_ID);
116 }
117
118 QString QmlProjectTargetFactory::displayNameForId(const QString &id) const
119 {
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");
124     return QString();
125 }
126
127 bool QmlProjectTargetFactory::canCreate(ProjectExplorer::Project *parent, const QString &id) const
128 {
129     if (!qobject_cast<QmlProject *>(parent))
130         return false;
131     return id == QLatin1String(Constants::QML_VIEWER_TARGET_ID);
132 }
133
134 QmlProjectTarget *QmlProjectTargetFactory::create(ProjectExplorer::Project *parent, const QString &id)
135 {
136     if (!canCreate(parent, id))
137         return 0;
138     QmlProject *qmlproject(static_cast<QmlProject *>(parent));
139     QmlProjectTarget *target = new QmlProjectTarget(qmlproject);
140
141     // Add RunConfiguration (QML does not have BuildConfigurations)
142     QmlProjectRunConfiguration *runConf = new QmlProjectRunConfiguration(target);
143     target->addRunConfiguration(runConf);
144
145     return target;
146 }
147
148 bool QmlProjectTargetFactory::canRestore(ProjectExplorer::Project *parent, const QVariantMap &map) const
149 {
150     return canCreate(parent, ProjectExplorer::idFromMap(map));
151 }
152
153 QmlProjectTarget *QmlProjectTargetFactory::restore(ProjectExplorer::Project *parent, const QVariantMap &map)
154 {
155     if (!canRestore(parent, map))
156         return 0;
157     QmlProject *qmlproject(static_cast<QmlProject *>(parent));
158     QmlProjectTarget *target(new QmlProjectTarget(qmlproject));
159     if (target->fromMap(map))
160         return target;
161     delete target;
162     return 0;
163 }
164
165 } // namespace Internal
166 } // namespace QmlProjectManager