• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeutils API Reference
  • KDE Home
  • Contact Us
 

kgpg

  • sources
  • kde-4.12
  • kdeutils
  • kgpg
  • model
groupeditproxymodel.cpp
Go to the documentation of this file.
1 /* Copyright 2008,2010,2012,2013 Rolf Eike Beer <kde@opensource.sf-tec.de>
2  *
3  * This program is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU General Public License as
5  * published by the Free Software Foundation; either version 2 of
6  * the License or (at your option) version 3 or any later version
7  * accepted by the membership of KDE e.V. (or its successor approved
8  * by the membership of KDE e.V.), which shall act as a proxy
9  * defined in Section 14 of version 3 of the license.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 #include "groupeditproxymodel.h"
20 #include "model/kgpgitemnode.h"
21 #include "kgpgitemmodel.h"
22 #include "core/kgpgkey.h"
23 
24 #include <KDebug>
25 
26 using namespace KgpgCore;
27 
28 GroupEditProxyModel::GroupEditProxyModel(QObject *parent, const bool &invert, QList<KGpgNode *> *ids, const KgpgCore::KgpgKeyTrust mintrust)
29  : QSortFilterProxyModel(parent),
30  m_model(NULL),
31  m_invert(invert),
32  m_ids(ids),
33  m_mintrust(mintrust)
34 {
35 }
36 
37 void
38 GroupEditProxyModel::setKeyModel(KGpgItemModel *md)
39 {
40  m_model = md;
41  setSourceModel(md);
42 }
43 
44 void
45 GroupEditProxyModel::setMinTrust(const KgpgCore::KgpgKeyTrust mintrust)
46 {
47  m_mintrust = mintrust;
48  invalidate();
49 }
50 
51 bool
52 GroupEditProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
53 {
54  QModelIndex idx = m_model->index(source_row, 0, source_parent);
55  KGpgNode *l = m_model->nodeForIndex(idx);
56 
57  if (l->getType() & ~ITYPE_PAIR)
58  return false;
59 
60  if (l->getTrust() < m_mintrust)
61  return false;
62 
63  const KGpgKeyNode * const lk = l->toKeyNode();
64  for (int i = 0; i < m_ids->count(); i++)
65  if (lk->compareId(m_ids->at(i)->getId()))
66  return !m_invert;
67 
68  return m_invert;
69 }
70 
71 KGpgNode *
72 GroupEditProxyModel::nodeForIndex(const QModelIndex &index) const
73 {
74  return m_model->nodeForIndex(mapToSource(index));
75 }
76 
77 int
78 GroupEditProxyModel::columnCount(const QModelIndex &) const
79 {
80  return 3;
81 }
82 
83 int
84 GroupEditProxyModel::rowCount(const QModelIndex &parent) const
85 {
86  if (parent.column() > 0)
87  return 0;
88  if (parent.isValid())
89  return 0;
90  if (m_model == NULL)
91  return 0;
92  return QSortFilterProxyModel::rowCount(parent);
93 }
94 
95 QVariant
96 GroupEditProxyModel::data(const QModelIndex &index, int role) const
97 {
98  if (!index.isValid() || (index.column() >= 3))
99  return QVariant();
100 
101  if ((role != Qt::ToolTipRole) && (role != Qt::DisplayRole))
102  return QVariant();
103 
104  KGpgNode *nd = m_model->nodeForIndex(mapToSource(index));
105  switch (index.column()) {
106  case 0:
107  if (role == Qt::ToolTipRole)
108  return nd->getNameComment();
109  else
110  return nd->getName();
111  case 1:
112  return nd->getEmail();
113  case 2:
114  if (role == Qt::ToolTipRole)
115  return nd->getId();
116  else
117  return nd->getId().right(8);
118  }
119 
120  return QVariant();
121 }
122 
123 bool
124 GroupEditProxyModel::hasChildren(const QModelIndex &parent) const
125 {
126  if (m_model == NULL)
127  return false;
128  if (parent.column() > 0)
129  return false;
130  return !parent.isValid();
131 }
132 
133 QVariant
134 GroupEditProxyModel::headerData(int section, Qt::Orientation orientation, int role) const
135 {
136  if (role != Qt::DisplayRole)
137  return QVariant();
138 
139  if (orientation != Qt::Horizontal)
140  return QVariant();
141 
142  if (m_model == NULL)
143  return QVariant();
144 
145  switch (section) {
146  case 0: return m_model->headerData(KEYCOLUMN_NAME, orientation, role);
147  case 1: return m_model->headerData(KEYCOLUMN_EMAIL, orientation, role);
148  case 2: return m_model->headerData(KEYCOLUMN_ID, orientation, role);
149  default: return QVariant();
150  }
151 }
KGpgItemModel
Definition: kgpgitemmodel.h:44
GroupEditProxyModel::filterAcceptsRow
virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
Definition: groupeditproxymodel.cpp:52
GroupEditProxyModel::data
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Definition: groupeditproxymodel.cpp:96
KGpgNode::getNameComment
virtual QString getNameComment() const
Definition: KGpgNode.cpp:51
GroupEditProxyModel::setKeyModel
void setKeyModel(KGpgItemModel *)
Definition: groupeditproxymodel.cpp:38
GroupEditProxyModel::GroupEditProxyModel
GroupEditProxyModel(QObject *parent, const bool &invert, QList< KGpgNode * > *ids, const KgpgCore::KgpgKeyTrust mintrust=KgpgCore::TRUST_FULL)
Definition: groupeditproxymodel.cpp:28
kgpgkey.h
QObject
GroupEditProxyModel::hasChildren
virtual bool hasChildren(const QModelIndex &parent) const
Definition: groupeditproxymodel.cpp:124
KGpgKeyNode
A public key with or without corresponding secret key.
Definition: KGpgKeyNode.h:33
KGpgNode::getType
virtual KgpgCore::KgpgItemType getType() const =0
Returns the item type of this object.
GroupEditProxyModel::headerData
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Definition: groupeditproxymodel.cpp:134
kgpgitemmodel.h
KGpgItemModel::index
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Definition: kgpgitemmodel.cpp:44
kgpgitemnode.h
groupeditproxymodel.h
GroupEditProxyModel::rowCount
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: groupeditproxymodel.cpp:84
KGpgNode
The abstract base class for all classes representing keyring data.
Definition: KGpgNode.h:42
KgpgCore::ITYPE_PAIR
key pair
Definition: kgpgkey.h:112
GroupEditProxyModel::nodeForIndex
KGpgNode * nodeForIndex(const QModelIndex &index) const
Definition: groupeditproxymodel.cpp:72
KGpgItemModel::headerData
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Definition: kgpgitemmodel.cpp:362
KGpgNode::toKeyNode
KGpgKeyNode * toKeyNode()
Definition: KGpgNode.cpp:94
KGpgNode::getId
virtual QString getId() const
Definition: KGpgNode.cpp:318
GroupEditProxyModel::setMinTrust
void setMinTrust(const KgpgCore::KgpgKeyTrust mintrust)
Definition: groupeditproxymodel.cpp:45
KGpgNode::getEmail
virtual QString getEmail() const
Definition: KGpgNode.cpp:300
KGpgItemModel::nodeForIndex
KGpgNode * nodeForIndex(const QModelIndex &index) const
Definition: kgpgitemmodel.cpp:230
KGpgNode::getName
virtual QString getName() const
Definition: KGpgNode.cpp:294
KGpgKeyNode::compareId
bool compareId(const QString &other) const
compare the id of this node to the given other node
Definition: KGpgKeyNode.cpp:333
GroupEditProxyModel::columnCount
virtual int columnCount(const QModelIndex &) const
Definition: groupeditproxymodel.cpp:78
KGpgNode::getTrust
virtual KgpgCore::KgpgKeyTrust getTrust() const
Definition: KGpgNode.cpp:282
KEYCOLUMN_EMAIL
#define KEYCOLUMN_EMAIL
Definition: kgpgitemmodel.h:31
KEYCOLUMN_NAME
#define KEYCOLUMN_NAME
Definition: kgpgitemmodel.h:30
QList
KEYCOLUMN_ID
#define KEYCOLUMN_ID
Definition: kgpgitemmodel.h:36
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:07:51 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kgpg

Skip menu "kgpg"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeutils API Reference

Skip menu "kdeutils API Reference"
  • ark
  • filelight
  • kcalc
  • kcharselect
  • kdf
  • kfloppy
  • kgpg
  • kremotecontrol
  • ktimer
  • kwallet
  • superkaramba
  • sweeper

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal