Commit 64cc15bc authored by Daniel Teske's avatar Daniel Teske

Kit: Fix crash on removing android kits that were autodetected

To reproduce:
In the Android settings, enabled "Automatically create kits"
  -> This creates kits with autodetected set to true
Switch to the kits page to get the KitPage filled, those kits
  now appear under the autodetected node.
Switch to the Android settings and disable "Automatically create kits",
  -> This doesn't want to delete the old kits, to not throw away user
     settings, so the kits are marked as manual by calling setAutoDetected
Switch to the Kit page and notice the kits still listed under the
  autodetected node. Clicking apply enables the remove button and on
  removing Creator crashes.

Add the necessary signal emissions to setAutoDetected and several other
methods and fix the KitModel to cope with changes to autodetected.

Task-number: QTCREATORBUG-13736
Change-Id: I3d0ff247a6bfff8ace53df8535749db5c736d54b
Reviewed-by: default avatarTobias Hunger <tobias.hunger@theqtcompany.com>
parent 8211a849
......@@ -582,16 +582,19 @@ QString Kit::toHtml(const QList<Task> &additional) const
void Kit::setAutoDetected(bool detected)
{
d->m_autodetected = detected;
kitUpdated();
}
void Kit::setAutoDetectionSource(const QString &autoDetectionSource)
{
d->m_autoDetectionSource = autoDetectionSource;
kitUpdated();
}
void Kit::setSdkProvided(bool sdkProvided)
{
d->m_sdkProvided = sdkProvided;
kitUpdated();
}
void Kit::makeSticky()
......@@ -608,11 +611,13 @@ void Kit::setSticky(Core::Id id, bool b)
d->m_sticky.insert(id);
else
d->m_sticky.remove(id);
kitUpdated();
}
void Kit::makeUnSticky()
{
d->m_sticky.clear();
kitUpdated();
}
void Kit::setMutable(Id id, bool b)
......@@ -621,6 +626,7 @@ void Kit::setMutable(Id id, bool b)
d->m_mutable.insert(id);
else
d->m_mutable.remove(id);
kitUpdated();
}
bool Kit::isMutable(Id id) const
......
......@@ -354,8 +354,11 @@ void KitManagerConfigWidget::workingCopyWasUpdated(Kit *k)
void KitManagerConfigWidget::kitWasUpdated(Kit *k)
{
if (m_kit == k)
if (m_kit == k) {
bool emitSignal = m_kit->isAutoDetected() != m_modifiedKit->isAutoDetected();
discard();
emit isAutoDetectedChanged();
}
updateVisibility();
}
......
......@@ -77,6 +77,7 @@ public:
signals:
void dirty();
void isAutoDetectedChanged();
private slots:
void setIcon();
......
......@@ -279,6 +279,31 @@ void KitModel::setDirty()
}
}
void KitModel::isAutoDetectedChanged()
{
KitManagerConfigWidget *w = qobject_cast<KitManagerConfigWidget *>(sender());
int idx = -1;
idx = Utils::indexOf(m_manualRoot->childNodes, [w](KitNode *node) { return node->widget == w; });
KitNode *oldParent = 0;
KitNode *newParent = w->workingCopy()->isAutoDetected() ? m_autoRoot : m_manualRoot;
if (idx != -1) {
oldParent = m_manualRoot;
} else {
idx = Utils::indexOf(m_autoRoot->childNodes, [w](KitNode *node) { return node->widget == w; });
if (idx != -1) {
oldParent = m_autoRoot;
}
}
if (oldParent && oldParent != newParent) {
beginMoveRows(index(oldParent), idx, idx, index(newParent), newParent->childNodes.size());
KitNode *n = oldParent->childNodes.takeAt(idx);
n->parent = newParent;
newParent->childNodes.append(n);
endMoveRows();
}
}
void KitModel::validateKitNames()
{
QList<KitNode *> nodes = m_manualRoot->childNodes;
......@@ -395,6 +420,9 @@ KitNode *KitModel::createNode(KitNode *parent, Kit *k)
KitNode *node = new KitNode(parent, k);
m_parentLayout->addWidget(node->widget);
connect(node->widget, SIGNAL(dirty()), this, SLOT(setDirty()));
connect(node->widget, SIGNAL(isAutoDetectedChanged()),
this, SLOT(isAutoDetectedChanged()));
return node;
}
......
......@@ -97,6 +97,7 @@ private slots:
void changeDefaultKit();
void setDirty();
void validateKitNames();
void isAutoDetectedChanged();
private:
QModelIndex index(KitNode *, int column = 0) const;
......
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