Libkleo

keylistmodel.h
1/* -*- mode: c++; c-basic-offset:4 -*-
2 models/keylistmodel.h
3
4 This file is part of libkleopatra, the KDE keymanagement library
5 SPDX-FileCopyrightText: 2007 Klarälvdalens Datakonsult AB
6 SPDX-FileCopyrightText: 2021 g10 Code GmbH
7 SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>
8
9 SPDX-License-Identifier: GPL-2.0-or-later
10*/
11
12#pragma once
13
14#include "keylist.h"
15#include "keylistmodelinterface.h"
16#include "kleo_export.h"
17
18#include <Libkleo/KeyGroup>
19
20#include <QAbstractItemModel>
21
22#include <vector>
23
24namespace GpgME
25{
26class Key;
27}
28
29namespace Kleo
30{
31
32class KLEO_EXPORT DragHandler
33{
34public:
35 virtual ~DragHandler()
36 {
37 }
38 virtual QMimeData *mimeData(const QModelIndexList &indexes) const = 0;
39 virtual Qt::ItemFlags flags(const QModelIndex &index) const = 0;
40 virtual QStringList mimeTypes() const = 0;
41};
42
43class KLEO_EXPORT AbstractKeyListModel : public QAbstractItemModel, public KeyListModelInterface
44{
45 Q_OBJECT
46public:
47 enum ItemType {
48 // clang-format off
49 Keys = 0x01,
50 Groups = 0x02,
51 All = Keys | Groups,
52 // clang-format on
53 };
54 Q_DECLARE_FLAGS(ItemTypes, ItemType)
55
56 explicit AbstractKeyListModel(QObject *parent = nullptr);
57 ~AbstractKeyListModel() override;
58
59 static AbstractKeyListModel *createFlatKeyListModel(QObject *parent = nullptr);
60 static AbstractKeyListModel *createHierarchicalKeyListModel(QObject *parent = nullptr);
61
62 GpgME::Key key(const QModelIndex &idx) const override;
63 std::vector<GpgME::Key> keys(const QList<QModelIndex> &indexes) const override;
64
65 KeyGroup group(const QModelIndex &idx) const override;
66
68 QModelIndex index(const GpgME::Key &key) const override;
69 QModelIndex index(const GpgME::Key &key, int col) const;
70 QList<QModelIndex> indexes(const std::vector<GpgME::Key> &keys) const override;
71
72 QModelIndex index(const KeyGroup &group) const override;
73 QModelIndex index(const KeyGroup &group, int col) const;
74
75 void setDragHandler(const std::shared_ptr<DragHandler> &dragHandler);
76
77Q_SIGNALS:
78 void rowAboutToBeMoved(const QModelIndex &old_parent, int old_row);
79 void rowMoved(const QModelIndex &new_parent, int new_row);
80
81public Q_SLOTS:
82 // extraOrigins is a list of origins that will be considered if the origin in the key is OriginUnknown. The indexes of keys and extraOrigins must match.
83 void setKeys(const std::vector<GpgME::Key> &keys, const std::vector<GpgME::Key::Origin> &extraOrigins = {});
84 /* Set this to set all or only secret keys from the keycache. */
85 void useKeyCache(bool value, Kleo::KeyList::Options options);
86 QModelIndex addKey(const GpgME::Key &key);
87 QList<QModelIndex> addKeys(const std::vector<GpgME::Key> &keys);
88 void removeKey(const GpgME::Key &key);
89
90 void setGroups(const std::vector<KeyGroup> &groups);
91 QModelIndex addGroup(const Kleo::KeyGroup &group);
92 bool removeGroup(const Kleo::KeyGroup &group);
93
95
96public:
97 int columnCount(const QModelIndex &pidx) const override;
98 QVariant headerData(int section, Qt::Orientation o, int role = Qt::DisplayRole) const override;
99 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
100 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
101
102 /**
103 * defines which information is displayed in tooltips
104 * see Kleo::Formatting::ToolTipOption
105 */
106 int toolTipOptions() const;
107
108 void setToolTipOptions(int opts);
109
110 /**
111 * Set the keys to use for KeyListModelInterface::Remark column
112 * to obtain remarks from this keys signature notations.
113 * Needs at least GpgME 1.14 to work properly. Remarks are
114 * joined by a semicolon and a space. */
115 void setRemarkKeys(const std::vector<GpgME::Key> &remarkKeys);
116 std::vector<GpgME::Key> remarkKeys() const;
117
118 Qt::ItemFlags flags(const QModelIndex &index) const override;
119 QStringList mimeTypes() const override;
120 QMimeData *mimeData(const QModelIndexList &indexes) const override;
121
122protected:
123 bool modelResetInProgress();
124
125private:
126 QVariant data(const GpgME::Key &key, int row, int column, int role) const;
127 QVariant data(const KeyGroup &group, int column, int role) const;
128
129 virtual GpgME::Key doMapToKey(const QModelIndex &index) const = 0;
130 virtual QModelIndex doMapFromKey(const GpgME::Key &key, int column) const = 0;
131 virtual QList<QModelIndex> doAddKeys(const std::vector<GpgME::Key> &keys) = 0;
132 virtual void doRemoveKey(const GpgME::Key &key) = 0;
133
134 virtual KeyGroup doMapToGroup(const QModelIndex &index) const = 0;
135 virtual QModelIndex doMapFromGroup(const KeyGroup &group, int column) const = 0;
136 virtual void doSetGroups(const std::vector<KeyGroup> &groups) = 0;
137 virtual QModelIndex doAddGroup(const KeyGroup &group) = 0;
138 virtual bool doSetGroupData(const QModelIndex &index, const KeyGroup &group) = 0;
139 virtual bool doRemoveGroup(const KeyGroup &group) = 0;
140
141 virtual void doClear(ItemTypes types) = 0;
142
143private:
144 class Private;
146};
147
148Q_DECLARE_OPERATORS_FOR_FLAGS(AbstractKeyListModel::ItemTypes)
149
150}
ItemType
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const=0
DisplayRole
typedef ItemFlags
Orientation
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:56:14 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.