lowercase
[novacoin.git] / transactiontablemodel.cpp
1 #include "transactiontablemodel.h"
2
3 #include <QLocale>
4
5 /* Credit and Debit columns are right-aligned as they contain numbers */
6 static int column_alignments[] = {
7         Qt::AlignLeft|Qt::AlignVCenter,
8         Qt::AlignLeft|Qt::AlignVCenter,
9         Qt::AlignLeft|Qt::AlignVCenter,
10         Qt::AlignRight|Qt::AlignVCenter,
11         Qt::AlignRight|Qt::AlignVCenter
12     };
13
14 TransactionTableModel::TransactionTableModel(QObject *parent):
15         QAbstractTableModel(parent)
16 {
17     columns << tr("Status") << tr("Date") << tr("Description") << tr("Debit") << tr("Credit");
18 }
19
20 int TransactionTableModel::rowCount(const QModelIndex &parent) const
21 {
22     Q_UNUSED(parent);
23     return 5;
24 }
25
26 int TransactionTableModel::columnCount(const QModelIndex &parent) const
27 {
28     Q_UNUSED(parent);
29     return columns.length();
30 }
31
32 QVariant TransactionTableModel::data(const QModelIndex &index, int role) const
33 {
34     if(!index.isValid())
35         return QVariant();
36
37     if(role == Qt::DisplayRole)
38     {
39         /* index.row(), index.column() */
40         /* Return QString */
41         return QLocale::system().toString(index.row());
42     } else if (role == Qt::TextAlignmentRole)
43     {
44         return column_alignments[index.column()];
45     } else if (role == Qt::UserRole)
46     {
47         /* user role: transaction type for filtering
48            "s" (sent)
49            "r" (received)
50            "g" (generated)
51         */
52         switch(index.row() % 3)
53         {
54         case 0: return QString("s");
55         case 1: return QString("r");
56         case 2: return QString("o");
57         }
58     }
59     return QVariant();
60 }
61
62 QVariant TransactionTableModel::headerData(int section, Qt::Orientation orientation, int role) const
63 {
64     if(role == Qt::DisplayRole)
65     {
66         if(orientation == Qt::Horizontal)
67         {
68             return columns[section];
69         }
70     } else if (role == Qt::TextAlignmentRole)
71     {
72         return column_alignments[section];
73     }
74     return QVariant();
75 }
76
77 Qt::ItemFlags TransactionTableModel::flags(const QModelIndex &index) const
78 {
79     if (!index.isValid())
80         return Qt::ItemIsEnabled;
81
82     return QAbstractTableModel::flags(index);
83 }