Libkleo

keyrearrangecolumnsproxymodel.cpp
1/* models/keyrearangecolumnsproxymodel.cpp
2
3 This file is part of Kleopatra, the KDE keymanager
4 SPDX-FileCopyrightText: 2016 Bundesamt für Sicherheit in der Informationstechnik
5 SPDX-FileContributor: Intevation GmbH
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9
10#include <config-libkleo.h>
11
12#include "keyrearrangecolumnsproxymodel.h"
13
14#include <libkleo/keygroup.h>
15
16#include <gpgme++/key.h>
17
18using namespace Kleo;
19using namespace GpgME;
20
21KeyRearrangeColumnsProxyModel::KeyRearrangeColumnsProxyModel(QObject *parent)
23 , KeyListModelInterface()
24{
25}
26
27KeyListModelInterface *KeyRearrangeColumnsProxyModel::klm() const
28{
29 auto *ret = dynamic_cast<KeyListModelInterface *>(sourceModel());
30 Q_ASSERT(ret);
31 return ret;
32}
33
34Key KeyRearrangeColumnsProxyModel::key(const QModelIndex &idx) const
35{
36 return klm()->key(mapToSource(idx));
37}
38
39std::vector<GpgME::Key> KeyRearrangeColumnsProxyModel::keys(const QList<QModelIndex> &idxs) const
40{
41 QList<QModelIndex> srcIdxs;
42 srcIdxs.reserve(idxs.count());
43 for (const QModelIndex &idx : idxs) {
44 srcIdxs << mapToSource(idx);
45 }
46 return klm()->keys(srcIdxs);
47}
48
49KeyGroup KeyRearrangeColumnsProxyModel::group(const QModelIndex &idx) const
50{
51 return klm()->group(mapToSource(idx));
52}
53
54QModelIndex KeyRearrangeColumnsProxyModel::index(const GpgME::Key &key) const
55{
56 return mapFromSource(klm()->index(key));
57}
58
59QList<QModelIndex> KeyRearrangeColumnsProxyModel::indexes(const std::vector<GpgME::Key> &keys) const
60{
61 QList<QModelIndex> myIdxs;
62 const QList<QModelIndex> srcIdxs = klm()->indexes(keys);
63 myIdxs.reserve(srcIdxs.count());
64 for (const QModelIndex &idx : srcIdxs) {
65 myIdxs << mapFromSource(idx);
66 }
67 return myIdxs;
68}
69
70QModelIndex KeyRearrangeColumnsProxyModel::index(const KeyGroup &group) const
71{
72 return mapFromSource(klm()->index(group));
73}
74
75void KeyRearrangeColumnsProxyModel::sort(int column, Qt::SortOrder order)
76{
77 const auto fakeIdx = createIndex(0, column);
78 if (!fakeIdx.isValid()) {
79 // Empty model?
81 return;
82 }
83 const auto remappedIdx = mapToSource(fakeIdx);
84 KRearrangeColumnsProxyModel::sort(remappedIdx.column(), order);
85}
QModelIndex mapToSource(const QModelIndex &proxyIndex) const override
QModelIndex mapFromSource(const QModelIndex &sourceIndex) const override
QModelIndex createIndex(int row, int column, void *ptr) const const
virtual void sort(int column, Qt::SortOrder order)
int count(const T &value) const const
void reserve(int alloc)
SortOrder
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sun Feb 25 2024 18:39:42 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.