aboutsummaryrefslogtreecommitdiff
path: root/gui/src/addresstablemodel.cpp
blob: aec29fa2028ee7dd6bb149b6295f537a31efb6cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "addresstablemodel.h"
#include "main.h"

const QString AddressTableModel::Send = "S";
const QString AddressTableModel::Receive = "R";

AddressTableModel::AddressTableModel(QObject *parent) :
    QAbstractTableModel(parent)
{

}

int AddressTableModel::rowCount(const QModelIndex &parent) const
{
    Q_UNUSED(parent);
    int retval = 0;
    CRITICAL_BLOCK(cs_mapAddressBook)
    {
        retval = mapAddressBook.size();
    }
    return retval;
}

int AddressTableModel::columnCount(const QModelIndex &parent) const
{
    return 2;
}

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)
            return "1PC9aZC4hNX2rmmrt7uHTfYAS3hRbph4UN" + QString::number(index.row());
        else
            return "Description";
    } else if (role == TypeRole)
    {
        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);
}