summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRolf Eike Beer <kde@opensource.sf-tec.de>2012-02-14 18:37:23 (GMT)
committerRolf Eike Beer <kde@opensource.sf-tec.de>2012-02-15 19:26:37 (GMT)
commitc12a848ed88f99978fdca1bfdd2e4d7c01887edd (patch)
tree9ec198f173a881033c254552c87804dc0d6b87b2
parent622ecfca7ed0ab15acc7cf43f7076062e0c6ffaf (diff)
more efficient refreshing when modifying groups
Modifications to groups do not have any side effects in the model (i.e. no other nodes change when a group changes), so it is overkill to tell views that the whole model layout has changed. Just announce that lines were added or removed.
-rw-r--r--core/KGpgRootNode.cpp10
-rw-r--r--core/KGpgRootNode.h5
-rw-r--r--model/kgpgitemmodel.cpp52
3 files changed, 43 insertions, 24 deletions
diff --git a/core/KGpgRootNode.cpp b/core/KGpgRootNode.cpp
index 9892c69..0ab09a6 100644
--- a/core/KGpgRootNode.cpp
+++ b/core/KGpgRootNode.cpp
@@ -29,7 +29,7 @@ KGpgRootNode::KGpgRootNode(KGpgItemModel *model)
m_deleting(false)
{
m_model = model;
- addGroups();
+ addGroups(KgpgInterface::getGpgGroupNames(KGpgSettings::gpgConfigPath()));
}
KGpgRootNode::~KGpgRootNode()
@@ -49,12 +49,10 @@ KGpgRootNode::getType() const
}
void
-KGpgRootNode::addGroups()
+KGpgRootNode::addGroups(const QStringList &groups)
{
- const QStringList groups = KgpgInterface::getGpgGroupNames(KGpgSettings::gpgConfigPath());
-
- for (QStringList::const_iterator it = groups.begin(); it != groups.end(); ++it)
- new KGpgGroupNode(this, QString(*it));
+ foreach (const QString &groupName, groups)
+ new KGpgGroupNode(this, groupName);
}
void
diff --git a/core/KGpgRootNode.h b/core/KGpgRootNode.h
index c0dfcef..97c597c 100644
--- a/core/KGpgRootNode.h
+++ b/core/KGpgRootNode.h
@@ -55,9 +55,10 @@ public:
virtual KgpgCore::KgpgItemType getType() const;
/**
- * Read the group definitions from GnuPG config file
+ * Create new group nodes
+ * @param groups list of group names to create
*/
- void addGroups();
+ void addGroups(const QStringList &groups);
void addKeys(const QStringList &ids = QStringList());
void refreshKeys(KGpgKeyNode::List nodes);
/**
diff --git a/model/kgpgitemmodel.cpp b/model/kgpgitemmodel.cpp
index 53e37ea..cbc3432 100644
--- a/model/kgpgitemmodel.cpp
+++ b/model/kgpgitemmodel.cpp
@@ -221,11 +221,13 @@ KGpgGroupNode *
KGpgItemModel::addGroup(const QString &name, const KGpgKeyNode::List &keys)
{
KGpgGroupNode *nd;
+ const int cIndex = m_root->getChildCount(); // row of the new node
- emit layoutAboutToBeChanged();
+ emit beginInsertRows(QModelIndex(), cIndex, cIndex);
nd = new KGpgGroupNode(m_root, name, keys);
- fixPersistentIndexes();
- emit layoutChanged();
+ emit endInsertRows();
+
+ Q_ASSERT(m_root->getChildIndex(nd) == cIndex);
return nd;
}
@@ -242,7 +244,7 @@ KGpgItemModel::delNode(KGpgNode *node)
void
KGpgItemModel::changeGroup(KGpgGroupNode *node, const QList<KGpgNode *> &keys)
{
- emit layoutAboutToBeChanged();
+ const QModelIndex gIndex = nodeIndex(node);
for (int i = node->getChildCount() - 1; i >= 0; i--) {
bool found = false;
@@ -253,22 +255,29 @@ KGpgItemModel::changeGroup(KGpgGroupNode *node, const QList<KGpgNode *> &keys)
}
if (found)
continue;
+
+ beginRemoveRows(gIndex, i, i);
delete node->getChild(i);
+ endRemoveRows();
}
+ int cnt = node->getChildCount();
+
for (int i = 0; i < keys.count(); i++) {
bool found = false;
- for (int j = 0; j < node->getChildCount(); j++) {
+ for (int j = 0; j < cnt; j++) {
found = (node->getChild(j)->getId() == keys.at(i)->getId());
if (found)
break;
}
if (found)
continue;
+
+ beginInsertRows(gIndex, cnt, cnt);
new KGpgGroupMemberNode(node, keys.at(i)->toKeyNode());
+ endInsertRows();
+ cnt++;
}
- fixPersistentIndexes();
- emit layoutChanged();
}
void
@@ -276,10 +285,12 @@ KGpgItemModel::deleteFromGroup(KGpgGroupNode *group, KGpgGroupMemberNode *member
{
Q_ASSERT(group == member->getParentKeyNode());
- emit layoutAboutToBeChanged();
+ const int childRow = group->getChildIndex(member);
+ const QModelIndex pIndex = nodeIndex(group);
+
+ emit beginRemoveRows(pIndex, childRow, childRow);
delete member;
- fixPersistentIndexes();
- emit layoutChanged();
+ emit endRemoveRows();
}
QVariant
@@ -402,16 +413,25 @@ KGpgItemModel::refreshKeyIds(KGpgKeyNode::List &nodes)
void
KGpgItemModel::refreshGroups()
{
- emit layoutAboutToBeChanged();
for (int i = m_root->getChildCount() - 1; i >= 0; i--) {
KGpgNode *nd = m_root->getChild(i);
- if (nd->getType() == ITYPE_GROUP)
- delete nd;
+ if (nd->getType() != ITYPE_GROUP)
+ continue;
+
+ beginRemoveRows(QModelIndex(), i, i);
+ delete nd;
+ endRemoveRows();
}
- m_root->addGroups();
- fixPersistentIndexes();
- emit layoutChanged();
+ const QStringList groups = KgpgInterface::getGpgGroupNames(KGpgSettings::gpgConfigPath());
+
+ if (groups.isEmpty())
+ return;
+
+ const int oldCount = m_root->getChildCount();
+ beginInsertRows(QModelIndex(), oldCount, oldCount + groups.count());
+ m_root->addGroups(groups);
+ endInsertRows();
}
bool