diff options
Diffstat (limited to 'src/ui/widgets/KeyList.cpp')
-rw-r--r-- | src/ui/widgets/KeyList.cpp | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/src/ui/widgets/KeyList.cpp b/src/ui/widgets/KeyList.cpp index d8e4a094..2082bbc9 100644 --- a/src/ui/widgets/KeyList.cpp +++ b/src/ui/widgets/KeyList.cpp @@ -42,6 +42,7 @@ KeyList::KeyList(GpgME::GpgContext *ctx, mKeyList->setShowGrid(false); mKeyList->sortByColumn(2, Qt::AscendingOrder); mKeyList->setSelectionBehavior(QAbstractItemView::SelectRows); + mKeyList->setSelectionMode( QAbstractItemView::SingleSelection ); // tableitems not editable mKeyList->setEditTriggers(QAbstractItemView::NoEditTriggers); @@ -105,16 +106,24 @@ void KeyList::slotRefresh() int row_count = 0; while (it != keys.end()) { + if(mFilter != nullptr) { + if(!mFilter(*it)) { + it = keys.erase(it); + continue; + } + } if(!excluded_key_ids.isEmpty()){ - bool if_find = false; - for(const auto &key_id : excluded_key_ids) { - if(it->id == key_id) { - it = keys.erase(it); - if_find = true; - break; - } + + auto iterator = std::find_if(excluded_key_ids.begin(), excluded_key_ids.end(), + [it] (const auto &key_id) -> bool { + if(it->id == key_id) return true; + else return false; + }); + + if(iterator != excluded_key_ids.end()) { + it = keys.erase(it); + continue; } - if(if_find) continue; } if (mSelectType == KeyListRow::ONLY_SECRET_KEY && !it->is_private_key) { it = keys.erase(it); @@ -423,3 +432,7 @@ void KeyList::setExcludeKeys(std::initializer_list<QString> key_ids) { excluded_key_ids.push_back(key_id); } } + +void KeyList::setFilter(std::function<bool(const GpgKey &)> filter) { + this->mFilter = filter; +} |