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 "keyrearrangecolumnsproxymodel.h"
11 
12 #include "kleo/keygroup.h"
13 
14 #include <gpgme++/key.h>
15 
16 using namespace Kleo;
17 using namespace GpgME;
18 
19 KeyRearrangeColumnsProxyModel::KeyRearrangeColumnsProxyModel(QObject *parent) :
21  KeyListModelInterface()
22 {
23 
24 }
25 
26 KeyListModelInterface *KeyRearrangeColumnsProxyModel::klm() const
27 {
28  auto *ret = dynamic_cast<KeyListModelInterface *>(sourceModel());
29  Q_ASSERT(ret);
30  return ret;
31 }
32 
33 Key KeyRearrangeColumnsProxyModel::key(const QModelIndex &idx) const
34 {
35  return klm()->key(mapToSource(idx));
36 }
37 
38 std::vector<GpgME::Key> KeyRearrangeColumnsProxyModel::keys(const QList<QModelIndex> &idxs) const
39 {
40  QList<QModelIndex> srcIdxs;
41  srcIdxs.reserve(idxs.count());
42  for (const QModelIndex &idx : idxs) {
43  srcIdxs << mapToSource(idx);
44  }
45  return klm()->keys(srcIdxs);
46 }
47 
48 KeyGroup KeyRearrangeColumnsProxyModel::group(const QModelIndex &idx) const
49 {
50  return klm()->group(mapToSource(idx));
51 }
52 
53 QModelIndex KeyRearrangeColumnsProxyModel::index(const GpgME::Key &key) const
54 {
55  return mapFromSource(klm()->index(key));
56 }
57 
58 QList<QModelIndex> KeyRearrangeColumnsProxyModel::indexes(const std::vector<GpgME::Key> &keys) const
59 {
60  QList<QModelIndex> myIdxs;
61  const QList <QModelIndex> srcIdxs = klm()->indexes(keys);
62  myIdxs.reserve(srcIdxs.count());
63  for (const QModelIndex &idx : srcIdxs) {
64  myIdxs << mapFromSource(idx);
65  }
66  return myIdxs;
67 }
68 
69 QModelIndex KeyRearrangeColumnsProxyModel::index(const KeyGroup &group) const
70 {
71  return mapFromSource(klm()->index(group));
72 }
73 
74 void KeyRearrangeColumnsProxyModel::sort(int column, Qt::SortOrder order)
75 {
76  const auto fakeIdx = createIndex(0, column);
77  if (!fakeIdx.isValid()) {
78  // Empty model?
79  KRearrangeColumnsProxyModel::sort(column, order);
80  return;
81  }
82  const auto remappedIdx = mapToSource(fakeIdx);
83  KRearrangeColumnsProxyModel::sort(remappedIdx.column(), order);
84 }
void reserve(int alloc)
int count(const T &value) const const
SortOrder
virtual void sort(int column, Qt::SortOrder order) override
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Dec 4 2021 23:16:32 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.