Commit 87da02ef authored by Rolf Eike Beer's avatar Rolf Eike Beer
Browse files

add proxymodel missed yesterday

svn path=/branches/work/kgpg2/; revision=752999
parent f5cb8d39
#include "groupeditproxymodel.h"
#include "kgpgitemnode.h"
#include "kgpgitemmodel.h"
#include "core/kgpgkey.h"
#include <KDebug>
using namespace KgpgCore;
GroupEditProxyModel::GroupEditProxyModel(QObject *parent, const bool &invert, QList<KGpgNode *> *ids)
: QSortFilterProxyModel(parent), m_invert(invert), m_ids(ids)
{
}
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();
}
void
GroupEditProxyModel::beginChange()
{
emit layoutAboutToBeChanged();
}
void
GroupEditProxyModel::endChange()
{
emit layoutChanged();
}
#ifndef GROUPEDITPROXYMODEL_H
#define GROUPEDITPROXYMODEL_H
#include <QSortFilterProxyModel>
#include <QStringList>
class KGpgNode;
class KGpgGroupNode;
class KGpgItemModel;
class GroupEditProxyModel: public QSortFilterProxyModel
{
public:
explicit GroupEditProxyModel(QObject * parent, const bool &invert, QList<KGpgNode *> *ids);
void setKeyModel(KGpgItemModel *);
KGpgNode *nodeForIndex(const QModelIndex &index) const;
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
protected:
virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
virtual int columnCount(const QModelIndex &) const;
private:
KGpgItemModel *m_model;
bool m_invert;
QList<KGpgNode *> *m_ids;
public Q_SLOTS:
void beginChange();
void endChange();
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment