Commit f1f1f65f authored by Tobias Hunger's avatar Tobias Hunger Committed by hjk

Kits: Simplify handling of sticky kit information

Change-Id: Iff01445d1251487bd44c227de36f1b47ba4c3d42
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
parent 6e11e562
......@@ -51,11 +51,9 @@ using namespace Utils;
namespace Android {
namespace Internal {
static const char ANDROID_GDBSERVER_INFORMATION[] = "Android.GdbServer.Information";
AndroidGdbServerKitInformation::AndroidGdbServerKitInformation()
{
setDataId(ANDROID_GDBSERVER_INFORMATION);
setId(AndroidGdbServerKitInformation::id());
setPriority(27999); // Just one less than Debugger!
}
......@@ -77,7 +75,12 @@ KitInformation::ItemList AndroidGdbServerKitInformation::toUserOutput(const Kit
KitConfigWidget *AndroidGdbServerKitInformation::createConfigWidget(Kit *kit) const
{
return new AndroidGdbServerKitInformationWidget(kit, isSticky(kit));
return new AndroidGdbServerKitInformationWidget(kit, this);
}
Core::Id AndroidGdbServerKitInformation::id()
{
return "Android.GdbServer.Information";
}
bool AndroidGdbServerKitInformation::isAndroidKit(const Kit *kit)
......@@ -93,12 +96,12 @@ bool AndroidGdbServerKitInformation::isAndroidKit(const Kit *kit)
FileName AndroidGdbServerKitInformation::gdbServer(const Kit *kit)
{
return FileName::fromString(kit->value(ANDROID_GDBSERVER_INFORMATION).toString());
return FileName::fromString(kit->value(AndroidGdbServerKitInformation::id()).toString());
}
void AndroidGdbServerKitInformation::setGdbSever(Kit *kit, const FileName &gdbServerCommand)
{
kit->setValue(ANDROID_GDBSERVER_INFORMATION, gdbServerCommand.toString());
kit->setValue(AndroidGdbServerKitInformation::id(), gdbServerCommand.toString());
}
FileName AndroidGdbServerKitInformation::autoDetect(Kit *kit)
......@@ -110,18 +113,13 @@ FileName AndroidGdbServerKitInformation::autoDetect(Kit *kit)
return atc->suggestedGdbServer();
}
void AndroidGdbServerKitInformation::setSticky(Kit *k, bool b)
{
k->setSticky(ANDROID_GDBSERVER_INFORMATION, b);
}
///////////////
// AndroidGdbServerKitInformationWidget
///////////////
AndroidGdbServerKitInformationWidget::AndroidGdbServerKitInformationWidget(Kit *kit, bool sticky)
: KitConfigWidget(kit, sticky),
AndroidGdbServerKitInformationWidget::AndroidGdbServerKitInformationWidget(Kit *kit, const KitInformation *ki)
: KitConfigWidget(kit, ki),
m_label(new ElidingLabel),
m_button(new QPushButton(tr("Manage...")))
{
......
......@@ -45,7 +45,8 @@ class AndroidGdbServerKitInformationWidget : public ProjectExplorer::KitConfigWi
{
Q_OBJECT
public:
AndroidGdbServerKitInformationWidget(ProjectExplorer::Kit *kit, bool sticky);
AndroidGdbServerKitInformationWidget(ProjectExplorer::Kit *kit,
const ProjectExplorer::KitInformation *ki);
QString displayName() const;
QString toolTip() const;
......@@ -78,11 +79,11 @@ public:
ProjectExplorer::KitConfigWidget *createConfigWidget(ProjectExplorer::Kit *) const;
static Core::Id id();
static bool isAndroidKit(const ProjectExplorer::Kit *kit);
static Utils::FileName gdbServer(const ProjectExplorer::Kit *kit);
static void setGdbSever(ProjectExplorer::Kit *kit, const Utils::FileName &gdbServerCommand);
static Utils::FileName autoDetect(ProjectExplorer::Kit *kit);
static void setSticky(ProjectExplorer::Kit *k, bool b);
};
} // namespace Internal
......
......@@ -77,9 +77,6 @@ static const char DEFAULT_DEBUGGER_PATH_KEY[] = "DefaultDebugger.Path.";
static const char DEBUGGER_FILENAME[] = "/qtcreator/debuggers.xml";
static const char DEBUGGER_LEGACY_FILENAME[] = "/qtcreator/profiles.xml";
static const char DEBUGGER_INFORMATION_LEGACY[] = "Debugger.Information";
//static const char DEBUGGER_INFORMATION[] = "Debugger.InformationV3";
static const char DEBUGGER_INFORMATION[] = "Debugger.Information";
static const char DEBUGGER_INFORMATION_COMMAND[] = "Binary";
static const char DEBUGGER_INFORMATION_DISPLAYNAME[] = "DisplayName";
static const char DEBUGGER_INFORMATION_ID[] = "Id";
......@@ -224,7 +221,7 @@ void DebuggerItem::reinitializeFromFile()
DebuggerKitInformation::DebuggerKitInformation()
{
setObjectName(QLatin1String("DebuggerKitInformation"));
setDataId(DEBUGGER_INFORMATION);
setId(DebuggerKitInformation::id());
setPriority(28000);
}
......@@ -242,7 +239,7 @@ QVariant DebuggerKitInformation::defaultValue(Kit *k) const
void DebuggerKitInformation::setup(Kit *k)
{
k->setValue(DEBUGGER_INFORMATION, defaultValue(k));
k->setValue(DebuggerKitInformation::id(), defaultValue(k));
}
// Check the configuration errors and return a flag mask. Provide a quick check and
......@@ -258,7 +255,7 @@ enum DebuggerConfigurationErrors {
static QVariant debuggerPathOrId(const Kit *k)
{
QTC_ASSERT(k, return QString());
QVariant id = k->value(DEBUGGER_INFORMATION);
QVariant id = k->value(DebuggerKitInformation::id());
if (!id.isValid())
return id; // Invalid.
......@@ -344,7 +341,7 @@ QList<Task> DebuggerKitInformation::validateDebugger(const Kit *k)
KitConfigWidget *DebuggerKitInformation::createConfigWidget(Kit *k) const
{
return new Internal::DebuggerKitConfigWidget(k, isSticky(k));
return new Internal::DebuggerKitConfigWidget(k, this);
}
KitInformation::ItemList DebuggerKitInformation::toUserOutput(const Kit *k) const
......@@ -382,12 +379,11 @@ void DebuggerKitInformation::setDebugger(Kit *k,
theDebuggerItemManager()->setDebugger(k, type, command);
}
void DebuggerKitInformation::setSticky(Kit *k, bool b)
Core::Id DebuggerKitInformation::id()
{
k->setSticky(DEBUGGER_INFORMATION, b);
return "Debugger.Information";
}
namespace Internal {
static FileName userSettingsFileName()
......@@ -590,7 +586,7 @@ void DebuggerItemManager::readLegacyDebuggers()
QVariantMap data1 = v.toMap();
QString kitName = data1.value(QLatin1String("PE.Profile.Name")).toString();
QVariantMap data2 = data1.value(QLatin1String("PE.Profile.Data")).toMap();
QVariant v3 = data2.value(QLatin1String(DEBUGGER_INFORMATION));
QVariant v3 = data2.value(DebuggerKitInformation::id().toString());
QString fn;
if (v3.type() == QVariant::String)
fn = v3.toString();
......@@ -838,8 +834,7 @@ void DebuggerItemManager::setDebugger(Kit *kit, Debugger::DebuggerEngineType typ
const DebuggerItem *it = findByCommand(command);
QTC_ASSERT(it, return);
QTC_ASSERT(it->id.isValid(), return);
kit->setValue(DEBUGGER_INFORMATION, it->id);
kit->setValue(DebuggerKitInformation::id(), it->id);
}
QModelIndex DebuggerItemManager::currentIndex() const
......@@ -1004,8 +999,8 @@ QVariant DebuggerItemManager::defaultDebugger(ToolChain *tc)
// DebuggerKitConfigWidget
// -----------------------------------------------------------------------
DebuggerKitConfigWidget::DebuggerKitConfigWidget(Kit *workingCopy, bool sticky)
: KitConfigWidget(workingCopy, sticky)
DebuggerKitConfigWidget::DebuggerKitConfigWidget(Kit *workingCopy, const KitInformation *ki)
: KitConfigWidget(workingCopy, ki)
{
DebuggerItemManager *manager = theDebuggerItemManager();
QTC_CHECK(manager);
......@@ -1072,7 +1067,7 @@ void DebuggerKitConfigWidget::manageDebuggers()
void DebuggerKitConfigWidget::currentDebuggerChanged(int)
{
m_kit->setValue(DEBUGGER_INFORMATION, m_comboBox->itemData(m_comboBox->currentIndex()));
m_kit->setValue(DebuggerKitInformation::id(), m_comboBox->itemData(m_comboBox->currentIndex()));
}
void DebuggerKitConfigWidget::onDebuggerAdded(const QVariant &id, const QString &displayName)
......
......@@ -127,7 +127,8 @@ class DebuggerKitConfigWidget : public ProjectExplorer::KitConfigWidget
Q_OBJECT
public:
DebuggerKitConfigWidget(ProjectExplorer::Kit *workingCopy, bool sticky);
DebuggerKitConfigWidget(ProjectExplorer::Kit *workingCopy,
const ProjectExplorer::KitInformation *ki);
QString displayName() const;
QString toolTip() const;
......
......@@ -62,11 +62,10 @@ public:
static void setDebugger(ProjectExplorer::Kit *k,
DebuggerEngineType type, const Utils::FileName &command);
static Core::Id id();
static Utils::FileName debuggerCommand(const ProjectExplorer::Kit *k);
static DebuggerEngineType engineType(const ProjectExplorer::Kit *k);
static QString displayString(const ProjectExplorer::Kit *k);
static void setSticky(ProjectExplorer::Kit *k, bool b);
};
} // namespace Debugger
......
......@@ -107,7 +107,7 @@ Kit::Kit(Core::Id id) :
{
KitGuard g(this);
foreach (KitInformation *sti, KitManager::kitInformation())
setValue(sti->dataId(), sti->defaultValue(this));
setValue(sti->id(), sti->defaultValue(this));
setDisplayName(QCoreApplication::translate("ProjectExplorer::Kit", "Unnamed"));
setIconPath(Utils::FileName::fromString(QLatin1String(":///DESKTOP///")));
......@@ -471,8 +471,8 @@ void Kit::setSdkProvided(bool sdkProvided)
void Kit::makeSticky()
{
foreach (KitInformation *ki, KitManager::kitInformation()) {
if (hasValue(ki->dataId()))
setSticky(ki->dataId(), true);
if (hasValue(ki->id()))
setSticky(ki->id(), true);
}
}
......
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** 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.
**
** GNU Lesser General Public License Usage
** 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
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "kitconfigwidget.h"
#include "kit.h"
#include "kitinformation.h"
namespace ProjectExplorer {
KitConfigWidget::KitConfigWidget(Kit *kit, const KitInformation *ki) : m_kit(kit),
m_kitInformation(ki), m_isSticky(kit->isSticky(ki->id()))
{ }
} // namespace ProjectExplorer
......@@ -37,6 +37,7 @@
namespace ProjectExplorer {
class Kit;
class KitInformation;
// --------------------------------------------------------------------------
// KitConfigWidget
......@@ -47,7 +48,7 @@ class PROJECTEXPLORER_EXPORT KitConfigWidget : public QObject
Q_OBJECT
public:
KitConfigWidget(Kit *kit, bool sticky) : m_kit(kit), m_isSticky(sticky) { }
KitConfigWidget(Kit *kit, const KitInformation *ki);
virtual QString displayName() const = 0;
virtual QString toolTip() const { return QString(); }
......@@ -58,13 +59,14 @@ public:
virtual QWidget *mainWidget() const = 0;
virtual QWidget *buttonWidget() const { return 0; }
bool isSticky() { return m_isSticky; }
bool isSticky() const { return m_isSticky; }
signals:
void dirty();
protected:
ProjectExplorer::Kit *m_kit;
Kit *m_kit;
const KitInformation *m_kitInformation;
bool m_isSticky;
};
......
......@@ -49,12 +49,10 @@ namespace ProjectExplorer {
// SysRootInformation:
// --------------------------------------------------------------------------
static const char SYSROOT_INFORMATION[] = "PE.Profile.SysRoot";
SysRootKitInformation::SysRootKitInformation()
{
setObjectName(QLatin1String("SysRootInformation"));
setDataId(SYSROOT_INFORMATION);
setId(SysRootKitInformation::id());
setPriority(31000);
}
......@@ -77,7 +75,7 @@ QList<Task> SysRootKitInformation::validate(const Kit *k) const
KitConfigWidget *SysRootKitInformation::createConfigWidget(Kit *k) const
{
return new Internal::SysRootInformationConfigWidget(k, isSticky(k));
return new Internal::SysRootInformationConfigWidget(k, this);
}
KitInformation::ItemList SysRootKitInformation::toUserOutput(const Kit *k) const
......@@ -85,10 +83,15 @@ KitInformation::ItemList SysRootKitInformation::toUserOutput(const Kit *k) const
return ItemList() << qMakePair(tr("Sys Root"), sysRoot(k).toUserOutput());
}
Core::Id SysRootKitInformation::id()
{
return "PE.Profile.SysRoot";
}
bool SysRootKitInformation::hasSysRoot(const Kit *k)
{
if (k)
return !k->value(Core::Id(SYSROOT_INFORMATION)).toString().isEmpty();
return !k->value(SysRootKitInformation::id()).toString().isEmpty();
return false;
}
......@@ -96,29 +99,22 @@ Utils::FileName SysRootKitInformation::sysRoot(const Kit *k)
{
if (!k)
return Utils::FileName();
return Utils::FileName::fromString(k->value(Core::Id(SYSROOT_INFORMATION)).toString());
return Utils::FileName::fromString(k->value(SysRootKitInformation::id()).toString());
}
void SysRootKitInformation::setSysRoot(Kit *k, const Utils::FileName &v)
{
k->setValue(Core::Id(SYSROOT_INFORMATION), v.toString());
}
void SysRootKitInformation::setSticky(Kit *k, bool b)
{
k->setSticky(SYSROOT_INFORMATION, b);
k->setValue(SysRootKitInformation::id(), v.toString());
}
// --------------------------------------------------------------------------
// ToolChainInformation:
// --------------------------------------------------------------------------
static const char TOOLCHAIN_INFORMATION[] = "PE.Profile.ToolChain";
ToolChainKitInformation::ToolChainKitInformation()
{
setObjectName(QLatin1String("ToolChainInformation"));
setDataId(TOOLCHAIN_INFORMATION);
setId(ToolChainKitInformation::id());
setPriority(30000);
connect(KitManager::instance(), SIGNAL(kitsLoaded()),
......@@ -170,7 +166,7 @@ void ToolChainKitInformation::fix(Kit *k)
void ToolChainKitInformation::setup(Kit *k)
{
QTC_ASSERT(ToolChainManager::isLoaded(), return);
const QString id = k->value(TOOLCHAIN_INFORMATION).toString();
const QString id = k->value(ToolChainKitInformation::id()).toString();
if (id.isEmpty())
return;
......@@ -187,7 +183,7 @@ void ToolChainKitInformation::setup(Kit *k)
KitConfigWidget *ToolChainKitInformation::createConfigWidget(Kit *k) const
{
return new Internal::ToolChainInformationConfigWidget(k, isSticky(k));
return new Internal::ToolChainInformationConfigWidget(k, this);
}
QString ToolChainKitInformation::displayNamePostfix(const Kit *k) const
......@@ -217,17 +213,22 @@ IOutputParser *ToolChainKitInformation::createOutputParser(const Kit *k) const
return 0;
}
Core::Id ToolChainKitInformation::id()
{
return "PE.Profile.ToolChain";
}
ToolChain *ToolChainKitInformation::toolChain(const Kit *k)
{
QTC_ASSERT(ToolChainManager::isLoaded(), return 0);
if (!k)
return 0;
return ToolChainManager::findToolChain(k->value(TOOLCHAIN_INFORMATION).toString());
return ToolChainManager::findToolChain(k->value(ToolChainKitInformation::id()).toString());
}
void ToolChainKitInformation::setToolChain(Kit *k, ToolChain *tc)
{
k->setValue(TOOLCHAIN_INFORMATION, tc ? tc->id() : QString());
k->setValue(ToolChainKitInformation::id(), tc ? tc->id() : QString());
}
QString ToolChainKitInformation::msgNoToolChainInTarget()
......@@ -235,11 +236,6 @@ QString ToolChainKitInformation::msgNoToolChainInTarget()
return tr("No compiler set in kit.");
}
void ToolChainKitInformation::setSticky(Kit *k, bool b)
{
k->setSticky(TOOLCHAIN_INFORMATION, b);
}
void ToolChainKitInformation::kitsWereLoaded()
{
foreach (Kit *k, KitManager::kits())
......@@ -268,12 +264,10 @@ void ToolChainKitInformation::toolChainRemoved(ToolChain *tc)
// DeviceTypeInformation:
// --------------------------------------------------------------------------
static const char DEVICETYPE_INFORMATION[] = "PE.Profile.DeviceType";
DeviceTypeKitInformation::DeviceTypeKitInformation()
{
setObjectName(QLatin1String("DeviceTypeInformation"));
setDataId(DEVICETYPE_INFORMATION);
setId(DeviceTypeKitInformation::id());
setPriority(33000);
}
......@@ -291,7 +285,7 @@ QList<Task> DeviceTypeKitInformation::validate(const Kit *k) const
KitConfigWidget *DeviceTypeKitInformation::createConfigWidget(Kit *k) const
{
return new Internal::DeviceTypeInformationConfigWidget(k, isSticky(k));
return new Internal::DeviceTypeInformationConfigWidget(k, this);
}
KitInformation::ItemList DeviceTypeKitInformation::toUserOutput(const Kit *k) const
......@@ -311,31 +305,29 @@ KitInformation::ItemList DeviceTypeKitInformation::toUserOutput(const Kit *k) co
return ItemList() << qMakePair(tr("Device type"), typeDisplayName);
}
const Core::Id DeviceTypeKitInformation::deviceTypeId(const Kit *k)
const Core::Id DeviceTypeKitInformation::id()
{
return k ? Core::Id::fromSetting(k->value(DEVICETYPE_INFORMATION)) : Core::Id();
return "PE.Profile.DeviceType";
}
void DeviceTypeKitInformation::setDeviceTypeId(Kit *k, Core::Id type)
const Core::Id DeviceTypeKitInformation::deviceTypeId(const Kit *k)
{
k->setValue(DEVICETYPE_INFORMATION, type.toSetting());
return k ? Core::Id::fromSetting(k->value(DeviceTypeKitInformation::id())) : Core::Id();
}
void DeviceTypeKitInformation::setSticky(Kit *k, bool b)
void DeviceTypeKitInformation::setDeviceTypeId(Kit *k, Core::Id type)
{
k->setSticky(DEVICETYPE_INFORMATION, b);
k->setValue(DeviceTypeKitInformation::id(), type.toSetting());
}
// --------------------------------------------------------------------------
// DeviceInformation:
// --------------------------------------------------------------------------
static const char DEVICE_INFORMATION[] = "PE.Profile.Device";
DeviceKitInformation::DeviceKitInformation()
{
setObjectName(QLatin1String("DeviceInformation"));
setDataId(DEVICE_INFORMATION);
setId(DeviceKitInformation::id());
setPriority(32000);
connect(KitManager::instance(), SIGNAL(kitsLoaded()),
......@@ -384,7 +376,7 @@ void DeviceKitInformation::setup(Kit *k)
KitConfigWidget *DeviceKitInformation::createConfigWidget(Kit *k) const
{
return new Internal::DeviceInformationConfigWidget(k, isSticky(k));
return new Internal::DeviceInformationConfigWidget(k, this);
}
QString DeviceKitInformation::displayNamePostfix(const Kit *k) const
......@@ -399,6 +391,11 @@ KitInformation::ItemList DeviceKitInformation::toUserOutput(const Kit *k) const
return ItemList() << qMakePair(tr("Device"), dev.isNull() ? tr("Unconfigured") : dev->displayName());
}
Core::Id DeviceKitInformation::id()
{
return "PE.Profile.Device";
}
IDevice::ConstPtr DeviceKitInformation::device(const Kit *k)
{
QTC_ASSERT(DeviceManager::instance()->isLoaded(), return IDevice::ConstPtr());
......@@ -407,7 +404,7 @@ IDevice::ConstPtr DeviceKitInformation::device(const Kit *k)
Core::Id DeviceKitInformation::deviceId(const Kit *k)
{
return k ? Core::Id::fromSetting(k->value(DEVICE_INFORMATION)) : Core::Id();
return k ? Core::Id::fromSetting(k->value(DeviceKitInformation::id())) : Core::Id();
}
void DeviceKitInformation::setDevice(Kit *k, IDevice::ConstPtr dev)
......@@ -417,12 +414,7 @@ void DeviceKitInformation::setDevice(Kit *k, IDevice::ConstPtr dev)
void DeviceKitInformation::setDeviceId(Kit *k, const Core::Id id)
{
k->setValue(DEVICE_INFORMATION, id.toSetting());
}
void DeviceKitInformation::setSticky(Kit *k, bool b)
{
k->setSticky(DEVICE_INFORMATION, b);
k->setValue(DeviceKitInformation::id(), id.toSetting());
}
void DeviceKitInformation::kitsWereLoaded()
......
......@@ -61,11 +61,10 @@ public:
ItemList toUserOutput(const Kit *k) const;
static Core::Id id();
static bool hasSysRoot(const Kit *k);
static Utils::FileName sysRoot(const Kit *k);
static void setSysRoot(Kit *k, const Utils::FileName &v);
static void setSticky(Kit *k, bool b);
};
class PROJECTEXPLORER_EXPORT SysRootMatcher : public KitMatcher
......@@ -109,13 +108,12 @@ public:
void addToEnvironment(const Kit *k, Utils::Environment &env) const;
IOutputParser *createOutputParser(const Kit *k) const;
static Core::Id id();
static ToolChain *toolChain(const Kit *k);
static void setToolChain(Kit *k, ToolChain *tc);
static QString msgNoToolChainInTarget();
static void setSticky(Kit *k, bool b);
private slots:
void kitsWereLoaded();
void toolChainUpdated(ProjectExplorer::ToolChain *tc);
......@@ -156,9 +154,9 @@ public:
ItemList toUserOutput(const Kit *k) const;
static const Core::Id id();
static const Core::Id deviceTypeId(const Kit *k);
static void setDeviceTypeId(Kit *k, Core::Id type);
static void setSticky(Kit *k, bool b);
};
class PROJECTEXPLORER_EXPORT DeviceTypeMatcher : public KitMatcher
......@@ -202,16 +200,15 @@ public:
ItemList toUserOutput(const Kit *k) const;
static Core::Id id();
static IDevice::ConstPtr device(const Kit *k);
static Core::Id deviceId(const Kit *k);
static void setDevice(Kit *k, IDevice::ConstPtr dev);
static void setDeviceId(Kit *k, const Core::Id id);
static void setSticky(Kit *k, bool b);
static void setDeviceId(Kit *k, const Core::Id dataId);
private slots:
void kitsWereLoaded();
void deviceUpdated(const Core::Id &id);
void deviceUpdated(const Core::Id &dataId);
void devicesChanged();
void kitUpdated(ProjectExplorer::Kit *k);
};
......
......@@ -55,8 +55,8 @@ namespace Internal {
// SysRootInformationConfigWidget: