Coins: improve freeze/thaw performance and fix indexing bug

This commit is contained in:
tobtoht 2021-02-04 00:14:20 +01:00
parent e0f7473ed4
commit c296eab191
No known key found for this signature in database
GPG key ID: 1CADD27F41F45C3C
6 changed files with 26 additions and 34 deletions

View file

@ -61,7 +61,7 @@ CoinsWidget::CoinsWidget(QWidget *parent)
void CoinsWidget::setModel(CoinsModel * model, Coins * coins) {
m_coins = coins;
m_model = model;
m_proxyModel = new CoinsProxyModel(this);
m_proxyModel = new CoinsProxyModel(this, m_coins);
m_proxyModel->setSourceModel(m_model);
ui->coins->setModel(m_proxyModel);
ui->coins->setColumnHidden(CoinsModel::Spent, true);
@ -135,7 +135,8 @@ void CoinsWidget::setShowSpent(bool show)
void CoinsWidget::freezeOutput() {
QModelIndex index = ui->coins->currentIndex();
emit freeze(m_proxyModel->mapToSource(index).row());
QVector<int> indexes = {m_proxyModel->mapToSource(index).row()};
emit freeze(indexes);
}
void CoinsWidget::freezeAllSelected() {
@ -145,12 +146,13 @@ void CoinsWidget::freezeAllSelected() {
for (QModelIndex index: list) {
indexes.push_back(m_proxyModel->mapToSource(index).row()); // todo: will segfault if index get invalidated
}
emit freezeMulti(indexes);
emit freeze(indexes);
}
void CoinsWidget::thawOutput() {
QModelIndex index = ui->coins->currentIndex();
emit thaw(m_proxyModel->mapToSource(index).row());
QVector<int> indexes = {m_proxyModel->mapToSource(index).row()};
emit thaw(indexes);
}
void CoinsWidget::thawAllSelected() {
@ -160,7 +162,7 @@ void CoinsWidget::thawAllSelected() {
for (QModelIndex index: list) {
indexes.push_back(m_proxyModel->mapToSource(index).row());
}
emit thawMulti(indexes);
emit thaw(indexes);
}
void CoinsWidget::viewOutput() {

View file

@ -39,10 +39,8 @@ private slots:
void onSweepOutput();
signals:
void freeze(int index);
void freezeMulti(QVector<int>);
void thaw(int index);
void thawMulti(QVector<int>);
void freeze(QVector<int> indexes);
void thaw(QVector<int> indexes);
void sweepOutput(const QString &keyImage, const QString &address, bool isChurn, int outputs);
private:

View file

@ -36,10 +36,6 @@ void Coins::refresh(quint32 accountIndex)
m_pimpl->refresh();
for (const auto i : m_pimpl->getAll()) {
if (i->subaddrAccount() != accountIndex) {
continue;
}
m_tinfo.append(new CoinsInfo(i, this));
}
}

View file

@ -289,30 +289,19 @@ MainWindow::MainWindow(AppContext *ctx, QWidget *parent) :
connect(m_ctx, &AppContext::openAliasResolved, ui->sendWidget, &SendWidget::onOpenAliasResolved);
// Coins
connect(ui->coinsWidget, &CoinsWidget::freeze, [=](int index) {
m_ctx->currentWallet->coins()->freeze(index);
m_ctx->currentWallet->coins()->refresh(m_ctx->currentWallet->currentSubaddressAccount());
m_ctx->updateBalance();
// subaddress account filtering should be done in Model maybe, so we can update data in coins() directly
});
connect(ui->coinsWidget, &CoinsWidget::freezeMulti, [&](const QVector<int>& indexes) {
connect(ui->coinsWidget, &CoinsWidget::freeze, [&](const QVector<int>& indexes) {
for (int i : indexes) {
m_ctx->currentWallet->coins()->freeze(i);
m_ctx->currentWallet->coins()->refresh(m_ctx->currentWallet->currentSubaddressAccount());
m_ctx->updateBalance();
}
});
connect(ui->coinsWidget, &CoinsWidget::thaw, [=](int index) {
m_ctx->currentWallet->coins()->thaw(index);
m_ctx->currentWallet->coins()->refresh(m_ctx->currentWallet->currentSubaddressAccount());
m_ctx->updateBalance();
});
connect(ui->coinsWidget, &CoinsWidget::thawMulti, [&](const QVector<int>& indexes) {
connect(ui->coinsWidget, &CoinsWidget::thaw, [&](const QVector<int>& indexes) {
for (int i : indexes) {
m_ctx->currentWallet->coins()->thaw(i);
m_ctx->currentWallet->coins()->refresh(m_ctx->currentWallet->currentSubaddressAccount());
m_ctx->updateBalance();
}
m_ctx->currentWallet->coins()->refresh(m_ctx->currentWallet->currentSubaddressAccount());
m_ctx->updateBalance();
});
connect(ui->coinsWidget, &CoinsWidget::sweepOutput, m_ctx, &AppContext::onSweepOutput);

View file

@ -3,17 +3,22 @@
#include "CoinsProxyModel.h"
#include "CoinsModel.h"
#include "libwalletqt/CoinsInfo.h"
CoinsProxyModel::CoinsProxyModel(QObject *parent)
: QSortFilterProxyModel(parent)
CoinsProxyModel::CoinsProxyModel(QObject *parent, Coins *coins)
: QSortFilterProxyModel(parent), m_coins(coins)
{
setSortRole(Qt::UserRole);
}
bool CoinsProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
QModelIndex spentIndex = sourceModel()->index(sourceRow, CoinsModel::Spent, sourceParent);
bool isSpent = sourceModel()->data(spentIndex).toBool();
bool isSpent;
int accountIndex;
m_coins->coin(sourceRow, [&isSpent, &accountIndex](const CoinsInfo &c){
isSpent = c.spent();
accountIndex = c.subaddrAccount();
});
return !(!m_showSpent && isSpent);
return !(!m_showSpent && isSpent) && accountIndex == 0;
}

View file

@ -5,12 +5,13 @@
#define FEATHER_COINSPROXYMODEL_H
#include <QSortFilterProxyModel>
#include "libwalletqt/Coins.h"
class CoinsProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
explicit CoinsProxyModel(QObject* parent = nullptr);
explicit CoinsProxyModel(QObject* parent, Coins *coins);
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
public slots:
@ -21,6 +22,7 @@ public slots:
private:
bool m_showSpent = false;
Coins *m_coins;
};
#endif //FEATHER_COINSPROXYMODEL_H