groupeditproxymodel.cpp 2 KB
Newer Older
1
2
3
4
5
6
#include "groupeditproxymodel.h"
#include "kgpgitemnode.h"
#include "kgpgitemmodel.h"
#include "core/kgpgkey.h"

#include <KDebug>
7
#include <KLocale>
8
9
10
11

using namespace KgpgCore;

GroupEditProxyModel::GroupEditProxyModel(QObject *parent, const bool &invert, QList<KGpgNode *> *ids)
Rolf Eike Beer's avatar
Rolf Eike Beer committed
12
	: QSortFilterProxyModel(parent), m_model(NULL), m_invert(invert), m_ids(ids)
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
{
}

void
GroupEditProxyModel::setKeyModel(KGpgItemModel *md)
{
	m_model = md;
	setSourceModel(md);
}

bool
GroupEditProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
{
	QModelIndex idx = m_model->index(source_row, 0, source_parent);
	KGpgNode *l = m_model->nodeForIndex(idx);

	if (l->getType() & ~ITYPE_GPAIR)
		return false;

	if ((l->getTrust() != TRUST_FULL) && (l->getTrust() != TRUST_ULTIMATE))
		return false;

	for (int i = 0; i < m_ids->count(); i++)
		if (m_ids->at(i)->getId() == l->getId())
			return !m_invert;

	return m_invert;
}

KGpgNode *
GroupEditProxyModel::nodeForIndex(const QModelIndex &index) const
{
	return m_model->nodeForIndex(mapToSource(index));
}

int
GroupEditProxyModel::columnCount(const QModelIndex &) const
{
	return 3;
}

QVariant
GroupEditProxyModel::data(const QModelIndex &index, int role) const
{
	if ((index.column() >= 3) || (role != Qt::DisplayRole))
		return QVariant();

	KGpgNode *nd = m_model->nodeForIndex(mapToSource(index));
	switch (index.column()) {
		case 0:	return nd->getName();
		case 1:	return nd->getEmail();
		case 2:	return nd->getId().right(8);
	}

	return QVariant();
}

70
71
QVariant
GroupEditProxyModel::headerData(int section, Qt::Orientation orientation, int role) const
72
{
73
74
	if (role != Qt::DisplayRole)
		return QVariant();
75

76
77
78
	if (orientation != Qt::Horizontal)
		return QVariant();

79
80
81
	if (m_model == NULL)
		return QVariant();

82
	switch (section) {
83
84
85
86
	case 0:	return m_model->headerData(KEYCOLUMN_NAME, orientation, role);
	case 1:	return m_model->headerData(KEYCOLUMN_EMAIL, orientation, role);
	case 2:	return m_model->headerData(KEYCOLUMN_ID, orientation, role);
	default:	return QVariant();
87
	}
88
}