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

KitMatcher: Make sure matcher function is properly initialized

This fixes some crashes in the TargetSetupPage and other places.

Also remove isValid method again. It was introduced to fix the same
crash that this patch also addresses, but introduces a bit more
complexity than this approach.

Change-Id: Iee80a2baffb2854b6fad8931d23a1da6d218f919
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
parent 4a60aa7f
......@@ -106,9 +106,9 @@ class PROJECTEXPLORER_EXPORT KitMatcher
{
public:
typedef std::function<bool(const Kit *)> Matcher;
KitMatcher() : m_matcher([](const Kit *k) -> bool { Q_UNUSED(k); return true; }) {}
KitMatcher(const Matcher &m) : m_matcher(m) {}
bool isValid() const { return !!m_matcher; }
bool matches(const Kit *kit) const { return m_matcher(kit); }
private:
......
......@@ -102,9 +102,7 @@ public:
ProjectPrivate::ProjectPrivate() :
m_activeTarget(0),
m_editorConfiguration(new EditorConfiguration()),
m_accessor(0),
m_requiredKitMatcher([](const Kit*) { return true; }),
m_preferredKitMatcher([](const Kit*) { return true; })
m_accessor(0)
{ }
ProjectPrivate::~ProjectPrivate()
......
......@@ -144,8 +144,6 @@ using namespace Internal;
TargetSetupPage::TargetSetupPage(QWidget *parent) :
QWizardPage(parent),
m_requiredMatcher(KitMatcher::Matcher()),
m_preferredMatcher(KitMatcher::Matcher()),
m_importer(0),
m_baseLayout(0),
m_firstWidget(0),
......@@ -259,10 +257,7 @@ void TargetSetupPage::setupWidgets()
{
// Known profiles:
QList<Kit *> kitList;
if (m_requiredMatcher.isValid())
kitList = KitManager::matchingKits(m_requiredMatcher);
else
kitList = KitManager::kits();
kitList = KitManager::matchingKits(m_requiredMatcher);
foreach (Kit *k, kitList)
addWidget(k);
......@@ -376,7 +371,7 @@ void TargetSetupPage::handleKitUpdate(Kit *k)
TargetSetupWidget *widget = m_widgets.value(k->id());
bool acceptable = !m_requiredMatcher.isValid() || m_requiredMatcher.matches(k);
bool acceptable = m_requiredMatcher.matches(k);
if (widget && !acceptable)
removeWidget(k);
......@@ -512,7 +507,7 @@ void TargetSetupPage::removeWidget(Kit *k)
TargetSetupWidget *TargetSetupPage::addWidget(Kit *k)
{
if (!k || (m_requiredMatcher.isValid() && !m_requiredMatcher.matches(k)))
if (!k || !m_requiredMatcher.matches(k))
return 0;
IBuildConfigurationFactory *factory
......@@ -530,7 +525,7 @@ TargetSetupWidget *TargetSetupPage::addWidget(Kit *k)
m_baseLayout->removeWidget(widget);
m_baseLayout->removeItem(m_spacer);
widget->setKitSelected(m_preferredMatcher.isValid() && m_preferredMatcher.matches(k));
widget->setKitSelected(m_preferredMatcher.matches(k));
m_widgets.insert(k->id(), widget);
connect(widget, SIGNAL(selectedToggled()),
this, SLOT(kitSelectionChanged()));
......
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