mirror of
https://git.wownero.com/wowlet/wowlet.git
synced 2024-08-15 01:03:14 +00:00
Merge pull request 'Coins: improve freeze/thaw performance and fix indexing bug' (#325) from tobtoht/feather:coins_bug into master
Reviewed-on: https://git.wownero.com/feather/feather/pulls/325
This commit is contained in:
commit
ac2ca5a81b
6 changed files with 26 additions and 34 deletions
|
@ -61,7 +61,7 @@ CoinsWidget::CoinsWidget(QWidget *parent)
|
||||||
void CoinsWidget::setModel(CoinsModel * model, Coins * coins) {
|
void CoinsWidget::setModel(CoinsModel * model, Coins * coins) {
|
||||||
m_coins = coins;
|
m_coins = coins;
|
||||||
m_model = model;
|
m_model = model;
|
||||||
m_proxyModel = new CoinsProxyModel(this);
|
m_proxyModel = new CoinsProxyModel(this, m_coins);
|
||||||
m_proxyModel->setSourceModel(m_model);
|
m_proxyModel->setSourceModel(m_model);
|
||||||
ui->coins->setModel(m_proxyModel);
|
ui->coins->setModel(m_proxyModel);
|
||||||
ui->coins->setColumnHidden(CoinsModel::Spent, true);
|
ui->coins->setColumnHidden(CoinsModel::Spent, true);
|
||||||
|
@ -135,7 +135,8 @@ void CoinsWidget::setShowSpent(bool show)
|
||||||
|
|
||||||
void CoinsWidget::freezeOutput() {
|
void CoinsWidget::freezeOutput() {
|
||||||
QModelIndex index = ui->coins->currentIndex();
|
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() {
|
void CoinsWidget::freezeAllSelected() {
|
||||||
|
@ -145,12 +146,13 @@ void CoinsWidget::freezeAllSelected() {
|
||||||
for (QModelIndex index: list) {
|
for (QModelIndex index: list) {
|
||||||
indexes.push_back(m_proxyModel->mapToSource(index).row()); // todo: will segfault if index get invalidated
|
indexes.push_back(m_proxyModel->mapToSource(index).row()); // todo: will segfault if index get invalidated
|
||||||
}
|
}
|
||||||
emit freezeMulti(indexes);
|
emit freeze(indexes);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoinsWidget::thawOutput() {
|
void CoinsWidget::thawOutput() {
|
||||||
QModelIndex index = ui->coins->currentIndex();
|
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() {
|
void CoinsWidget::thawAllSelected() {
|
||||||
|
@ -160,7 +162,7 @@ void CoinsWidget::thawAllSelected() {
|
||||||
for (QModelIndex index: list) {
|
for (QModelIndex index: list) {
|
||||||
indexes.push_back(m_proxyModel->mapToSource(index).row());
|
indexes.push_back(m_proxyModel->mapToSource(index).row());
|
||||||
}
|
}
|
||||||
emit thawMulti(indexes);
|
emit thaw(indexes);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoinsWidget::viewOutput() {
|
void CoinsWidget::viewOutput() {
|
||||||
|
|
|
@ -39,10 +39,8 @@ private slots:
|
||||||
void onSweepOutput();
|
void onSweepOutput();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void freeze(int index);
|
void freeze(QVector<int> indexes);
|
||||||
void freezeMulti(QVector<int>);
|
void thaw(QVector<int> indexes);
|
||||||
void thaw(int index);
|
|
||||||
void thawMulti(QVector<int>);
|
|
||||||
void sweepOutput(const QString &keyImage, const QString &address, bool isChurn, int outputs);
|
void sweepOutput(const QString &keyImage, const QString &address, bool isChurn, int outputs);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -36,10 +36,6 @@ void Coins::refresh(quint32 accountIndex)
|
||||||
|
|
||||||
m_pimpl->refresh();
|
m_pimpl->refresh();
|
||||||
for (const auto i : m_pimpl->getAll()) {
|
for (const auto i : m_pimpl->getAll()) {
|
||||||
if (i->subaddrAccount() != accountIndex) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_tinfo.append(new CoinsInfo(i, this));
|
m_tinfo.append(new CoinsInfo(i, this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -289,30 +289,19 @@ MainWindow::MainWindow(AppContext *ctx, QWidget *parent) :
|
||||||
connect(m_ctx, &AppContext::openAliasResolved, ui->sendWidget, &SendWidget::onOpenAliasResolved);
|
connect(m_ctx, &AppContext::openAliasResolved, ui->sendWidget, &SendWidget::onOpenAliasResolved);
|
||||||
|
|
||||||
// Coins
|
// Coins
|
||||||
connect(ui->coinsWidget, &CoinsWidget::freeze, [=](int index) {
|
connect(ui->coinsWidget, &CoinsWidget::freeze, [&](const QVector<int>& indexes) {
|
||||||
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) {
|
|
||||||
for (int i : indexes) {
|
for (int i : indexes) {
|
||||||
m_ctx->currentWallet->coins()->freeze(i);
|
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->currentWallet->coins()->refresh(m_ctx->currentWallet->currentSubaddressAccount());
|
||||||
m_ctx->updateBalance();
|
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) {
|
for (int i : indexes) {
|
||||||
m_ctx->currentWallet->coins()->thaw(i);
|
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);
|
connect(ui->coinsWidget, &CoinsWidget::sweepOutput, m_ctx, &AppContext::onSweepOutput);
|
||||||
|
|
||||||
|
|
|
@ -3,17 +3,22 @@
|
||||||
|
|
||||||
#include "CoinsProxyModel.h"
|
#include "CoinsProxyModel.h"
|
||||||
#include "CoinsModel.h"
|
#include "CoinsModel.h"
|
||||||
|
#include "libwalletqt/CoinsInfo.h"
|
||||||
|
|
||||||
CoinsProxyModel::CoinsProxyModel(QObject *parent)
|
CoinsProxyModel::CoinsProxyModel(QObject *parent, Coins *coins)
|
||||||
: QSortFilterProxyModel(parent)
|
: QSortFilterProxyModel(parent), m_coins(coins)
|
||||||
{
|
{
|
||||||
setSortRole(Qt::UserRole);
|
setSortRole(Qt::UserRole);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CoinsProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
bool CoinsProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
||||||
{
|
{
|
||||||
QModelIndex spentIndex = sourceModel()->index(sourceRow, CoinsModel::Spent, sourceParent);
|
bool isSpent;
|
||||||
bool isSpent = sourceModel()->data(spentIndex).toBool();
|
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;
|
||||||
}
|
}
|
|
@ -5,12 +5,13 @@
|
||||||
#define FEATHER_COINSPROXYMODEL_H
|
#define FEATHER_COINSPROXYMODEL_H
|
||||||
|
|
||||||
#include <QSortFilterProxyModel>
|
#include <QSortFilterProxyModel>
|
||||||
|
#include "libwalletqt/Coins.h"
|
||||||
|
|
||||||
class CoinsProxyModel : public QSortFilterProxyModel
|
class CoinsProxyModel : public QSortFilterProxyModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit CoinsProxyModel(QObject* parent = nullptr);
|
explicit CoinsProxyModel(QObject* parent, Coins *coins);
|
||||||
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
|
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
@ -21,6 +22,7 @@ public slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_showSpent = false;
|
bool m_showSpent = false;
|
||||||
|
Coins *m_coins;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //FEATHER_COINSPROXYMODEL_H
|
#endif //FEATHER_COINSPROXYMODEL_H
|
||||||
|
|
Loading…
Reference in a new issue