Skip to content

Commit

Permalink
Add sorting to Coins tab... for amounts indeed may be handy
Browse files Browse the repository at this point in the history
  • Loading branch information
aivve committed Jan 13, 2022
1 parent 95eff02 commit 70d66b2
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/gui/CoinsFrame.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2011-2016 The Cryptonote developers
// Copyright (c) 2015-2016 XDN developers
// Copyright (c) 2016-2021 Karbo developers
// Copyright (c) 2016-2022 Karbo developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

Expand Down Expand Up @@ -29,6 +29,9 @@ CoinsFrame::CoinsFrame(QWidget* _parent) : QFrame(_parent), m_ui(new Ui::CoinsFr
m_visibleOutputsModel(new VisibleOutputsModel)
{
m_ui->setupUi(this);
m_ui->m_outputsView->setSortingEnabled(true);
m_ui->m_outputsView->sortByColumn(4, Qt::DescendingOrder);
m_visibleOutputsModel->setSortRole(Qt::EditRole);
m_visibleOutputsModel->setDynamicSortFilter(true);
m_ui->m_outputsView->setModel(m_visibleOutputsModel.data());
m_ui->m_outputsView->header()->setSectionResizeMode(QHeaderView::Interactive);
Expand Down
111 changes: 109 additions & 2 deletions src/gui/OutputsModel.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2011-2016 The Cryptonote developers
// Copyright (c) 2015-2016 XDN developers
// Copyright (c) 2016-2021 Karbo developers
// Copyright (c) 2016-2022 Karbo developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

Expand Down Expand Up @@ -109,9 +109,11 @@ QVariant OutputsModel::data(const QModelIndex& _index, int _role) const {

switch(_role) {
case Qt::DisplayRole:
case Qt::EditRole:
return getDisplayRole(_index);

case Qt::EditRole:
return getEditRole(_index);

case Qt::DecorationRole:
return getDecorationRole(_index);

Expand Down Expand Up @@ -262,6 +264,111 @@ QVariant OutputsModel::getDisplayRole(const QModelIndex& _index) const {
return QVariant();
}

QVariant OutputsModel::getEditRole(const QModelIndex& _index) const {
OutputState state = static_cast<OutputState>(_index.data(ROLE_STATE).value<quint8>());
bool is_spent = state == OutputState::SPENT;

OutputType type = static_cast<OutputType>(_index.data(ROLE_TYPE).value<quint8>());

switch(_index.column()) {

case COLUMN_STATE: {
if (is_spent) {
return tr("Spent");
} else {
return tr("Unspent");
}

return QVariant();
}

case COLUMN_TYPE: {
if (type == OutputType::Key)
return tr("Key");
else if (type == OutputType::Multisignature)
return tr("Multisignature");
else
return tr("Invalid");
}

case COLUMN_OUTPUT_KEY:
return _index.data(ROLE_OUTPUT_KEY).toByteArray().toHex().toUpper();

case COLUMN_TX_HASH:
return _index.data(ROLE_TX_HASH).toByteArray().toHex().toUpper();

case COLUMN_AMOUNT: {
qint64 amount = _index.data(ROLE_AMOUNT).value<qint64>();
return amount;
}

case COLUMN_GLOBAL_OUTPUT_INDEX: {
quint32 index = _index.data(ROLE_GLOBAL_OUTPUT_INDEX).value<qint32>();
if (index < 0 || index == std::numeric_limits<uint32_t>::max())
return tr("Pending");
else
return index;
}

case COLUMN_OUTPUT_IN_TRANSACTION:
return _index.data(ROLE_OUTPUT_IN_TRANSACTION).value<qint32>();

case COLUMN_TX_PUBLIC_KEY: {
if (type == OutputType::Key)
return _index.data(ROLE_TX_PUBLIC_KEY).toByteArray().toHex().toUpper();
else if (type == OutputType::Multisignature)
return "-";
}

case COLUMN_SPENDING_BLOCK_HEIGHT: {
if (is_spent) {
quint32 height = _index.data(ROLE_SPENDING_BLOCK_HEIGHT).value<qint32>();
if (height < 0 || height == std::numeric_limits<uint32_t>::max())
return "Unconfirmed";
else
return height;
} else {
return "-";
}
}

case COLUMN_TIMESTAMP: {
if (is_spent) {
QDateTime date = _index.data(ROLE_TIMESTAMP).toDateTime();
return (date.isNull() || !date.isValid() ? "-" : date.toString("dd-MM-yy HH:mm"));
} else {
return "-";
}
}

case COLUMN_SPENDING_TRANSACTION_HASH: {
if (is_spent)
return _index.data(ROLE_SPENDING_TRANSACTION_HASH).toByteArray().toHex().toUpper();
else
return "-";
}

case COLUMN_KEY_IMAGE: {
if (is_spent)
return _index.data(ROLE_KEY_IMAGE).toByteArray().toHex().toUpper();
else
return "-";
}

case COLUMN_INPUT_IN_TRANSACTION: {
if (is_spent)
return _index.data(ROLE_INPUT_IN_TRANSACTION).value<qint32>();
else
return "-";
}

default:
break;
}

return QVariant();
}

QVariant OutputsModel::getToolTipRole(const QModelIndex& _index) const {
OutputState state = static_cast<OutputState>(_index.data(ROLE_STATE).value<quint8>());
if (state == OutputState::SPENT) {
Expand Down
3 changes: 2 additions & 1 deletion src/gui/OutputsModel.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2011-2016 The Cryptonote developers
// Copyright (c) 2015-2016 XDN developers
// Copyright (c) 2016-2021 Karbo developers
// Copyright (c) 2016-2022 Karbo developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

Expand Down Expand Up @@ -59,6 +59,7 @@ class OutputsModel : public QAbstractItemModel {
~OutputsModel();

QVariant getDisplayRole(const QModelIndex& _index) const;
QVariant getEditRole(const QModelIndex& _index) const;
QVariant getDecorationRole(const QModelIndex& _index) const;
QVariant getAlignmentRole(const QModelIndex& _index) const;
QVariant getUserRole(const QModelIndex& _index, int _role, CryptoNote::TransactionSpentOutputInformation _output) const;
Expand Down

0 comments on commit 70d66b2

Please sign in to comment.