Skip to content

Commit

Permalink
GUI: Remove unused, and invalid, cached QR pixmap pointer.
Browse files Browse the repository at this point in the history
Plus delete AddNewContactDialog dialog after use it.

Github-Pull: #2555
Rebased-From: c5e81a1
  • Loading branch information
furszy committed Sep 20, 2021
1 parent 798c3e9 commit 2981a17
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 27 deletions.
10 changes: 5 additions & 5 deletions src/qt/pivx/receivedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
#include "qt/pivx/receivedialog.h"
#include "qt/pivx/forms/ui_receivedialog.h"
#include "qt/pivx/qtutils.h"
#include "walletmodel.h"
#include <QFile>
#include "qt/walletmodel.h"

#include <QPixmap>

ReceiveDialog::ReceiveDialog(QWidget *parent) :
FocusedDialog(parent),
Expand Down Expand Up @@ -45,7 +46,7 @@ ReceiveDialog::ReceiveDialog(QWidget *parent) :
connect(ui->btnSave, &QPushButton::clicked, this, &ReceiveDialog::onCopy);
}

void ReceiveDialog::updateQr(QString address)
void ReceiveDialog::updateQr(const QString& address)
{
if (!info) info = new SendCoinsRecipient();
info->address = address;
Expand All @@ -55,8 +56,7 @@ void ReceiveDialog::updateQr(QString address)
QString error;
QPixmap pixmap = encodeToQr(uri, error);
if (!pixmap.isNull()) {
qrImage = &pixmap;
ui->labelQrImg->setPixmap(qrImage->scaled(ui->labelQrImg->width(), ui->labelQrImg->height()));
ui->labelQrImg->setPixmap(pixmap.scaled(ui->labelQrImg->width(), ui->labelQrImg->height()));
} else {
ui->labelQrImg->setText(!error.isEmpty() ? error : "Error encoding address");
}
Expand Down
4 changes: 1 addition & 3 deletions src/qt/pivx/receivedialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#define RECEIVEDIALOG_H

#include "qt/pivx/focuseddialog.h"
#include <QPixmap>

class SendCoinsRecipient;

Expand All @@ -22,13 +21,12 @@ class ReceiveDialog : public FocusedDialog
explicit ReceiveDialog(QWidget *parent = nullptr);
~ReceiveDialog();

void updateQr(QString address);
void updateQr(const QString& address);

private Q_SLOTS:
void onCopy();
private:
Ui::ReceiveDialog *ui{nullptr};
QPixmap *qrImage{nullptr};
SendCoinsRecipient *info{nullptr};
};

Expand Down
12 changes: 5 additions & 7 deletions src/qt/pivx/receivewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "qt/pivx/addnewcontactdialog.h"
#include "qt/pivx/qtutils.h"
#include "qt/pivx/myaddressrow.h"
#include "qt/pivx/furlistrow.h"
#include "qt/pivx/addressholder.h"
#include "walletmodel.h"
#include "guiutil.h"
Expand Down Expand Up @@ -145,11 +144,10 @@ void ReceiveWidget::refreshView(const QModelIndex& tl, const QModelIndex& br)
return refreshView(index.data(Qt::DisplayRole).toString());
}

void ReceiveWidget::refreshView(QString refreshAddress)
void ReceiveWidget::refreshView(const QString& refreshAddress)
{
try {
QString latestAddress = (refreshAddress.isEmpty()) ? this->addressTableModel->getAddressToShow(shieldedMode) : refreshAddress;

const QString& latestAddress = (refreshAddress.isEmpty()) ? addressTableModel->getAddressToShow(shieldedMode) : refreshAddress;
if (latestAddress.isEmpty()) {
// Check for generation errors
ui->labelQrImg->setText(tr("No available address\ntry unlocking the wallet"));
Expand Down Expand Up @@ -189,7 +187,7 @@ void ReceiveWidget::updateLabel()
}
}

void ReceiveWidget::updateQr(QString& address)
void ReceiveWidget::updateQr(const QString& address)
{
info->address = address;
QString uri = GUIUtil::formatBitcoinURI(*info);
Expand All @@ -199,8 +197,7 @@ void ReceiveWidget::updateQr(QString& address)
QColor qrColor("#382d4d");
QPixmap pixmap = encodeToQr(uri, error, qrColor);
if (!pixmap.isNull()) {
qrImage = &pixmap;
ui->labelQrImg->setPixmap(qrImage->scaled(ui->labelQrImg->width(), ui->labelQrImg->height()));
ui->labelQrImg->setPixmap(pixmap.scaled(ui->labelQrImg->width(), ui->labelQrImg->height()));
} else {
ui->labelQrImg->setText(!error.isEmpty() ? error : "Error encoding address");
}
Expand Down Expand Up @@ -236,6 +233,7 @@ void ReceiveWidget::onLabelClicked()
inform(tr("Error storing address label"));
}
}
dialog->deleteLater();
isShowingDialog = false;
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/qt/pivx/receivewidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private Q_SLOTS:
void onLabelClicked();
void onCopyClicked();
void refreshView(const QModelIndex& tl, const QModelIndex& br);
void refreshView(QString refreshAddress = QString());
void refreshView(const QString& refreshAddress = QString());
void handleAddressClicked(const QModelIndex &index);
void onSortChanged(int idx);
void onSortOrderChanged(int idx);
Expand All @@ -62,14 +62,12 @@ private Q_SLOTS:

// Cached last address
SendCoinsRecipient *info{nullptr};
// Cached qr
QPixmap *qrImage{nullptr};

// Cached sort type and order
AddressTableModel::ColumnIndex sortType = AddressTableModel::Label;
Qt::SortOrder sortOrder = Qt::AscendingOrder;

void updateQr(QString& address);
void updateQr(const QString& address);
void updateLabel();
void showAddressGenerationDialog(bool isPaymentRequest);
void sortAddresses();
Expand Down
7 changes: 3 additions & 4 deletions src/qt/pivx/requestdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,21 +162,20 @@ void RequestDialog::showEvent(QShowEvent *event)
if (ui->lineEditAmount) ui->lineEditAmount->setFocus();
}

void RequestDialog::updateQr(QString str)
void RequestDialog::updateQr(const QString& str)
{
QString uri = GUIUtil::formatBitcoinURI(*info);
ui->labelQrImg->setText("");
QString error;
QPixmap pixmap = encodeToQr(uri, error);
if (!pixmap.isNull()) {
qrImage = &pixmap;
ui->labelQrImg->setPixmap(qrImage->scaled(ui->labelQrImg->width(), ui->labelQrImg->height()));
ui->labelQrImg->setPixmap(pixmap.scaled(ui->labelQrImg->width(), ui->labelQrImg->height()));
} else {
ui->labelQrImg->setText(!error.isEmpty() ? error : "Error encoding address");
}
}

void RequestDialog::inform(QString text)
void RequestDialog::inform(const QString& text)
{
if (!snackBar)
snackBar = new SnackBar(nullptr, this);
Expand Down
6 changes: 2 additions & 4 deletions src/qt/pivx/requestdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,8 @@ private Q_SLOTS:
// Cached last address
SendCoinsRecipient *info{nullptr};

QPixmap *qrImage{nullptr};

void updateQr(QString str);
void inform(QString text);
void updateQr(const QString& str);
void inform(const QString& text);
};

#endif // REQUESTDIALOG_H

0 comments on commit 2981a17

Please sign in to comment.