latest patch from sss about keyring proxy model

This commit is contained in:
csoler 2017-10-18 23:24:54 +02:00
parent cd1da4495e
commit 0f7d7544ee
4 changed files with 68 additions and 96 deletions

View File

@ -7,7 +7,7 @@
#define IMAGE_TRUSTED ":/images/rs-2.png" #define IMAGE_TRUSTED ":/images/rs-2.png"
/*TODO: /*TODO:
* using list here for internal data storage is not best options * using list here for internal data storage is not best option
*/ */
pgpid_item_model::pgpid_item_model(std::list<RsPgpId> &neighs_, float &_font_height, QObject *parent) pgpid_item_model::pgpid_item_model(std::list<RsPgpId> &neighs_, float &_font_height, QObject *parent)
: QAbstractTableModel(parent), neighs(neighs_), font_height(_font_height) : QAbstractTableModel(parent), neighs(neighs_), font_height(_font_height)
@ -95,26 +95,6 @@ QVariant pgpid_item_model::headerData(int section, Qt::Orientation orientation,
return QVariant(); return QVariant();
} }
/*QModelIndex pgpid_item_model::index(int row, int column, const QModelIndex &parent) const
{
return createIndex(row, column);
}*/
/*QModelIndex pgpid_item_model::parent(const QModelIndex &index) const
{
if(index.row() > -1 && index.column() > -1)
return createIndex(-1, -1);
if (!index.isValid())
return QModelIndex();
return QModelIndex();
}*/
/*bool pgpid_item_model::hasChildren(const QModelIndex &parent) const
{
if(parent.column() == -1 && parent.row() == -1)
return true;
return false;
} */
int pgpid_item_model::rowCount(const QModelIndex &/*parent*/) const int pgpid_item_model::rowCount(const QModelIndex &/*parent*/) const
{ {
@ -126,20 +106,6 @@ int pgpid_item_model::columnCount(const QModelIndex &/*parent*/) const
return COLUMN_COUNT; return COLUMN_COUNT;
} }
//bool pgpid_item_model::insertRows(int position, int rows, const QModelIndex &/*index*/)
//{
// beginInsertRows(QModelIndex(), position, position+rows-1);
// endInsertRows();
// return true;
//}
//bool pgpid_item_model::removeRows(int position, int rows, const QModelIndex &/*index*/)
//{
// beginRemoveRows(QModelIndex(), position, position+rows-1);
// endRemoveRows();
// return true;
//}
QVariant pgpid_item_model::data(const QModelIndex &index, int role) const QVariant pgpid_item_model::data(const QModelIndex &index, int role) const
{ {
@ -159,7 +125,32 @@ QVariant pgpid_item_model::data(const QModelIndex &index, int role) const
if (!rsPeers->getGPGDetails(*it, detail)) if (!rsPeers->getGPGDetails(*it, detail))
return QVariant(); return QVariant();
//shit code end //shit code end
if(role == Qt::DisplayRole) if(role == Qt::EditRole) //some columns return raw data for editrole, used for proper filtering
{
switch(index.column())
{
case COLUMN_LAST_USED:
return detail.lastUsed;
break;
case COLUMN_I_AUTH_PEER:
{
if (detail.ownsign)
return RS_TRUST_LVL_ULTIMATE;
return detail.trustLvl;
}
break;
case COLUMN_PEER_AUTH_ME:
return detail.hasSignedMe;
break;
case COLUMN_CHECK:
return detail.accept_connection;
break;
default:
break;
}
}
if(role == Qt::DisplayRole || role == Qt::EditRole)
{ {
switch(index.column()) switch(index.column())
{ {
@ -211,10 +202,8 @@ QVariant pgpid_item_model::data(const QModelIndex &index, int role) const
else else
lst_used_str = tr("%1 days ago").arg((int)( last_time_used / 86400 )) ; lst_used_str = tr("%1 days ago").arg((int)( last_time_used / 86400 )) ;
// QString lst_used_sort_str = QString::number(detail.lastUsed,'f',10);
return lst_used_str; return lst_used_str;
// item->setData(COLUMN_LAST_USED,ROLE_SORT,lst_used_sort_str) ;
} }
break; break;
case COLUMN_CHECK: case COLUMN_CHECK:
@ -291,11 +280,6 @@ QVariant pgpid_item_model::data(const QModelIndex &index, int role) const
return QVariant(); return QVariant();
} }
/*void pgpid_item_model::sort(int column, Qt::SortOrder order)
{
} */
//following code is just a poc, it's still suboptimal, unefficient, but much better then existing rs code //following code is just a poc, it's still suboptimal, unefficient, but much better then existing rs code

View File

@ -23,20 +23,12 @@ public:
// Header: // Header:
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
// Basic functionality:
// QModelIndex index(int row, int column,
// const QModelIndex &parent = QModelIndex()) const override;
// QModelIndex parent(const QModelIndex &index) const override;
// bool hasChildren(const QModelIndex &parent = QModelIndex()) const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override; int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override; int columnCount(const QModelIndex &parent = QModelIndex()) const override;
// bool insertRows(int position, int rows, const QModelIndex &index = QModelIndex()) override;
// bool removeRows(int position, int rows, const QModelIndex &index = QModelIndex()) override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
// void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;
public slots: public slots:
void data_updated(std::list<RsPgpId> &new_neighs); void data_updated(std::list<RsPgpId> &new_neighs);

View File

@ -1,50 +1,48 @@
#include "pgpid_item_proxy.h" #include "pgpid_item_proxy.h"
//TODO: include only required headers here
#include <retroshare/rsiface.h>
#include <retroshare/rspeers.h>
#include <retroshare/rsdisc.h>
#include <retroshare/rsmsgs.h>
//TODO: set this defines in one place
// Defines for key list columns
#define COLUMN_CHECK 0
#define COLUMN_PEERNAME 1
#define COLUMN_I_AUTH_PEER 2
#define COLUMN_PEER_AUTH_ME 3
#define COLUMN_PEERID 4
#define COLUMN_LAST_USED 5
#define COLUMN_COUNT 6
pgpid_item_proxy::pgpid_item_proxy(QObject *parent) : pgpid_item_proxy::pgpid_item_proxy(QObject *parent) :
//QAbstractProxyModel(parent)
QSortFilterProxyModel(parent) QSortFilterProxyModel(parent)
{ {
} }
void pgpid_item_proxy::use_only_trusted_keys(bool val)
/*QModelIndex pgpid_item_proxy::mapFromSource(const QModelIndex &sourceIndex) const
{ {
if(sourceIndex.isValid()) only_trusted_keys = val;
return createIndex(sourceIndex.row(), sourceIndex.column(), sourceIndex.internalPointer()); filterChanged();
else
return QModelIndex();
} }
bool pgpid_item_proxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
QModelIndex pgpid_item_proxy::mapToSource(const QModelIndex &proxyIndex) const
{ {
if(proxyIndex.isValid()) if(only_trusted_keys)
return sourceModel()->index(proxyIndex.row(), proxyIndex.column()); {
else if(!rsPeers)
return QModelIndex();} return false;
RsPgpId peer_id (sourceModel()->data(sourceModel()->index(sourceRow, COLUMN_PEERID, sourceParent)).toString().toStdString());
RsPeerDetails details;
QModelIndex pgpid_item_proxy::index(int row, int column, const QModelIndex &parent) const if(!rsPeers->getGPGDetails(peer_id, details))
{ return false;
const QModelIndex sourceParent = mapToSource(parent); if(details.validLvl < RS_TRUST_LVL_MARGINAL)
const QModelIndex sourceIndex = sourceModel()->index(row, column, sourceParent); return false;
return mapFromSource(sourceIndex); }
return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
} }
QModelIndex pgpid_item_proxy::parent(const QModelIndex &child) const
{
const QModelIndex sourceIndex = mapToSource(child);
const QModelIndex sourceParent = sourceIndex.parent();
return mapFromSource(sourceParent);
}
int pgpid_item_proxy::rowCount(const QModelIndex &parent) const
{
//TODO:
return sourceModel()->rowCount(parent);
}
int pgpid_item_proxy::columnCount(const QModelIndex &parent) const
{
return sourceModel()->columnCount(parent);
}
*/

View File

@ -4,20 +4,18 @@
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
class pgpid_item_proxy : class pgpid_item_proxy :
//public QAbstractProxyModel
public QSortFilterProxyModel public QSortFilterProxyModel
{ {
Q_OBJECT Q_OBJECT
public: public:
pgpid_item_proxy(QObject *parent = nullptr); pgpid_item_proxy(QObject *parent = nullptr);
/* virtual QModelIndex mapFromSource(const QModelIndex &sourceIndex) const; bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
QModelIndex mapToSource(const QModelIndex &proxyIndex) const; public slots:
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; void use_only_trusted_keys(bool val);
QModelIndex parent(const QModelIndex &child) const;
int rowCount(const QModelIndex &parent = QModelIndex()) const; private:
int columnCount(const QModelIndex &parent = QModelIndex()) const; bool only_trusted_keys = false;
*/
}; };
#endif // PGPID_ITEM_PROXY_H #endif // PGPID_ITEM_PROXY_H