twisterp2pnetworkbittorrentblockchainmicrobloggingipv6social-networkdhtdecentralizedtwister-servertwister-ipv6twister-coretwisterarmyp2p-network
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
2.1 KiB
84 lines
2.1 KiB
14 years ago
|
#include "TransactionTableModel.h"
|
||
|
|
||
14 years ago
|
#include <QLocale>
|
||
|
|
||
14 years ago
|
/* Credit and Debit columns are right-aligned as they contain numbers */
|
||
14 years ago
|
static int column_alignments[] = {
|
||
|
Qt::AlignLeft|Qt::AlignVCenter,
|
||
|
Qt::AlignLeft|Qt::AlignVCenter,
|
||
|
Qt::AlignLeft|Qt::AlignVCenter,
|
||
|
Qt::AlignRight|Qt::AlignVCenter,
|
||
|
Qt::AlignRight|Qt::AlignVCenter
|
||
14 years ago
|
};
|
||
|
|
||
14 years ago
|
TransactionTableModel::TransactionTableModel(QObject *parent):
|
||
|
QAbstractTableModel(parent)
|
||
|
{
|
||
14 years ago
|
columns << tr("Status") << tr("Date") << tr("Description") << tr("Debit") << tr("Credit");
|
||
14 years ago
|
}
|
||
|
|
||
|
int TransactionTableModel::rowCount(const QModelIndex &parent) const
|
||
|
{
|
||
|
Q_UNUSED(parent);
|
||
|
return 5;
|
||
|
}
|
||
|
|
||
|
int TransactionTableModel::columnCount(const QModelIndex &parent) const
|
||
|
{
|
||
|
Q_UNUSED(parent);
|
||
|
return columns.length();
|
||
|
}
|
||
|
|
||
|
QVariant TransactionTableModel::data(const QModelIndex &index, int role) const
|
||
|
{
|
||
|
if(!index.isValid())
|
||
|
return QVariant();
|
||
|
|
||
|
if(role == Qt::DisplayRole)
|
||
|
{
|
||
|
/* index.row(), index.column() */
|
||
|
/* Return QString */
|
||
14 years ago
|
return QLocale::system().toString(index.row());
|
||
14 years ago
|
} else if (role == Qt::TextAlignmentRole)
|
||
|
{
|
||
|
return column_alignments[index.column()];
|
||
14 years ago
|
} else if (role == Qt::UserRole)
|
||
|
{
|
||
|
/* user role: transaction type for filtering
|
||
|
"s" (sent)
|
||
|
"r" (received)
|
||
|
"g" (generated)
|
||
|
*/
|
||
|
switch(index.row() % 3)
|
||
|
{
|
||
|
case 0: return QString("s");
|
||
|
case 1: return QString("r");
|
||
|
case 2: return QString("o");
|
||
|
}
|
||
14 years ago
|
}
|
||
|
return QVariant();
|
||
|
}
|
||
|
|
||
|
QVariant TransactionTableModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||
|
{
|
||
14 years ago
|
if(role == Qt::DisplayRole)
|
||
|
{
|
||
|
if(orientation == Qt::Horizontal)
|
||
|
{
|
||
|
return columns[section];
|
||
|
}
|
||
|
} else if (role == Qt::TextAlignmentRole)
|
||
14 years ago
|
{
|
||
14 years ago
|
return column_alignments[section];
|
||
14 years ago
|
}
|
||
|
return QVariant();
|
||
|
}
|
||
|
|
||
|
Qt::ItemFlags TransactionTableModel::flags(const QModelIndex &index) const
|
||
|
{
|
||
|
if (!index.isValid())
|
||
|
return Qt::ItemIsEnabled;
|
||
|
|
||
|
return QAbstractTableModel::flags(index);
|
||
|
}
|