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 void setKeys(const std::vector<GpgME::Key> &keys);
83 /* Set this to set all or only secret keys from the keycache. */
84 void useKeyCache(bool value, Kleo::KeyList::Options options);
85 QModelIndex addKey(const GpgME::Key &key);
86 QList<QModelIndex> addKeys(const std::vector<GpgME::Key> &keys);
87 void removeKey(const GpgME::Key &key);
88
89 void setGroups(const std::vector<KeyGroup> &groups);
90 QModelIndex addGroup(const Kleo::KeyGroup &group);
91 bool removeGroup(const Kleo::KeyGroup &group);
92
94
95public:
96 int columnCount(const QModelIndex &pidx) const override;
97 QVariant headerData(int section, Qt::Orientation o, int role = Qt::DisplayRole) const override;
98 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
99 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
100
101 /**
102 * defines which information is displayed in tooltips
103 * see Kleo::Formatting::ToolTipOption
104 */
105 int toolTipOptions() const;
106
107 void setToolTipOptions(int opts);
108
109 /**
110 * Set the keys to use for KeyListModelInterface::Remark column
111 * to obtain remarks from this keys signature notations.
112 * Needs at least GpgME 1.14 to work properly. Remarks are
113 * joined by a semicolon and a space. */
114 void setRemarkKeys(const std::vector<GpgME::Key> &remarkKeys);
115 std::vector<GpgME::Key> remarkKeys() const;
116
117 Qt::ItemFlags flags(const QModelIndex &index) const override;
118 QStringList mimeTypes() const override;
119 QMimeData *mimeData(const QModelIndexList &indexes) const override;
120
121protected:
122 bool modelResetInProgress();
123
124private:
125 QVariant data(const GpgME::Key &key, int column, int role) const;
126 QVariant data(const KeyGroup &group, int column, int role) const;
127
128 virtual GpgME::Key doMapToKey(const QModelIndex &index) const = 0;
129 virtual QModelIndex doMapFromKey(const GpgME::Key &key, int column) const = 0;
130 virtual QList<QModelIndex> doAddKeys(const std::vector<GpgME::Key> &keys) = 0;
131 virtual void doRemoveKey(const GpgME::Key &key) = 0;
132
133 virtual KeyGroup doMapToGroup(const QModelIndex &index) const = 0;
134 virtual QModelIndex doMapFromGroup(const KeyGroup &group, int column) const = 0;
135 virtual void doSetGroups(const std::vector<KeyGroup> &groups) = 0;
136 virtual QModelIndex doAddGroup(const KeyGroup &group) = 0;
137 virtual bool doSetGroupData(const QModelIndex &index, const KeyGroup &group) = 0;
138 virtual bool doRemoveGroup(const KeyGroup &group) = 0;
139
140 virtual void doClear(ItemTypes types) = 0;
141
142private:
143 class Private;
145};
146
147}
148
149Q_DECLARE_OPERATORS_FOR_FLAGS(Kleo::AbstractKeyListModel::ItemTypes)
KGuiItem clear()
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 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.