summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRolf Eike Beer <kde@opensource.sf-tec.de>2012-02-15 19:53:08 (GMT)
committerRolf Eike Beer <kde@opensource.sf-tec.de>2012-02-15 19:53:08 (GMT)
commit751c40508de14dfc4f756ec6e5388d849d63004f (patch)
tree844f3342c14f11186cf6d3a17097b2e142de12ab
parent109558c512e4b67af94ac6c7983301dde162c13d (diff)
fix crashes on model changes
QAbstractItemModel::changePersistentIndex() is heavily underdocumented, so I probably got it wrong. Use beginResetModel()/endResetModel() to guard "global" changes in the model instead of layoutAboutToBeChanged()/layoutChanged(). This should hopefully get rid of all the spurious crashes deep in the Qt model implementation. BUG:294097 CCBUG:254090 FIXED-IN:4.8.1
-rw-r--r--model/kgpgitemmodel.cpp34
-rw-r--r--model/kgpgitemmodel.h3
2 files changed, 7 insertions, 30 deletions
diff --git a/model/kgpgitemmodel.cpp b/model/kgpgitemmodel.cpp
index a7e0de7..e219e8d 100644
--- a/model/kgpgitemmodel.cpp
+++ b/model/kgpgitemmodel.cpp
@@ -237,10 +237,9 @@ KGpgItemModel::addGroup(const QString &name, const KGpgKeyNode::List &keys)
void
KGpgItemModel::delNode(KGpgNode *node)
{
- emit layoutAboutToBeChanged();
+ beginResetModel();
delete node;
- fixPersistentIndexes();
- emit layoutChanged();
+ endResetModel();
}
void
@@ -378,7 +377,7 @@ KGpgItemModel::refreshKeys(const QStringList &ids)
void
KGpgItemModel::refreshKeyIds(const QStringList &ids)
{
- emit layoutAboutToBeChanged();
+ beginResetModel();
if (ids.isEmpty()) {
for (int i = m_root->getChildCount() - 1; i >= 0; i--) {
KGpgNode *nd = m_root->getChild(i);
@@ -397,8 +396,7 @@ KGpgItemModel::refreshKeyIds(const QStringList &ids)
}
m_root->addKeys(ids);
- fixPersistentIndexes();
- emit layoutChanged();
+ endResetModel();
}
void
@@ -406,10 +404,9 @@ KGpgItemModel::refreshKeyIds(KGpgKeyNode::List &nodes)
{
QStringList ids;
- emit layoutAboutToBeChanged();
+ beginResetModel();
m_root->refreshKeys(nodes);
- fixPersistentIndexes();
- emit layoutChanged();
+ endResetModel();
}
void
@@ -443,25 +440,6 @@ KGpgItemModel::isDefaultKey(const KGpgNode *node) const
}
void
-KGpgItemModel::fixPersistentIndexes()
-{
- foreach (const QModelIndex &idx, persistentIndexList()) {
- if (!idx.isValid())
- continue;
-
- KGpgNode *nd = nodeForIndex(idx);
- int j = rowForNode(nd);
- if (j == idx.row())
- continue;
-
- if (j >= 0)
- changePersistentIndex(idx, createIndex(j, idx.column(), nd));
- else
- changePersistentIndex(idx, QModelIndex());
- }
-}
-
-void
KGpgItemModel::invalidateIndexes(KGpgNode *nd)
{
foreach (const QModelIndex &idx, persistentIndexList()) {
diff --git a/model/kgpgitemmodel.h b/model/kgpgitemmodel.h
index 6776234..b3047fe 100644
--- a/model/kgpgitemmodel.h
+++ b/model/kgpgitemmodel.h
@@ -1,4 +1,4 @@
-/* Copyright 2008 Rolf Eike Beer <kde@opensource.sf-tec.de>
+/* Copyright 2008,2009,2010,2011,2012 Rolf Eike Beer <kde@opensource.sf-tec.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -93,7 +93,6 @@ protected:
void refreshKeyIds(const QStringList &id);
void refreshKeyIds(KGpgKeyNode::List &nodes);
bool isDefaultKey(const KGpgNode *node) const;
- void fixPersistentIndexes();
void updateNodeTrustColor(KGpgExpandableNode *node, const KgpgCore::KgpgKeyTrust trust, const QColor &color);
};