use user roles instead of hidden columns for model sort/filter keys

This commit is contained in:
Wladimir J. van der Laan 2011-05-22 19:32:37 +02:00
parent 858ff187f5
commit 8968bf2e36
6 changed files with 21 additions and 21 deletions

View File

@ -10,11 +10,14 @@ public:
explicit AddressTableModel(QObject *parent = 0);
enum {
Label = 0, /* User specified label */
Address = 1, /* Bitcoin address */
Type = 2 /* Send/Receive, used for filter */
Label = 0, /* User specified label */
Address = 1 /* Bitcoin address */
} ColumnIndex;
enum {
TypeRole = Qt::UserRole
} RoleIndex;
static const QString Send; /* Send addres */
static const QString Receive; /* Receive address */

View File

@ -15,10 +15,13 @@ public:
Date = 1,
Description = 2,
Debit = 3,
Credit = 4,
Type = 5
Credit = 4
} ColumnIndex;
enum {
TypeRole = Qt::UserRole
} RoleIndex;
/* Transaction type */
static const QString Sent;
static const QString Received;

View File

@ -29,8 +29,7 @@ void AddressBookDialog::setModel(AddressTableModel *model)
QSortFilterProxyModel *receive_model = new QSortFilterProxyModel(this);
receive_model->setSourceModel(model);
receive_model->setDynamicSortFilter(true);
receive_model->setFilterRole(Qt::UserRole);
receive_model->setFilterKeyColumn(AddressTableModel::Type);
receive_model->setFilterRole(AddressTableModel::TypeRole);
receive_model->setFilterFixedString(AddressTableModel::Receive);
ui->receiveTableView->setModel(receive_model);
@ -38,8 +37,7 @@ void AddressBookDialog::setModel(AddressTableModel *model)
QSortFilterProxyModel *send_model = new QSortFilterProxyModel(this);
send_model->setSourceModel(model);
send_model->setDynamicSortFilter(true);
send_model->setFilterRole(Qt::UserRole);
send_model->setFilterKeyColumn(AddressTableModel::Type);
send_model->setFilterRole(AddressTableModel::TypeRole);
send_model->setFilterFixedString(AddressTableModel::Send);
ui->sendTableView->setModel(send_model);
@ -52,10 +50,6 @@ void AddressBookDialog::setModel(AddressTableModel *model)
AddressTableModel::Address, 320);
ui->sendTableView->horizontalHeader()->setResizeMode(
AddressTableModel::Label, QHeaderView::Stretch);
/* Hide "Type" column in both views as it is only used for filtering */
ui->receiveTableView->setColumnHidden(AddressTableModel::Type, true);
ui->sendTableView->setColumnHidden(AddressTableModel::Type, true);
}
void AddressBookDialog::setTab(int tab)

View File

@ -1,4 +1,5 @@
#include "addresstablemodel.h"
#include "main.h"
const QString AddressTableModel::Send = "S";
const QString AddressTableModel::Receive = "R";
@ -16,7 +17,7 @@ int AddressTableModel::rowCount(const QModelIndex &parent) const
int AddressTableModel::columnCount(const QModelIndex &parent) const
{
return 3;
return 2;
}
QVariant AddressTableModel::data(const QModelIndex &index, int role) const
@ -32,7 +33,7 @@ QVariant AddressTableModel::data(const QModelIndex &index, int role) const
return "1PC9aZC4hNX2rmmrt7uHTfYAS3hRbph4UN" + QString::number(index.row());
else
return "Description";
} else if (role == Qt::UserRole)
} else if (role == TypeRole)
{
switch(index.row() % 2)
{

View File

@ -193,8 +193,7 @@ QWidget *BitcoinGUI::createTabs()
QSortFilterProxyModel *proxy_model = new QSortFilterProxyModel(this);
proxy_model->setSourceModel(transaction_model);
proxy_model->setDynamicSortFilter(true);
proxy_model->setFilterRole(Qt::UserRole);
proxy_model->setFilterKeyColumn(TransactionTableModel::Type);
proxy_model->setFilterRole(TransactionTableModel::TypeRole);
proxy_model->setFilterRegExp(QRegExp(tab_filters.at(i)));
QTableView *transaction_table = new QTableView(this);
@ -213,7 +212,6 @@ QWidget *BitcoinGUI::createTabs()
TransactionTableModel::Debit, 79);
transaction_table->horizontalHeader()->resizeSection(
TransactionTableModel::Credit, 79);
transaction_table->setColumnHidden(TransactionTableModel::Type, true);
tabs->addTab(transaction_table, tab_labels.at(i));
}

View File

@ -1,4 +1,5 @@
#include "transactiontablemodel.h"
#include "main.h"
#include <QLocale>
@ -19,13 +20,13 @@ static int column_alignments[] = {
TransactionTableModel::TransactionTableModel(QObject *parent):
QAbstractTableModel(parent)
{
columns << tr("Status") << tr("Date") << tr("Description") << tr("Debit") << tr("Credit") << tr("Type");
columns << tr("Status") << tr("Date") << tr("Description") << tr("Debit") << tr("Credit");
}
int TransactionTableModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return 5;
return 4;
}
int TransactionTableModel::columnCount(const QModelIndex &parent) const
@ -47,7 +48,7 @@ QVariant TransactionTableModel::data(const QModelIndex &index, int role) const
} else if (role == Qt::TextAlignmentRole)
{
return column_alignments[index.column()];
} else if (role == Qt::UserRole)
} else if (role == TypeRole)
{
/* user role: transaction type for filtering
"s" (sent)