mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
latest patch from sss about keyring proxy model
This commit is contained in:
parent
cd1da4495e
commit
0f7d7544ee
@ -7,7 +7,7 @@
|
||||
#define IMAGE_TRUSTED ":/images/rs-2.png"
|
||||
|
||||
/*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)
|
||||
: QAbstractTableModel(parent), neighs(neighs_), font_height(_font_height)
|
||||
@ -95,26 +95,6 @@ QVariant pgpid_item_model::headerData(int section, Qt::Orientation orientation,
|
||||
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
|
||||
{
|
||||
@ -126,20 +106,6 @@ int pgpid_item_model::columnCount(const QModelIndex &/*parent*/) const
|
||||
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
|
||||
{
|
||||
@ -159,7 +125,32 @@ QVariant pgpid_item_model::data(const QModelIndex &index, int role) const
|
||||
if (!rsPeers->getGPGDetails(*it, detail))
|
||||
return QVariant();
|
||||
//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())
|
||||
{
|
||||
@ -211,10 +202,8 @@ QVariant pgpid_item_model::data(const QModelIndex &index, int role) const
|
||||
else
|
||||
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;
|
||||
// item->setData(COLUMN_LAST_USED,ROLE_SORT,lst_used_sort_str) ;
|
||||
}
|
||||
break;
|
||||
case COLUMN_CHECK:
|
||||
@ -291,11 +280,6 @@ QVariant pgpid_item_model::data(const QModelIndex &index, int role) const
|
||||
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
|
||||
|
||||
|
@ -23,20 +23,12 @@ public:
|
||||
// Header:
|
||||
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 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;
|
||||
|
||||
// void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;
|
||||
public slots:
|
||||
void data_updated(std::list<RsPgpId> &new_neighs);
|
||||
|
||||
|
@ -1,50 +1,48 @@
|
||||
#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) :
|
||||
//QAbstractProxyModel(parent)
|
||||
QSortFilterProxyModel(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*QModelIndex pgpid_item_proxy::mapFromSource(const QModelIndex &sourceIndex) const
|
||||
void pgpid_item_proxy::use_only_trusted_keys(bool val)
|
||||
{
|
||||
if(sourceIndex.isValid())
|
||||
return createIndex(sourceIndex.row(), sourceIndex.column(), sourceIndex.internalPointer());
|
||||
else
|
||||
return QModelIndex();
|
||||
only_trusted_keys = val;
|
||||
filterChanged();
|
||||
}
|
||||
|
||||
|
||||
QModelIndex pgpid_item_proxy::mapToSource(const QModelIndex &proxyIndex) const
|
||||
bool pgpid_item_proxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
||||
{
|
||||
if(proxyIndex.isValid())
|
||||
return sourceModel()->index(proxyIndex.row(), proxyIndex.column());
|
||||
else
|
||||
return QModelIndex();}
|
||||
|
||||
|
||||
QModelIndex pgpid_item_proxy::index(int row, int column, const QModelIndex &parent) const
|
||||
{
|
||||
const QModelIndex sourceParent = mapToSource(parent);
|
||||
const QModelIndex sourceIndex = sourceModel()->index(row, column, sourceParent);
|
||||
return mapFromSource(sourceIndex);
|
||||
if(only_trusted_keys)
|
||||
{
|
||||
if(!rsPeers)
|
||||
return false;
|
||||
RsPgpId peer_id (sourceModel()->data(sourceModel()->index(sourceRow, COLUMN_PEERID, sourceParent)).toString().toStdString());
|
||||
RsPeerDetails details;
|
||||
if(!rsPeers->getGPGDetails(peer_id, details))
|
||||
return false;
|
||||
if(details.validLvl < RS_TRUST_LVL_MARGINAL)
|
||||
return false;
|
||||
}
|
||||
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);
|
||||
}
|
||||
*/
|
||||
|
@ -4,20 +4,18 @@
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
class pgpid_item_proxy :
|
||||
//public QAbstractProxyModel
|
||||
public QSortFilterProxyModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
pgpid_item_proxy(QObject *parent = nullptr);
|
||||
/* virtual QModelIndex mapFromSource(const QModelIndex &sourceIndex) const;
|
||||
QModelIndex mapToSource(const QModelIndex &proxyIndex) const;
|
||||
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
|
||||
QModelIndex parent(const QModelIndex &child) const;
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
*/
|
||||
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
|
||||
public slots:
|
||||
void use_only_trusted_keys(bool val);
|
||||
|
||||
private:
|
||||
bool only_trusted_keys = false;
|
||||
};
|
||||
|
||||
#endif // PGPID_ITEM_PROXY_H
|
||||
|
Loading…
Reference in New Issue
Block a user