Commit f9aa1207 authored by hjk's avatar hjk

ProjectExplorer: Clean up KitsManager API

Change-Id: Ib0b11918fbae9577928b6209a913afb3eccc48b5
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent dd956b32
......@@ -589,12 +589,12 @@ public:
#ifdef Q_OS_WIN
if (Utils::winIs64BitSystem()) {
CdbMatcher matcher64(64);
if (Kit *cdb64Kit = KitManager::find(&matcher64))
if (Kit *cdb64Kit = KitManager::find(matcher64))
return cdb64Kit;
}
#endif
CdbMatcher matcher;
return KitManager::find(&matcher);
return KitManager::find(matcher);
}
private:
......@@ -620,12 +620,9 @@ bool fillParameters(DebuggerStartParameters *sp, const Kit *kit, QString *errorM
abis = Abi::abisOfBinary(Utils::FileName::fromString(sp->executable));
}
if (!abis.isEmpty()) {
AbiKitMatcher matcher(abis);
kit = KitManager::find(&matcher);
if (!kit) {
CompatibleAbiKitMatcher matcher(abis);
kit = KitManager::find(&matcher);
}
kit = KitManager::find(AbiKitMatcher(abis));
if (!kit)
kit = KitManager::find(CompatibleAbiKitMatcher(abis));
}
if (!kit)
kit = KitManager::defaultKit();
......
......@@ -251,14 +251,13 @@ void ToolChainKitInformation::kitsWereLoaded()
this, SLOT(toolChainUpdated(ProjectExplorer::ToolChain*)));
}
void ToolChainKitInformation::toolChainUpdated(ProjectExplorer::ToolChain *tc)
void ToolChainKitInformation::toolChainUpdated(ToolChain *tc)
{
ToolChainMatcher m(tc);
foreach (Kit *k, KitManager::kits(&m))
foreach (Kit *k, KitManager::matchingKits(ToolChainMatcher(tc)))
notifyAboutUpdate(k);
}
void ToolChainKitInformation::toolChainRemoved(ProjectExplorer::ToolChain *tc)
void ToolChainKitInformation::toolChainRemoved(ToolChain *tc)
{
Q_UNUSED(tc);
foreach (Kit *k, KitManager::kits())
......
......@@ -60,9 +60,6 @@ static Utils::FileName settingsFileName()
}
namespace ProjectExplorer {
KitManager *KitManager::m_instance = 0;
namespace Internal {
// --------------------------------------------------------------------------
......@@ -129,15 +126,18 @@ KitManagerPrivate::~KitManagerPrivate()
// KitManager:
// --------------------------------------------------------------------------
KitManager *KitManager::instance()
static Internal::KitManagerPrivate *d;
static KitManager *m_instance;
QObject *KitManager::instance()
{
return m_instance;
}
KitManager::KitManager(QObject *parent) :
QObject(parent),
d(new Internal::KitManagerPrivate())
QObject(parent)
{
d = new Internal::KitManagerPrivate;
QTC_CHECK(!m_instance);
m_instance = this;
......@@ -154,8 +154,8 @@ KitManager::KitManager(QObject *parent) :
bool KitManager::setKeepDisplayNameUnique(bool unique)
{
bool current = m_instance->d->m_keepDisplayNameUnique;
m_instance->d->m_keepDisplayNameUnique = unique;
bool current = d->m_keepDisplayNameUnique;
d->m_keepDisplayNameUnique = unique;
return current;
}
......@@ -292,6 +292,11 @@ void KitManager::saveKits()
d->m_writer->save(data, Core::ICore::mainWindow());
}
static bool isLoaded()
{
return d->m_initialized;
}
bool greaterPriority(KitInformation *a, KitInformation *b)
{
return a->priority() > b->priority();
......@@ -299,15 +304,15 @@ bool greaterPriority(KitInformation *a, KitInformation *b)
void KitManager::registerKitInformation(KitInformation *ki)
{
QTC_CHECK(!m_instance->isLoaded());
QTC_ASSERT(!m_instance->d->m_informationList.contains(ki), return);
QTC_CHECK(!isLoaded());
QTC_ASSERT(!d->m_informationList.contains(ki), return);
QList<KitInformation *>::iterator it
= qLowerBound(m_instance->d->m_informationList.begin(),
m_instance->d->m_informationList.end(), ki, greaterPriority);
m_instance->d->m_informationList.insert(it, ki);
= qLowerBound(d->m_informationList.begin(),
d->m_informationList.end(), ki, greaterPriority);
d->m_informationList.insert(it, ki);
if (!m_instance->isLoaded())
if (!isLoaded())
return;
foreach (Kit *k, kits()) {
......@@ -322,8 +327,8 @@ void KitManager::registerKitInformation(KitInformation *ki)
void KitManager::deregisterKitInformation(KitInformation *ki)
{
QTC_CHECK(m_instance->d->m_informationList.contains(ki));
m_instance->d->m_informationList.removeOne(ki);
QTC_CHECK(d->m_informationList.contains(ki));
d->m_informationList.removeOne(ki);
delete ki;
}
......@@ -375,13 +380,17 @@ KitManager::KitList KitManager::restoreKits(const Utils::FileName &fileName)
return result;
}
QList<Kit *> KitManager::kits(const KitMatcher *m)
QList<Kit *> KitManager::kits()
{
return d->m_kitList;
}
QList<Kit *> KitManager::matchingKits(const KitMatcher &matcher)
{
QList<Kit *> result;
foreach (Kit *k, m_instance->d->m_kitList) {
if (!m || m->matches(k))
foreach (Kit *k, d->m_kitList)
if (matcher.matches(k))
result.append(k);
}
return result;
}
......@@ -397,20 +406,22 @@ Kit *KitManager::find(const Core::Id &id)
return 0;
}
Kit *KitManager::find(const KitMatcher *m)
Kit *KitManager::find(const KitMatcher &matcher)
{
QList<Kit *> matched = kits(m);
return matched.isEmpty() ? 0 : matched.first();
foreach (Kit *k, d->m_kitList)
if (matcher.matches(k))
return k;
return 0;
}
Kit *KitManager::defaultKit()
{
return m_instance->d->m_defaultKit;
return d->m_defaultKit;
}
QList<KitInformation *> KitManager::kitInformation()
{
return m_instance->d->m_informationList;
return d->m_informationList;
}
Internal::KitManagerConfigWidget *KitManager::createConfigWidget(Kit *k)
......@@ -426,15 +437,10 @@ Internal::KitManagerConfigWidget *KitManager::createConfigWidget(Kit *k)
void KitManager::deleteKit(Kit *k)
{
QTC_ASSERT(!KitManager::instance()->kits().contains(k), return);
QTC_ASSERT(!KitManager::kits().contains(k), return);
delete k;
}
bool KitManager::isLoaded() const
{
return d->m_initialized;
}
QString KitManager::uniqueKitName(const Kit *k, const QString name, const QList<Kit *> &allKits)
{
QStringList nameList;
......@@ -465,20 +471,20 @@ void KitManager::notifyAboutDisplayNameChange(Kit *k)
{
if (!k)
return;
if (m_instance->d->m_kitList.contains(k) && m_instance->d->m_keepDisplayNameUnique)
if (d->m_kitList.contains(k) && d->m_keepDisplayNameUnique)
k->setDisplayName(uniqueKitName(k, k->displayName(), kits()));
int pos = m_instance->d->m_kitList.indexOf(k);
if (pos >= 0 && m_instance->d->m_initialized)
m_instance->d->moveKit(pos);
int pos = d->m_kitList.indexOf(k);
if (pos >= 0 && d->m_initialized)
d->moveKit(pos);
notifyAboutUpdate(k);
}
void KitManager::notifyAboutUpdate(ProjectExplorer::Kit *k)
{
if (!k || !m_instance->isLoaded())
if (!k || !isLoaded())
return;
if (m_instance->d->m_kitList.contains(k))
if (d->m_kitList.contains(k))
emit m_instance->kitUpdated(k);
else
emit m_instance->unmanagedKitUpdated(k);
......@@ -486,7 +492,7 @@ void KitManager::notifyAboutUpdate(ProjectExplorer::Kit *k)
bool KitManager::registerKit(ProjectExplorer::Kit *k)
{
QTC_ASSERT(m_instance->isLoaded(), return false);
QTC_ASSERT(isLoaded(), return false);
if (!k)
return true;
foreach (Kit *current, kits()) {
......@@ -506,7 +512,7 @@ void KitManager::deregisterKit(Kit *k)
{
if (!k || !kits().contains(k))
return;
m_instance->d->m_kitList.removeOne(k);
d->m_kitList.removeOne(k);
if (defaultKit() == k) {
QList<Kit *> stList = kits();
Kit *newDefault = 0;
......@@ -528,7 +534,7 @@ void KitManager::setDefaultKit(Kit *k)
return;
if (k && !kits().contains(k))
return;
m_instance->d->m_defaultKit = k;
d->m_defaultKit = k;
emit m_instance->defaultkitChanged();
}
......@@ -580,7 +586,7 @@ bool KitInformation::isSticky(const Kit *k) const
void KitInformation::notifyAboutUpdate(Kit *k)
{
KitManager::instance()->notifyAboutUpdate(k);
KitManager::notifyAboutUpdate(k);
}
} // namespace ProjectExplorer
......@@ -51,7 +51,6 @@ class KitManager;
namespace Internal {
class KitManagerConfigWidget;
class KitManagerPrivate;
class KitModel;
} // namespace Internal
......@@ -115,12 +114,13 @@ class PROJECTEXPLORER_EXPORT KitManager : public QObject
Q_OBJECT
public:
static KitManager *instance();
static QObject *instance();
~KitManager();
static QList<Kit *> kits(const KitMatcher *m = 0);
static QList<Kit *> kits();
static QList<Kit *> matchingKits(const KitMatcher &matcher);
static Kit *find(const Core::Id &id);
static Kit *find(const KitMatcher *m);
static Kit *find(const KitMatcher &matcher);
static Kit *defaultKit();
static QList<KitInformation *> kitInformation();
......@@ -158,7 +158,6 @@ signals:
private:
explicit KitManager(QObject *parent = 0);
bool isLoaded() const;
static bool setKeepDisplayNameUnique(bool unique);
// Make sure the this is only called after all
......@@ -178,11 +177,6 @@ private:
static void notifyAboutUpdate(ProjectExplorer::Kit *k);
void addKit(Kit *k);
Internal::KitManagerPrivate *const d;
static KitManager *m_instance;
friend class Internal::KitManagerPrivate; // for the restoreToolChains methods
friend class ProjectExplorerPlugin; // for constructor
friend class Kit;
friend class Internal::KitModel;
......
......@@ -87,7 +87,7 @@ KitManagerConfigWidget::KitManagerConfigWidget(Kit *k) :
connect(m_iconButton, SIGNAL(clicked()), this, SLOT(setIcon()));
connect(m_nameEdit, SIGNAL(textChanged(QString)), this, SLOT(setDisplayName()));
KitManager *km = KitManager::instance();
QObject *km = KitManager::instance();
connect(km, SIGNAL(unmanagedKitUpdated(ProjectExplorer::Kit*)),
this, SLOT(workingCopyWasUpdated(ProjectExplorer::Kit*)));
connect(km, SIGNAL(kitUpdated(ProjectExplorer::Kit*)),
......
......@@ -130,7 +130,7 @@ Target::Target(Project *project, Kit *k) :
setDisplayName(d->m_kit->displayName());
setIcon(d->m_kit->icon());
KitManager *km = KitManager::instance();
QObject *km = KitManager::instance();
connect(km, SIGNAL(kitUpdated(ProjectExplorer::Kit*)),
this, SLOT(handleKitUpdates(ProjectExplorer::Kit*)));
connect(km, SIGNAL(kitRemoved(ProjectExplorer::Kit*)),
......
......@@ -50,6 +50,7 @@
#include <QDebug>
using namespace Core;
using namespace ProjectExplorer;
namespace QmlProjectManager {
namespace Internal {
......@@ -377,12 +378,12 @@ bool QmlProject::fromMap(const QVariantMap &map)
if (!activeTarget()) {
// find a kit that matches prerequisites (prefer default one)
Internal::QmlProjectKitMatcher matcher(defaultImport());
QList<ProjectExplorer::Kit*> kits = ProjectExplorer::KitManager::kits(&matcher);
QList<Kit*> kits = KitManager::matchingKits(matcher);
if (!kits.isEmpty()) {
ProjectExplorer::Kit *kit = 0;
if (kits.contains(ProjectExplorer::KitManager::defaultKit())) {
kit = ProjectExplorer::KitManager::defaultKit();
Kit *kit = 0;
if (kits.contains(KitManager::defaultKit())) {
kit = KitManager::defaultKit();
} else {
kit = kits.first();
}
......@@ -392,7 +393,7 @@ bool QmlProject::fromMap(const QVariantMap &map)
// addedTarget calls updateEnabled on the runconfigurations
// which needs to happen after refresh
foreach (ProjectExplorer::Target *t, targets())
foreach (Target *t, targets())
addedTarget(t);
connect(this, SIGNAL(addedTarget(ProjectExplorer::Target*)),
......
......@@ -239,13 +239,13 @@ void BlackBerryConfigurationManager::saveActiveConfigurationNdkEnvPath()
void BlackBerryConfigurationManager::clearInvalidConfigurations()
{
// Deregister invalid auto deteted BlackBerry Kits
foreach (ProjectExplorer::Kit *kit, ProjectExplorer::KitManager::instance()->kits()) {
foreach (Kit *kit, KitManager::kits()) {
if (!kit->isAutoDetected())
continue;
if (ProjectExplorer::DeviceTypeKitInformation::deviceTypeId(kit) == Constants::QNX_BB_OS_TYPE
if (DeviceTypeKitInformation::deviceTypeId(kit) == Constants::QNX_BB_OS_TYPE
&& !kit->isValid())
ProjectExplorer::KitManager::instance()->deregisterKit(kit);
KitManager::deregisterKit(kit);
}
// Remove invalid auto detected BlackBerry qtVerions
......
......@@ -41,6 +41,8 @@
#include <projectexplorer/customwizard/customwizard.h>
#include <coreplugin/editormanager/editormanager.h>
using namespace ProjectExplorer;
namespace Qt4ProjectManager {
AbstractMobileAppWizardDialog::AbstractMobileAppWizardDialog(QWidget *parent,
......@@ -208,13 +210,10 @@ bool AbstractMobileAppWizardDialog::isQtPlatformSelected(const QString &platform
{
QList<Core::Id> selectedKitsList = selectedKits();
QtSupport::QtPlatformKitMatcher matcher(platform);
QList<ProjectExplorer::Kit *> kitsList
= ProjectExplorer::KitManager::kits(&matcher);
foreach (ProjectExplorer::Kit *k, kitsList) {
foreach (Kit *k, KitManager::matchingKits(QtSupport::QtPlatformKitMatcher(platform)))
if (selectedKitsList.contains(k->id()))
return true;
}
return false;
}
......
......@@ -49,6 +49,7 @@
#include <QCoreApplication>
#include <QVariant>
using namespace ProjectExplorer;
using namespace Qt4ProjectManager;
using namespace Qt4ProjectManager::Internal;
......@@ -323,13 +324,10 @@ bool BaseQt4ProjectWizardDialog::isQtPlatformSelected(const QString &platform) c
{
QList<Core::Id> selectedKitList = selectedKits();
QtSupport::QtPlatformKitMatcher matcher(platform);
QList<ProjectExplorer::Kit *> kitList
= ProjectExplorer::KitManager::kits(&matcher);
foreach (ProjectExplorer::Kit *k, kitList) {
foreach (Kit *k, KitManager::matchingKits(QtSupport::QtPlatformKitMatcher(platform)))
if (selectedKitList.contains(k->id()))
return true;
}
return false;
}
......
......@@ -50,6 +50,7 @@
#include <QScrollArea>
#include <QVBoxLayout>
using namespace ProjectExplorer;
using namespace QtSupport;
namespace Qt4ProjectManager {
......@@ -172,7 +173,7 @@ TargetSetupPage::TargetSetupPage(QWidget *parent) :
setTitle(tr("Kit Selection"));
ProjectExplorer::KitManager *km = ProjectExplorer::KitManager::instance();
QObject *km = KitManager::instance();
connect(km, SIGNAL(kitAdded(ProjectExplorer::Kit*)),
this, SLOT(handleKitAddition(ProjectExplorer::Kit*)));
connect(km, SIGNAL(kitRemoved(ProjectExplorer::Kit*)),
......@@ -254,7 +255,9 @@ void TargetSetupPage::setImportSearch(bool b)
void TargetSetupPage::setupWidgets()
{
// Known profiles:
foreach (ProjectExplorer::Kit *k, ProjectExplorer::KitManager::kits(m_requiredMatcher))
QList<Kit *> kits = m_requiredMatcher
? KitManager::matchingKits(*m_requiredMatcher) : KitManager::kits();
foreach (Kit *k, kits)
addWidget(k);
// Setup import widget:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment