2011-05-12 14:49:42 +02:00
|
|
|
#include "addresstablemodel.h"
|
2011-05-22 19:32:37 +02:00
|
|
|
#include "main.h"
|
2011-05-09 20:44:46 +02:00
|
|
|
|
2011-05-13 15:58:27 +02:00
|
|
|
const QString AddressTableModel::Send = "S";
|
|
|
|
const QString AddressTableModel::Receive = "R";
|
|
|
|
|
2011-05-09 20:44:46 +02:00
|
|
|
AddressTableModel::AddressTableModel(QObject *parent) :
|
|
|
|
QAbstractTableModel(parent)
|
|
|
|
{
|
2011-05-13 15:58:27 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int AddressTableModel::rowCount(const QModelIndex &parent) const
|
|
|
|
{
|
2011-05-27 08:20:23 +02:00
|
|
|
Q_UNUSED(parent);
|
|
|
|
int retval = 0;
|
|
|
|
CRITICAL_BLOCK(cs_mapAddressBook)
|
|
|
|
{
|
|
|
|
retval = mapAddressBook.size();
|
|
|
|
}
|
|
|
|
return retval;
|
2011-05-13 15:58:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int AddressTableModel::columnCount(const QModelIndex &parent) const
|
|
|
|
{
|
2011-05-22 19:32:37 +02:00
|
|
|
return 2;
|
2011-05-13 15:58:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QVariant AddressTableModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
|
|
|
if(!index.isValid())
|
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
if(role == Qt::DisplayRole)
|
|
|
|
{
|
|
|
|
/* index.row(), index.column() */
|
|
|
|
/* Return QString */
|
|
|
|
if(index.column() == Address)
|
2011-05-13 22:00:27 +02:00
|
|
|
return "1PC9aZC4hNX2rmmrt7uHTfYAS3hRbph4UN" + QString::number(index.row());
|
2011-05-13 15:58:27 +02:00
|
|
|
else
|
|
|
|
return "Description";
|
2011-05-22 19:32:37 +02:00
|
|
|
} else if (role == TypeRole)
|
2011-05-13 15:58:27 +02:00
|
|
|
{
|
|
|
|
switch(index.row() % 2)
|
|
|
|
{
|
|
|
|
case 0: return Send;
|
|
|
|
case 1: return Receive;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant AddressTableModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
|
|
{
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
Qt::ItemFlags AddressTableModel::flags(const QModelIndex &index) const
|
|
|
|
{
|
|
|
|
if (!index.isValid())
|
|
|
|
return Qt::ItemIsEnabled;
|
|
|
|
|
|
|
|
return QAbstractTableModel::flags(index);
|
2011-05-09 20:44:46 +02:00
|
|
|
}
|