use user roles instead of hidden columns for model sort/filter keys
This commit is contained in:
parent
858ff187f5
commit
8968bf2e36
6 changed files with 21 additions and 21 deletions
|
@ -10,11 +10,14 @@ public:
|
||||||
explicit AddressTableModel(QObject *parent = 0);
|
explicit AddressTableModel(QObject *parent = 0);
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
Label = 0, /* User specified label */
|
Label = 0, /* User specified label */
|
||||||
Address = 1, /* Bitcoin address */
|
Address = 1 /* Bitcoin address */
|
||||||
Type = 2 /* Send/Receive, used for filter */
|
|
||||||
} ColumnIndex;
|
} ColumnIndex;
|
||||||
|
|
||||||
|
enum {
|
||||||
|
TypeRole = Qt::UserRole
|
||||||
|
} RoleIndex;
|
||||||
|
|
||||||
static const QString Send; /* Send addres */
|
static const QString Send; /* Send addres */
|
||||||
static const QString Receive; /* Receive address */
|
static const QString Receive; /* Receive address */
|
||||||
|
|
||||||
|
|
|
@ -15,10 +15,13 @@ public:
|
||||||
Date = 1,
|
Date = 1,
|
||||||
Description = 2,
|
Description = 2,
|
||||||
Debit = 3,
|
Debit = 3,
|
||||||
Credit = 4,
|
Credit = 4
|
||||||
Type = 5
|
|
||||||
} ColumnIndex;
|
} ColumnIndex;
|
||||||
|
|
||||||
|
enum {
|
||||||
|
TypeRole = Qt::UserRole
|
||||||
|
} RoleIndex;
|
||||||
|
|
||||||
/* Transaction type */
|
/* Transaction type */
|
||||||
static const QString Sent;
|
static const QString Sent;
|
||||||
static const QString Received;
|
static const QString Received;
|
||||||
|
|
|
@ -29,8 +29,7 @@ void AddressBookDialog::setModel(AddressTableModel *model)
|
||||||
QSortFilterProxyModel *receive_model = new QSortFilterProxyModel(this);
|
QSortFilterProxyModel *receive_model = new QSortFilterProxyModel(this);
|
||||||
receive_model->setSourceModel(model);
|
receive_model->setSourceModel(model);
|
||||||
receive_model->setDynamicSortFilter(true);
|
receive_model->setDynamicSortFilter(true);
|
||||||
receive_model->setFilterRole(Qt::UserRole);
|
receive_model->setFilterRole(AddressTableModel::TypeRole);
|
||||||
receive_model->setFilterKeyColumn(AddressTableModel::Type);
|
|
||||||
receive_model->setFilterFixedString(AddressTableModel::Receive);
|
receive_model->setFilterFixedString(AddressTableModel::Receive);
|
||||||
ui->receiveTableView->setModel(receive_model);
|
ui->receiveTableView->setModel(receive_model);
|
||||||
|
|
||||||
|
@ -38,8 +37,7 @@ void AddressBookDialog::setModel(AddressTableModel *model)
|
||||||
QSortFilterProxyModel *send_model = new QSortFilterProxyModel(this);
|
QSortFilterProxyModel *send_model = new QSortFilterProxyModel(this);
|
||||||
send_model->setSourceModel(model);
|
send_model->setSourceModel(model);
|
||||||
send_model->setDynamicSortFilter(true);
|
send_model->setDynamicSortFilter(true);
|
||||||
send_model->setFilterRole(Qt::UserRole);
|
send_model->setFilterRole(AddressTableModel::TypeRole);
|
||||||
send_model->setFilterKeyColumn(AddressTableModel::Type);
|
|
||||||
send_model->setFilterFixedString(AddressTableModel::Send);
|
send_model->setFilterFixedString(AddressTableModel::Send);
|
||||||
ui->sendTableView->setModel(send_model);
|
ui->sendTableView->setModel(send_model);
|
||||||
|
|
||||||
|
@ -52,10 +50,6 @@ void AddressBookDialog::setModel(AddressTableModel *model)
|
||||||
AddressTableModel::Address, 320);
|
AddressTableModel::Address, 320);
|
||||||
ui->sendTableView->horizontalHeader()->setResizeMode(
|
ui->sendTableView->horizontalHeader()->setResizeMode(
|
||||||
AddressTableModel::Label, QHeaderView::Stretch);
|
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)
|
void AddressBookDialog::setTab(int tab)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "addresstablemodel.h"
|
#include "addresstablemodel.h"
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
const QString AddressTableModel::Send = "S";
|
const QString AddressTableModel::Send = "S";
|
||||||
const QString AddressTableModel::Receive = "R";
|
const QString AddressTableModel::Receive = "R";
|
||||||
|
@ -16,7 +17,7 @@ int AddressTableModel::rowCount(const QModelIndex &parent) const
|
||||||
|
|
||||||
int AddressTableModel::columnCount(const QModelIndex &parent) const
|
int AddressTableModel::columnCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
return 3;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant AddressTableModel::data(const QModelIndex &index, int role) const
|
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());
|
return "1PC9aZC4hNX2rmmrt7uHTfYAS3hRbph4UN" + QString::number(index.row());
|
||||||
else
|
else
|
||||||
return "Description";
|
return "Description";
|
||||||
} else if (role == Qt::UserRole)
|
} else if (role == TypeRole)
|
||||||
{
|
{
|
||||||
switch(index.row() % 2)
|
switch(index.row() % 2)
|
||||||
{
|
{
|
||||||
|
|
|
@ -193,8 +193,7 @@ QWidget *BitcoinGUI::createTabs()
|
||||||
QSortFilterProxyModel *proxy_model = new QSortFilterProxyModel(this);
|
QSortFilterProxyModel *proxy_model = new QSortFilterProxyModel(this);
|
||||||
proxy_model->setSourceModel(transaction_model);
|
proxy_model->setSourceModel(transaction_model);
|
||||||
proxy_model->setDynamicSortFilter(true);
|
proxy_model->setDynamicSortFilter(true);
|
||||||
proxy_model->setFilterRole(Qt::UserRole);
|
proxy_model->setFilterRole(TransactionTableModel::TypeRole);
|
||||||
proxy_model->setFilterKeyColumn(TransactionTableModel::Type);
|
|
||||||
proxy_model->setFilterRegExp(QRegExp(tab_filters.at(i)));
|
proxy_model->setFilterRegExp(QRegExp(tab_filters.at(i)));
|
||||||
|
|
||||||
QTableView *transaction_table = new QTableView(this);
|
QTableView *transaction_table = new QTableView(this);
|
||||||
|
@ -213,7 +212,6 @@ QWidget *BitcoinGUI::createTabs()
|
||||||
TransactionTableModel::Debit, 79);
|
TransactionTableModel::Debit, 79);
|
||||||
transaction_table->horizontalHeader()->resizeSection(
|
transaction_table->horizontalHeader()->resizeSection(
|
||||||
TransactionTableModel::Credit, 79);
|
TransactionTableModel::Credit, 79);
|
||||||
transaction_table->setColumnHidden(TransactionTableModel::Type, true);
|
|
||||||
|
|
||||||
tabs->addTab(transaction_table, tab_labels.at(i));
|
tabs->addTab(transaction_table, tab_labels.at(i));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "transactiontablemodel.h"
|
#include "transactiontablemodel.h"
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
#include <QLocale>
|
#include <QLocale>
|
||||||
|
|
||||||
|
@ -19,13 +20,13 @@ static int column_alignments[] = {
|
||||||
TransactionTableModel::TransactionTableModel(QObject *parent):
|
TransactionTableModel::TransactionTableModel(QObject *parent):
|
||||||
QAbstractTableModel(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
|
int TransactionTableModel::rowCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(parent);
|
Q_UNUSED(parent);
|
||||||
return 5;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
int TransactionTableModel::columnCount(const QModelIndex &parent) const
|
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)
|
} else if (role == Qt::TextAlignmentRole)
|
||||||
{
|
{
|
||||||
return column_alignments[index.column()];
|
return column_alignments[index.column()];
|
||||||
} else if (role == Qt::UserRole)
|
} else if (role == TypeRole)
|
||||||
{
|
{
|
||||||
/* user role: transaction type for filtering
|
/* user role: transaction type for filtering
|
||||||
"s" (sent)
|
"s" (sent)
|
||||||
|
|
Loading…
Reference in a new issue