Commit 95859289 authored by Tobias Hunger's avatar Tobias Hunger

KitManager: Use static API as other singletons do

Change-Id: Ia49c6552a5aae72870687ef9c64f2642fbe24155
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
parent 6ee2d554
......@@ -744,7 +744,7 @@ void AndroidConfigurations::updateAutomaticKitList()
QList<Kit *> existingKits;
foreach (ProjectExplorer::Kit *k, ProjectExplorer::KitManager::instance()->kits()) {
foreach (ProjectExplorer::Kit *k, ProjectExplorer::KitManager::kits()) {
if (ProjectExplorer::DeviceKitInformation::deviceId(k) != Core::Id(Constants::ANDROID_DEVICE_ID))
continue;
if (!k->isAutoDetected())
......@@ -805,7 +805,7 @@ void AndroidConfigurations::updateAutomaticKitList()
}
foreach (Kit *k, existingKits)
KitManager::instance()->deregisterKit(k);
KitManager::deregisterKit(k);
foreach (Kit *kit, newKits) {
AndroidToolChain *tc = static_cast<AndroidToolChain *>(ToolChainKitInformation::toolChain(kit));
......@@ -814,7 +814,7 @@ void AndroidConfigurations::updateAutomaticKitList()
.arg(qt->targetArch())
.arg(tc->ndkToolChainVersion())
.arg(qt->qtVersionString()));
KitManager::instance()->registerKit(kit);
KitManager::registerKit(kit);
}
}
......
......@@ -77,7 +77,7 @@ bool AndroidPlugin::initialize(const QStringList &arguments, QString *errorMessa
addAutoReleasedObject(new Internal::AndroidToolChainFactory);
addAutoReleasedObject(new Internal::AndroidDeployConfigurationFactory);
addAutoReleasedObject(new Internal::AndroidDeviceFactory);
ProjectExplorer::KitManager::instance()->registerKitInformation(new Internal::AndroidGdbServerKitInformation);
ProjectExplorer::KitManager::registerKitInformation(new Internal::AndroidGdbServerKitInformation);
// AndroidManifest.xml editor
Core::MimeGlobPattern androidManifestGlobPattern(QLatin1String("AndroidManifest.xml"), Core::MimeGlobPattern::MaxWeight);
......
......@@ -157,7 +157,7 @@ bool AutotoolsProject::fromMap(const QVariantMap &map)
// Load the project tree structure.
loadProjectTree();
Kit *defaultKit = KitManager::instance()->defaultKit();
Kit *defaultKit = KitManager::defaultKit();
if (!activeTarget() && defaultKit)
addTarget(createTarget(defaultKit));
......
......@@ -292,8 +292,7 @@ bool CMakeOpenProjectWizard::compatibleKitExist() const
bool hasNinjaGenerator = m_cmakeManager->hasCodeBlocksNinjaGenerator();
bool preferNinja = m_cmakeManager->preferNinja();
QList<ProjectExplorer::Kit *> kitList =
ProjectExplorer::KitManager::instance()->kits();
QList<ProjectExplorer::Kit *> kitList = ProjectExplorer::KitManager::kits();
foreach (ProjectExplorer::Kit *k, kitList) {
// OfferNinja and ForceNinja differ in what they return
......@@ -665,8 +664,7 @@ void CMakeRunPage::initializePage()
QByteArray cachedGenerator = cachedGeneratorFromFile(m_buildDirectory + QLatin1String("/CMakeCache.txt"));
m_generatorComboBox->show();
QList<ProjectExplorer::Kit *> kitList =
ProjectExplorer::KitManager::instance()->kits();
QList<ProjectExplorer::Kit *> kitList = ProjectExplorer::KitManager::kits();
int defaultIndex = 0;
foreach (ProjectExplorer::Kit *k, kitList) {
......@@ -675,7 +673,7 @@ void CMakeRunPage::initializePage()
preferNinja,
hasCodeBlocksGenerator);
if (k == ProjectExplorer::KitManager::instance()->defaultKit())
if (k == ProjectExplorer::KitManager::defaultKit())
defaultIndex = m_generatorComboBox->count();
foreach (const GeneratorInfo &info, infos)
......
......@@ -184,7 +184,7 @@ QString StartApplicationParameters::displayName() const
name += QLatin1String("...");
}
if (Kit *kit = KitManager::instance()->find(kitId))
if (Kit *kit = KitManager::find(kitId))
name += QString::fromLatin1(" (%1)").arg(kit->displayName());
return name;
......
......@@ -593,12 +593,12 @@ public:
#ifdef Q_OS_WIN
if (Utils::winIs64BitSystem()) {
CdbMatcher matcher64(64);
if (Kit *cdb64Kit = KitManager::instance()->find(&matcher64))
if (Kit *cdb64Kit = KitManager::find(&matcher64))
return cdb64Kit;
}
#endif
CdbMatcher matcher;
return KitManager::instance()->find(&matcher);
return KitManager::find(&matcher);
}
private:
......@@ -625,14 +625,14 @@ bool fillParameters(DebuggerStartParameters *sp, const Kit *kit, QString *errorM
}
if (!abis.isEmpty()) {
AbiKitMatcher matcher(abis);
kit = KitManager::instance()->find(&matcher);
kit = KitManager::find(&matcher);
if (!kit) {
CompatibleAbiKitMatcher matcher(abis);
kit = KitManager::instance()->find(&matcher);
kit = KitManager::find(&matcher);
}
}
if (!kit)
kit = KitManager::instance()->defaultKit();
kit = KitManager::defaultKit();
}
// Verify that debugger and profile are valid
......@@ -1427,7 +1427,7 @@ bool DebuggerPluginPrivate::parseArgument(QStringList::const_iterator &it,
sp.displayName = tr("Core file \"%1\"").arg(sp.coreFile);
sp.startMessage = tr("Attaching to core file %1.").arg(sp.coreFile);
} else if (key == QLatin1String("kit")) {
kit = KitManager::instance()->find(Id::fromString(val));
kit = KitManager::find(Id::fromString(val));
}
}
}
......@@ -3436,7 +3436,7 @@ bool DebuggerPlugin::initialize(const QStringList &arguments, QString *errorMess
mstart->addSeparator(globalcontext, Constants::G_GENERAL);
mstart->addSeparator(globalcontext, Constants::G_SPECIAL);
KitManager::instance()->registerKitInformation(new DebuggerKitInformation);
KitManager::registerKitInformation(new DebuggerKitInformation);
return theDebuggerCore->initialize(arguments, errorMessage);
}
......
......@@ -335,7 +335,7 @@ static DebuggerStartParameters localStartParameters(RunConfiguration *runConfigu
return sp;
Target *target = runConfiguration->target();
Kit *kit = target ? target->kit() : KitManager::instance()->defaultKit();
Kit *kit = target ? target->kit() : KitManager::defaultKit();
if (!fillParameters(&sp, kit, errorMessage))
return sp;
sp.environment = environment->environment();
......
......@@ -248,7 +248,7 @@ void GenericProject::refresh(RefreshOptions options)
pinfo.clearProjectParts();
CppTools::ProjectPart::Ptr part(new CppTools::ProjectPart);
Kit *k = activeTarget() ? activeTarget()->kit() : KitManager::instance()->defaultKit();
Kit *k = activeTarget() ? activeTarget()->kit() : KitManager::defaultKit();
if (ToolChain *tc = ToolChainKitInformation::toolChain(k)) {
QStringList cxxflags; // FIXME: Can we do better?
part->evaluateToolchain(tc, cxxflags, cxxflags,
......@@ -408,7 +408,7 @@ bool GenericProject::fromMap(const QVariantMap &map)
if (!Project::fromMap(map))
return false;
Kit *defaultKit = KitManager::instance()->defaultKit();
Kit *defaultKit = KitManager::defaultKit();
if (!activeTarget() && defaultKit)
addTarget(createTarget(defaultKit));
......
......@@ -118,9 +118,8 @@ public:
Kit::Kit(Core::Id id) :
d(new Internal::KitPrivate(id))
{
KitManager *stm = KitManager::instance();
KitGuard g(this);
foreach (KitInformation *sti, stm->kitInformation())
foreach (KitInformation *sti, KitManager::kitInformation())
setValue(sti->dataId(), sti->defaultValue(this));
setDisplayName(QCoreApplication::translate("ProjectExplorer::Kit", "Unnamed"));
......@@ -193,7 +192,7 @@ bool Kit::hasWarning() const
QList<Task> Kit::validate() const
{
QList<Task> result;
QList<KitInformation *> infoList = KitManager::instance()->kitInformation();
QList<KitInformation *> infoList = KitManager::kitInformation();
d->m_isValid = true;
d->m_hasWarning = false;
foreach (KitInformation *i, infoList) {
......@@ -213,7 +212,7 @@ QList<Task> Kit::validate() const
void Kit::fix()
{
KitGuard g(this);
foreach (KitInformation *i, KitManager::instance()->kitInformation())
foreach (KitInformation *i, KitManager::kitInformation())
i->fix(this);
}
......@@ -222,7 +221,7 @@ void Kit::setup()
KitGuard g(this);
// Process the KitInfos in reverse order: They may only be based on other information lower in
// the stack.
QList<KitInformation *> info = KitManager::instance()->kitInformation();
QList<KitInformation *> info = KitManager::kitInformation();
for (int i = info.count() - 1; i >= 0; --i)
info.at(i)->setup(this);
}
......@@ -255,7 +254,7 @@ QStringList Kit::candidateNameList(const QString &base) const
{
QStringList result;
result << base;
foreach (KitInformation *ki, KitManager::instance()->kitInformation()) {
foreach (KitInformation *ki, KitManager::kitInformation()) {
const QString postfix = ki->displayNamePostfix(this);
if (!postfix.isEmpty())
result << candidateName(base, postfix);
......@@ -266,7 +265,7 @@ QStringList Kit::candidateNameList(const QString &base) const
QString Kit::fileSystemFriendlyName() const
{
QString name = cleanName(displayName());
foreach (Kit *i, KitManager::instance()->kits()) {
foreach (Kit *i, KitManager::kits()) {
if (i == this)
continue;
if (name == cleanName(i->displayName())) {
......@@ -393,7 +392,7 @@ QVariantMap Kit::toMap() const
void Kit::addToEnvironment(Utils::Environment &env) const
{
QList<KitInformation *> infoList = KitManager::instance()->kitInformation();
QList<KitInformation *> infoList = KitManager::kitInformation();
foreach (KitInformation *ki, infoList)
ki->addToEnvironment(this, env);
}
......@@ -401,7 +400,7 @@ void Kit::addToEnvironment(Utils::Environment &env) const
IOutputParser *Kit::createOutputParser() const
{
IOutputParser *first = 0;
QList<KitInformation *> infoList = KitManager::instance()->kitInformation();
QList<KitInformation *> infoList = KitManager::kitInformation();
foreach (KitInformation *ki, infoList) {
IOutputParser *next = ki->createOutputParser(this);
if (!first)
......@@ -441,7 +440,7 @@ QString Kit::toHtml() const
str << "</p>";
}
QList<KitInformation *> infoList = KitManager::instance()->kitInformation();
QList<KitInformation *> infoList = KitManager::kitInformation();
foreach (KitInformation *ki, infoList) {
KitInformation::ItemList list = ki->toUserOutput(this);
foreach (const KitInformation::Item &j, list)
......@@ -489,7 +488,7 @@ void Kit::setSdkProvided(bool sdkProvided)
void Kit::makeSticky()
{
foreach (KitInformation *ki, KitManager::instance()->kitInformation()) {
foreach (KitInformation *ki, KitManager::kitInformation()) {
if (hasValue(ki->dataId()))
makeSticky(ki->dataId());
}
......@@ -507,7 +506,7 @@ void Kit::kitUpdated()
return;
}
validate();
KitManager::instance()->notifyAboutUpdate(this);
KitManager::notifyAboutUpdate(this);
}
void Kit::kitDisplayNameChanged()
......@@ -518,7 +517,7 @@ void Kit::kitDisplayNameChanged()
return;
}
validate();
KitManager::instance()->notifyAboutDisplayNameChange(this);
KitManager::notifyAboutDisplayNameChange(this);
}
} // namespace ProjectExplorer
......@@ -71,7 +71,7 @@ QString KitChooser::kitToolTip(Kit *k) const
void KitChooser::populate()
{
clear();
foreach (Kit *kit, KitManager::instance()->kits()) {
foreach (Kit *kit, KitManager::kits()) {
if (kitMatches(kit)) {
addItem(kitText(kit), qVariantFromValue(kit->id()));
setItemData(count() - 1, kitToolTip(kit), Qt::ToolTipRole);
......@@ -109,7 +109,7 @@ Core::Id KitChooser::currentKitId() const
Kit *KitChooser::kitAt(int index) const
{
Core::Id id = qvariant_cast<Core::Id>(itemData(index));
return KitManager::instance()->find(id);
return KitManager::find(id);
}
} // namespace ProjectExplorer
......@@ -260,7 +260,7 @@ void ToolChainKitInformation::makeSticky(Kit *k)
void ToolChainKitInformation::kitsWereLoaded()
{
foreach (Kit *k, KitManager::instance()->kits())
foreach (Kit *k, KitManager::kits())
fix(k);
connect(ToolChainManager::instance(), SIGNAL(toolChainRemoved(ProjectExplorer::ToolChain*)),
......@@ -272,14 +272,14 @@ void ToolChainKitInformation::kitsWereLoaded()
void ToolChainKitInformation::toolChainUpdated(ProjectExplorer::ToolChain *tc)
{
ToolChainMatcher m(tc);
foreach (Kit *k, KitManager::instance()->kits(&m))
foreach (Kit *k, KitManager::kits(&m))
notifyAboutUpdate(k);
}
void ToolChainKitInformation::toolChainRemoved(ProjectExplorer::ToolChain *tc)
{
Q_UNUSED(tc);
foreach (Kit *k, KitManager::instance()->kits())
foreach (Kit *k, KitManager::kits())
fix(k);
}
......@@ -463,7 +463,7 @@ void DeviceKitInformation::makeSticky(Kit *k)
void DeviceKitInformation::kitsWereLoaded()
{
foreach (Kit *k, KitManager::instance()->kits())
foreach (Kit *k, KitManager::kits())
fix(k);
DeviceManager *dm = DeviceManager::instance();
......@@ -480,7 +480,7 @@ void DeviceKitInformation::kitsWereLoaded()
void DeviceKitInformation::deviceUpdated(const Core::Id &id)
{
foreach (Kit *k, KitManager::instance()->kits()) {
foreach (Kit *k, KitManager::kits()) {
if (deviceId(k) == id)
notifyAboutUpdate(k);
}
......@@ -493,7 +493,7 @@ void DeviceKitInformation::kitUpdated(Kit *k)
void DeviceKitInformation::devicesChanged()
{
foreach (Kit *k, KitManager::instance()->kits())
foreach (Kit *k, KitManager::kits())
setup(k); // Set default device if necessary
}
......
......@@ -154,8 +154,8 @@ KitManager::KitManager(QObject *parent) :
bool KitManager::setKeepDisplayNameUnique(bool unique)
{
bool current = d->m_keepDisplayNameUnique;
d->m_keepDisplayNameUnique = unique;
bool current = m_instance->d->m_keepDisplayNameUnique;
m_instance->d->m_keepDisplayNameUnique = unique;
return current;
}
......@@ -299,13 +299,15 @@ bool greaterPriority(KitInformation *a, KitInformation *b)
void KitManager::registerKitInformation(KitInformation *ki)
{
QTC_CHECK(!isLoaded());
QTC_CHECK(!m_instance->isLoaded());
QTC_ASSERT(!m_instance->d->m_informationList.contains(ki), return);
QList<KitInformation *>::iterator it
= qLowerBound(d->m_informationList.begin(), d->m_informationList.end(), ki, greaterPriority);
d->m_informationList.insert(it, ki);
= qLowerBound(m_instance->d->m_informationList.begin(),
m_instance->d->m_informationList.end(), ki, greaterPriority);
m_instance->d->m_informationList.insert(it, ki);
if (!d->m_initialized)
if (!m_instance->isLoaded())
return;
foreach (Kit *k, kits()) {
......@@ -320,8 +322,8 @@ void KitManager::registerKitInformation(KitInformation *ki)
void KitManager::deregisterKitInformation(KitInformation *ki)
{
QTC_CHECK(d->m_informationList.contains(ki));
d->m_informationList.removeAll(ki);
QTC_CHECK(m_instance->d->m_informationList.contains(ki));
m_instance->d->m_informationList.removeOne(ki);
delete ki;
}
......@@ -373,17 +375,17 @@ KitManager::KitList KitManager::restoreKits(const Utils::FileName &fileName)
return result;
}
QList<Kit *> KitManager::kits(const KitMatcher *m) const
QList<Kit *> KitManager::kits(const KitMatcher *m)
{
QList<Kit *> result;
foreach (Kit *k, d->m_kitList) {
foreach (Kit *k, m_instance->d->m_kitList) {
if (!m || m->matches(k))
result.append(k);
}
return result;
}
Kit *KitManager::find(const Core::Id &id) const
Kit *KitManager::find(const Core::Id &id)
{
if (!id.isValid())
return 0;
......@@ -395,26 +397,26 @@ Kit *KitManager::find(const Core::Id &id) const
return 0;
}
Kit *KitManager::find(const KitMatcher *m) const
Kit *KitManager::find(const KitMatcher *m)
{
QList<Kit *> matched = kits(m);
return matched.isEmpty() ? 0 : matched.first();
}
Kit *KitManager::defaultKit() const
Kit *KitManager::defaultKit()
{
return d->m_defaultKit;
return m_instance->d->m_defaultKit;
}
QList<KitInformation *> KitManager::kitInformation() const
QList<KitInformation *> KitManager::kitInformation()
{
return d->m_informationList;
return m_instance->d->m_informationList;
}
Internal::KitManagerConfigWidget *KitManager::createConfigWidget(Kit *k) const
Internal::KitManagerConfigWidget *KitManager::createConfigWidget(Kit *k)
{
Internal::KitManagerConfigWidget *result = new Internal::KitManagerConfigWidget(k);
foreach (KitInformation *ki, d->m_informationList)
foreach (KitInformation *ki, kitInformation())
result->addConfigWidget(ki->createConfigWidget(result->workingCopy()));
result->updateVisibility();
......@@ -463,28 +465,28 @@ void KitManager::notifyAboutDisplayNameChange(Kit *k)
{
if (!k)
return;
if (d->m_kitList.contains(k) && d->m_keepDisplayNameUnique)
if (m_instance->d->m_kitList.contains(k) && m_instance->d->m_keepDisplayNameUnique)
k->setDisplayName(uniqueKitName(k, k->displayName(), kits()));
int pos = d->m_kitList.indexOf(k);
if (pos >= 0 && d->m_initialized)
d->moveKit(pos);
int pos = m_instance->d->m_kitList.indexOf(k);
if (pos >= 0 && m_instance->d->m_initialized)
m_instance->d->moveKit(pos);
notifyAboutUpdate(k);
}
void KitManager::notifyAboutUpdate(ProjectExplorer::Kit *k)
{
if (!k || !d->m_initialized)
if (!k || !m_instance->isLoaded())
return;
if (d->m_kitList.contains(k))
emit kitUpdated(k);
if (m_instance->d->m_kitList.contains(k))
emit m_instance->kitUpdated(k);
else
emit unmanagedKitUpdated(k);
emit m_instance->unmanagedKitUpdated(k);
}
bool KitManager::registerKit(ProjectExplorer::Kit *k)
{
QTC_ASSERT(isLoaded(), return false);
QTC_ASSERT(m_instance->isLoaded(), return false);
if (!k)
return true;
foreach (Kit *current, kits()) {
......@@ -495,9 +497,8 @@ bool KitManager::registerKit(ProjectExplorer::Kit *k)
k->setDisplayName(uniqueKitName(k, k->displayName(), kits()));
// make sure we have all the information in our kits:
addKit(k);
if (d->m_initialized)
emit kitAdded(k);
m_instance->addKit(k);
emit m_instance->kitAdded(k);
return true;
}
......@@ -505,8 +506,8 @@ void KitManager::deregisterKit(Kit *k)
{
if (!k || !kits().contains(k))
return;
d->m_kitList.removeOne(k);
if (d->m_defaultKit == k) {
m_instance->d->m_kitList.removeOne(k);
if (defaultKit() == k) {
QList<Kit *> stList = kits();
Kit *newDefault = 0;
foreach (Kit *cur, stList) {
......@@ -517,20 +518,18 @@ void KitManager::deregisterKit(Kit *k)
}
setDefaultKit(newDefault);
}
if (d->m_initialized)
emit kitRemoved(k);
emit m_instance->kitRemoved(k);
delete k;
}
void KitManager::setDefaultKit(Kit *k)
{
if (d->m_defaultKit == k)
if (defaultKit() == k)
return;
if (k && !kits().contains(k))
return;
d->m_defaultKit = k;
if (d->m_initialized)
emit defaultkitChanged();
m_instance->d->m_defaultKit = k;
emit m_instance->defaultkitChanged();
}
void KitManager::addKit(Kit *k)
......
......@@ -113,30 +113,28 @@ public:
static KitManager *instance();
~KitManager();
QList<Kit *> kits(const KitMatcher *m = 0) const;
Kit *find(const Core::Id &id) const;
Kit *find(const KitMatcher *m) const;
Kit *defaultKit() const;
static QList<Kit *> kits(const KitMatcher *m = 0);
static Kit *find(const Core::Id &id);
static Kit *find(const KitMatcher *m);
static Kit *defaultKit();
QList<KitInformation *> kitInformation() const;
static QList<KitInformation *> kitInformation();
Internal::KitManagerConfigWidget *createConfigWidget(Kit *k) const;
static Internal::KitManagerConfigWidget *createConfigWidget(Kit *k);
static void deleteKit(Kit *k);
bool isLoaded() const;
static QString uniqueKitName(const Kit *k, const QString name, const QList<Kit *> &allKits);
public slots:
bool registerKit(ProjectExplorer::Kit *k);
void deregisterKit(ProjectExplorer::Kit *k);
void setDefaultKit(ProjectExplorer::Kit *k);
static bool registerKit(ProjectExplorer::Kit *k);
static void deregisterKit(ProjectExplorer::Kit *k);
static void setDefaultKit(ProjectExplorer::Kit *k);
void saveKits();
static void registerKitInformation(ProjectExplorer::KitInformation *ki);
static void deregisterKitInformation(ProjectExplorer::KitInformation *ki);
void registerKitInformation(ProjectExplorer::KitInformation *ki);
void deregisterKitInformation(ProjectExplorer::KitInformation *ki);
public slots:
void saveKits();
signals:
void kitAdded(ProjectExplorer::Kit *);
......@@ -155,7 +153,8 @@ signals:
private:
explicit KitManager(QObject *parent = 0);
bool setKeepDisplayNameUnique(bool unique);
bool isLoaded() const;
static bool setKeepDisplayNameUnique(bool unique);
// Make sure the this is only called after all
// KitInformation are registered!
......@@ -170,8 +169,8 @@ private:
};
KitList restoreKits(const Utils::FileName &fileName);
void notifyAboutDisplayNameChange(ProjectExplorer::Kit *k);
void notifyAboutUpdate(ProjectExplorer::Kit *k);
static void notifyAboutDisplayNameChange(ProjectExplorer::Kit *k);
static void notifyAboutUpdate(ProjectExplorer::Kit *k);
void addKit(Kit *k);
Internal::KitManagerPrivate *const d;
......
......@@ -101,7 +101,7 @@ KitManagerConfigWidget::~KitManagerConfigWidget()
KitManager::deleteKit(m_modifiedKit);
// Make sure our workingCopy did not get registered somehow:
foreach (const Kit *k, KitManager::instance()->kits())
foreach (const Kit *k, KitManager::kits())
QTC_CHECK(k->id() != Core::Id(WORKING_COPY_KIT_ID));
}
......@@ -113,7 +113,6 @@ QString KitManagerConfigWidget::displayName() const
void KitManagerConfigWidget::apply()
{
bool mustSetDefault = m_isDefaultKit;
KitManager *km = KitManager::instance();
bool mustRegister = false;
if (!m_kit) {
mustRegister = true;
......@@ -121,10 +120,10 @@ void KitManagerConfigWidget::apply()
}
m_kit->copyFrom(m_modifiedKit);//m_isDefaultKit is reset in discard() here.
if (mustRegister)
km->registerKit(m_kit);
KitManager::registerKit(m_kit);