Commit b8753c24 authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Only clear state related to keys when setting or removing keys

GnuPG-bug-id: 5175, 5238
parent 0ee0a52b
......@@ -167,7 +167,7 @@ QModelIndex AbstractKeyListModel::index(const KeyGroup &group, int col) const
void AbstractKeyListModel::setKeys(const std::vector<Key> &keys)
{
clear();
clear(Keys);
addKeys(keys);
}
......@@ -199,12 +199,14 @@ QList<QModelIndex> AbstractKeyListModel::addKeys(const std::vector<Key> &keys)
return doAddKeys(sorted);
}
void AbstractKeyListModel::clear()
void AbstractKeyListModel::clear(ItemTypes types)
{
beginResetModel();
doClear();
d->prettyEMailCache.clear();
d->remarksCache.clear();
doClear(types);
if (types & Keys) {
d->prettyEMailCache.clear();
d->remarksCache.clear();
}
endResetModel();
}
......@@ -421,8 +423,11 @@ private:
KeyGroup doMapToGroup(const QModelIndex &index) const override;
QModelIndex doMapFromGroup(const KeyGroup &group, int column) const override;
void doClear() override {
mKeysByFingerprint.clear();
void doClear(ItemTypes types) override
{
if (types & Keys) {
mKeysByFingerprint.clear();
}
}
private:
......@@ -455,11 +460,14 @@ private:
KeyGroup doMapToGroup(const QModelIndex &index) const override;
QModelIndex doMapFromGroup(const KeyGroup &group, int column) const override;
void doClear() override {
mTopLevels.clear();
mKeysByFingerprint.clear();
mKeysByExistingParent.clear();
mKeysByNonExistingParent.clear();
void doClear(ItemTypes types) override
{
if (types & Keys) {
mTopLevels.clear();
mKeysByFingerprint.clear();
mKeysByExistingParent.clear();
mKeysByNonExistingParent.clear();
}
}
private:
......@@ -937,7 +945,7 @@ void HierarchicalKeyListModel::doRemoveKey(const Key &key)
keys.erase(it);
// FIXME for simplicity, we just clear the model and re-add all keys minus the removed one. This is suboptimal,
// but acceptable given that deletion of non-leave nodes is rather rare.
clear();
clear(Keys);
addKeys(keys);
return;
}
......
......@@ -33,6 +33,13 @@ class KLEO_EXPORT AbstractKeyListModel : public QAbstractItemModel
{
Q_OBJECT
public:
enum ItemType {
Keys = 0x01,
Groups = 0x02,
All = Keys | Groups
};
Q_DECLARE_FLAGS(ItemTypes, ItemType)
explicit AbstractKeyListModel(QObject *parent = nullptr);
~AbstractKeyListModel() override;
......@@ -63,7 +70,8 @@ public Q_SLOTS:
QModelIndex addKey(const GpgME::Key &key);
QList<QModelIndex> addKeys(const std::vector<GpgME::Key> &keys);
void removeKey(const GpgME::Key &key);
void clear();
void clear(ItemTypes types = All);
public:
int columnCount(const QModelIndex &pidx) const override;
......@@ -95,7 +103,7 @@ private:
virtual KeyGroup doMapToGroup(const QModelIndex &index) const = 0;
virtual QModelIndex doMapFromGroup(const KeyGroup &group, int column) const = 0;
virtual void doClear() = 0;
virtual void doClear(ItemTypes types) = 0;
private:
class Private;
......@@ -104,4 +112,6 @@ private:
}
Q_DECLARE_OPERATORS_FOR_FLAGS(Kleo::AbstractKeyListModel::ItemTypes)
#endif /* __KLEOPATRA_MODELS_KEYLISTMODEL_H__ */
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