2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2010-03-05 11:25:49 +01:00
|
|
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-06-17 00:01:27 +10:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Commercial Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Nokia.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01: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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** If you are unsure which license is appropriate for your use, please
|
2009-08-14 09:30:56 +02:00
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "project.h"
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
#include "editorconfiguration.h"
|
2009-09-29 11:39:55 +02:00
|
|
|
#include "environment.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "projectexplorer.h"
|
2010-09-09 17:00:26 +02:00
|
|
|
#include "projectexplorerconstants.h"
|
2010-02-08 15:50:06 +01:00
|
|
|
#include "projectnodes.h"
|
|
|
|
|
#include "target.h"
|
2010-01-19 16:59:18 +01:00
|
|
|
#include "userfileaccessor.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
#include <coreplugin/ifile.h>
|
|
|
|
|
#include <extensionsystem/pluginmanager.h>
|
2010-09-09 17:00:26 +02:00
|
|
|
#include <limits>
|
2008-12-09 15:25:01 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
using namespace ProjectExplorer;
|
2009-04-20 16:29:46 +02:00
|
|
|
using namespace ProjectExplorer::Internal;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-01-14 19:08:43 +01:00
|
|
|
namespace {
|
2010-02-08 15:50:06 +01:00
|
|
|
const char * const ACTIVE_TARGET_KEY("ProjectExplorer.Project.ActiveTarget");
|
|
|
|
|
const char * const TARGET_KEY_PREFIX("ProjectExplorer.Project.Target.");
|
|
|
|
|
const char * const TARGET_COUNT_KEY("ProjectExplorer.Project.TargetCount");
|
2010-01-19 16:33:44 +01:00
|
|
|
|
2010-01-14 16:24:21 +01:00
|
|
|
const char * const EDITOR_SETTINGS_KEY("ProjectExplorer.Project.EditorSettings");
|
2010-07-16 14:00:41 +02:00
|
|
|
|
2010-01-14 19:08:43 +01:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
// Project
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
Project::Project() :
|
2010-02-08 15:50:06 +01:00
|
|
|
m_activeTarget(0),
|
2010-01-14 19:08:43 +01:00
|
|
|
m_editorConfiguration(new EditorConfiguration())
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-16 16:30:22 +01:00
|
|
|
Project::~Project()
|
|
|
|
|
{
|
2010-02-08 15:50:06 +01:00
|
|
|
qDeleteAll(m_targets);
|
2009-01-16 16:30:22 +01:00
|
|
|
delete m_editorConfiguration;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
bool Project::hasActiveBuildSettings() const
|
|
|
|
|
{
|
|
|
|
|
return activeTarget() &&
|
|
|
|
|
activeTarget()->buildConfigurationFactory();
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-14 19:08:43 +01:00
|
|
|
QString Project::makeUnique(const QString &preferredName, const QStringList &usedNames)
|
2009-10-07 13:18:26 +02:00
|
|
|
{
|
2010-01-14 19:08:43 +01:00
|
|
|
if (!usedNames.contains(preferredName))
|
|
|
|
|
return preferredName;
|
2009-10-07 13:18:26 +02:00
|
|
|
int i = 2;
|
2010-01-14 19:08:43 +01:00
|
|
|
QString tryName = preferredName + QString::number(i);
|
2009-10-07 13:18:26 +02:00
|
|
|
while (usedNames.contains(tryName))
|
2010-01-14 19:08:43 +01:00
|
|
|
tryName = preferredName + QString::number(++i);
|
2009-10-07 13:18:26 +02:00
|
|
|
return tryName;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
QSet<QString> Project::supportedTargetIds() const
|
|
|
|
|
{
|
|
|
|
|
return m_supportedTargetIds;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QSet<QString> Project::possibleTargetIds() const
|
|
|
|
|
{
|
|
|
|
|
QSet<QString> result(m_supportedTargetIds);
|
|
|
|
|
foreach (ProjectExplorer::Target *t, targets())
|
|
|
|
|
result.remove(t->id());
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Project::canAddTarget(const QString &id) const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-02-08 15:50:06 +01:00
|
|
|
return possibleTargetIds().contains(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Project::setSupportedTargetIds(const QSet<QString> &ids)
|
|
|
|
|
{
|
|
|
|
|
if (ids == m_supportedTargetIds)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
m_supportedTargetIds = ids;
|
|
|
|
|
emit supportedTargetIdsChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Project::changeEnvironment()
|
|
|
|
|
{
|
|
|
|
|
Target *t(qobject_cast<Target *>(sender()));
|
|
|
|
|
if (t == activeTarget())
|
|
|
|
|
emit environmentChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Project::addTarget(Target *t)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(t && !m_targets.contains(t), return);
|
|
|
|
|
QTC_ASSERT(!target(t->id()), return);
|
|
|
|
|
Q_ASSERT(t->project() == this);
|
2010-01-15 10:54:29 +01:00
|
|
|
|
2009-09-24 16:02:02 +02:00
|
|
|
// Check that we don't have a configuration with the same displayName
|
2010-02-08 15:50:06 +01:00
|
|
|
QString targetDisplayName = t->displayName();
|
2009-09-24 16:02:02 +02:00
|
|
|
QStringList displayNames;
|
2010-02-08 15:50:06 +01:00
|
|
|
foreach (const Target *target, m_targets)
|
|
|
|
|
displayNames << target->displayName();
|
|
|
|
|
targetDisplayName = makeUnique(targetDisplayName, displayNames);
|
2010-08-19 12:26:21 +02:00
|
|
|
t->setDefaultDisplayName(targetDisplayName);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-09-24 16:02:02 +02:00
|
|
|
// add it
|
2010-02-08 15:50:06 +01:00
|
|
|
m_targets.push_back(t);
|
|
|
|
|
connect(t, SIGNAL(environmentChanged()),
|
|
|
|
|
SLOT(changeEnvironment()));
|
|
|
|
|
emit addedTarget(t);
|
|
|
|
|
|
|
|
|
|
// check activeTarget:
|
|
|
|
|
if (activeTarget() == 0)
|
|
|
|
|
setActiveTarget(t);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
void Project::removeTarget(Target *target)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-02-08 15:50:06 +01:00
|
|
|
QTC_ASSERT(target && m_targets.contains(target), return);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
emit aboutToRemoveTarget(target);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
m_targets.removeOne(target);
|
|
|
|
|
|
|
|
|
|
emit removedTarget(target);
|
|
|
|
|
if (target == activeTarget()) {
|
|
|
|
|
if (m_targets.isEmpty())
|
|
|
|
|
setActiveTarget(0);
|
|
|
|
|
else
|
|
|
|
|
setActiveTarget(m_targets.at(0));
|
|
|
|
|
}
|
|
|
|
|
delete target;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
QList<Target *> Project::targets() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-02-08 15:50:06 +01:00
|
|
|
return m_targets;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
Target *Project::activeTarget() const
|
2010-01-19 16:33:44 +01:00
|
|
|
{
|
2010-02-08 15:50:06 +01:00
|
|
|
return m_activeTarget;
|
2010-01-19 16:33:44 +01:00
|
|
|
}
|
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
void Project::setActiveTarget(Target *target)
|
2010-01-19 16:33:44 +01:00
|
|
|
{
|
2010-02-08 15:50:06 +01:00
|
|
|
if ((!target && !m_targets.isEmpty()) ||
|
|
|
|
|
(target && m_targets.contains(target) && m_activeTarget != target)) {
|
|
|
|
|
m_activeTarget = target;
|
|
|
|
|
emit activeTargetChanged(m_activeTarget);
|
|
|
|
|
emit environmentChanged();
|
|
|
|
|
}
|
2010-01-19 16:33:44 +01:00
|
|
|
}
|
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
Target *Project::target(const QString &id) const
|
2009-05-06 16:33:43 +02:00
|
|
|
{
|
2010-02-08 15:50:06 +01:00
|
|
|
foreach (Target * target, m_targets) {
|
|
|
|
|
if (target->id() == id)
|
|
|
|
|
return target;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2009-05-06 16:33:43 +02:00
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void Project::saveSettings()
|
|
|
|
|
{
|
2010-01-19 16:59:18 +01:00
|
|
|
UserFileAccessor accessor;
|
|
|
|
|
accessor.saveSettings(this, toMap());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-07-03 16:46:01 +02:00
|
|
|
bool Project::restoreSettings()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-01-19 16:59:18 +01:00
|
|
|
UserFileAccessor accessor;
|
|
|
|
|
QVariantMap map(accessor.restoreSettings(this));
|
2010-01-19 16:33:44 +01:00
|
|
|
return fromMap(map);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-08-06 15:31:32 +02:00
|
|
|
QList<BuildConfigWidget*> Project::subConfigWidgets()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-08-06 15:31:32 +02:00
|
|
|
return QList<BuildConfigWidget*>();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-01-19 16:33:44 +01:00
|
|
|
QVariantMap Project::toMap() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-02-08 15:50:06 +01:00
|
|
|
const QList<Target *> ts = targets();
|
2009-11-24 15:36:31 +01:00
|
|
|
|
2010-01-19 16:33:44 +01:00
|
|
|
QVariantMap map;
|
2010-02-08 15:50:06 +01:00
|
|
|
map.insert(QLatin1String(ACTIVE_TARGET_KEY), ts.indexOf(m_activeTarget));
|
|
|
|
|
map.insert(QLatin1String(TARGET_COUNT_KEY), ts.size());
|
|
|
|
|
for (int i = 0; i < ts.size(); ++i)
|
|
|
|
|
map.insert(QString::fromLatin1(TARGET_KEY_PREFIX) + QString::number(i), ts.at(i)->toMap());
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-01-19 16:33:44 +01:00
|
|
|
map.insert(QLatin1String(EDITOR_SETTINGS_KEY), m_editorConfiguration->toMap());
|
|
|
|
|
|
|
|
|
|
return map;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-25 13:19:27 +01:00
|
|
|
QString Project::projectDirectory() const
|
|
|
|
|
{
|
2010-06-08 14:19:05 +02:00
|
|
|
return projectDirectory(file()->fileName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString Project::projectDirectory(const QString &proFile)
|
|
|
|
|
{
|
2010-06-30 13:31:09 +02:00
|
|
|
if (proFile.isEmpty())
|
|
|
|
|
return QString();
|
2010-06-08 14:19:05 +02:00
|
|
|
QFileInfo info(proFile);
|
2010-03-25 13:19:27 +01:00
|
|
|
return info.absoluteDir().path();
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-08 14:19:05 +02:00
|
|
|
|
2010-01-19 16:33:44 +01:00
|
|
|
bool Project::fromMap(const QVariantMap &map)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-01-19 16:33:44 +01:00
|
|
|
if (map.contains(QLatin1String(EDITOR_SETTINGS_KEY))) {
|
|
|
|
|
QVariantMap values(map.value(QLatin1String(EDITOR_SETTINGS_KEY)).toMap());
|
2010-08-06 11:54:09 +02:00
|
|
|
m_editorConfiguration->fromMap(values);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-09-09 17:00:26 +02:00
|
|
|
int previousFileVersion = map.value(QLatin1String(Constants::USERFILE_PREVIOUS_VERSION_KEY),
|
|
|
|
|
std::numeric_limits<int>::max()).toInt();
|
|
|
|
|
|
2010-01-19 16:33:44 +01:00
|
|
|
bool ok;
|
2010-02-08 15:50:06 +01:00
|
|
|
int maxI(map.value(QLatin1String(TARGET_COUNT_KEY), 0).toInt(&ok));
|
2010-01-19 16:33:44 +01:00
|
|
|
if (!ok || maxI < 0)
|
|
|
|
|
maxI = 0;
|
2010-02-08 15:50:06 +01:00
|
|
|
int active(map.value(QLatin1String(ACTIVE_TARGET_KEY), 0).toInt(&ok));
|
|
|
|
|
if (!ok || active < 0)
|
|
|
|
|
active = 0;
|
|
|
|
|
if (0 > active || maxI < active)
|
|
|
|
|
active = 0;
|
2010-01-19 16:33:44 +01:00
|
|
|
|
|
|
|
|
for (int i = 0; i < maxI; ++i) {
|
2010-02-08 15:50:06 +01:00
|
|
|
const QString key(QString::fromLatin1(TARGET_KEY_PREFIX) + QString::number(i));
|
2010-02-18 18:37:11 +01:00
|
|
|
if (!map.contains(key)) {
|
|
|
|
|
qWarning() << key << "was not found in data.";
|
2010-01-19 16:33:44 +01:00
|
|
|
return false;
|
2010-02-18 18:37:11 +01:00
|
|
|
}
|
2010-09-09 17:00:26 +02:00
|
|
|
QVariantMap targetMap = map.value(key).toMap();
|
|
|
|
|
targetMap.insert(Constants::USERFILE_PREVIOUS_VERSION_KEY, previousFileVersion);
|
|
|
|
|
Target *t(targetFactory()->restore(this, targetMap));
|
2010-02-18 18:37:11 +01:00
|
|
|
if (!t) {
|
|
|
|
|
qWarning() << "Restoration of a target failed! (Continuing)";
|
2010-01-19 16:33:44 +01:00
|
|
|
continue;
|
2010-02-18 18:37:11 +01:00
|
|
|
}
|
2010-02-08 15:50:06 +01:00
|
|
|
addTarget(t);
|
|
|
|
|
if (i == active)
|
|
|
|
|
setActiveTarget(t);
|
2009-11-30 13:58:06 +01:00
|
|
|
}
|
2010-01-19 16:33:44 +01:00
|
|
|
return true;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EditorConfiguration *Project::editorConfiguration() const
|
|
|
|
|
{
|
|
|
|
|
return m_editorConfiguration;
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-05 18:21:40 +02:00
|
|
|
QByteArray Project::predefinedMacros(const QString &) const
|
2009-05-04 18:22:40 +02:00
|
|
|
{
|
|
|
|
|
return QByteArray();
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-05 18:21:40 +02:00
|
|
|
QStringList Project::includePaths(const QString &) const
|
2009-05-04 18:22:40 +02:00
|
|
|
{
|
|
|
|
|
return QStringList();
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-05 18:21:40 +02:00
|
|
|
QStringList Project::frameworkPaths(const QString &) const
|
2009-05-04 18:22:40 +02:00
|
|
|
{
|
|
|
|
|
return QStringList();
|
|
|
|
|
}
|
2009-12-03 16:23:15 +01:00
|
|
|
|
|
|
|
|
QString Project::generatedUiHeader(const QString & /* formFile */) const
|
|
|
|
|
{
|
|
|
|
|
return QString();
|
|
|
|
|
}
|