Merge pull request 'Receive: Fix qr code segfault' (#152) from tobtoht/feather:qr_code_crash into master

Reviewed-on: https://git.wownero.com/feather/feather/pulls/152
This commit is contained in:
tobtoht 2020-11-14 11:17:04 +00:00
commit d58259cefe
3 changed files with 18 additions and 12 deletions

View file

@ -633,8 +633,7 @@ bool Wallet::refresh(bool historyAndSubaddresses /* = true */)
m_subaddress->refresh(currentSubaddressAccount()); m_subaddress->refresh(currentSubaddressAccount());
m_subaddressAccount->getAll(); m_subaddressAccount->getAll();
} }
if (result)
emit updated();
return result; return result;
} }
} }

View file

@ -51,15 +51,12 @@ void ReceiveWidget::setModel(SubaddressModel * model, Subaddress * subaddress) {
ui->addresses->header()->setSectionResizeMode(SubaddressModel::Label, QHeaderView::ResizeToContents); ui->addresses->header()->setSectionResizeMode(SubaddressModel::Label, QHeaderView::ResizeToContents);
ui->addresses->header()->setMinimumSectionSize(200); ui->addresses->header()->setMinimumSectionSize(200);
connect(ui->addresses->selectionModel(), &QItemSelectionModel::currentRowChanged, [=](QModelIndex current, QModelIndex prev){ connect(ui->addresses->selectionModel(), &QItemSelectionModel::currentChanged, [=](QModelIndex current, QModelIndex prev){
if (current.isValid()) this->updateQrCode();
this->setQrCode(current.model()->data(current.siblingAtColumn(SubaddressModel::Address), Qt::UserRole).toString()); });
else connect(m_model, &SubaddressModel::modelReset, [this](){
ui->qrCode->clear(); this->updateQrCode();
}); });
// connect(m_model, &SubaddressModel::modelReset, [this](){
// ui->btn_generateSubaddress->setEnabled(m_model->unusedLookahead() < SUBADDRESS_LOOKAHEAD_MINOR);
// });
} }
void ReceiveWidget::copyAddress() { void ReceiveWidget::copyAddress() {
@ -129,7 +126,14 @@ void ReceiveWidget::showHeaderMenu(const QPoint& position)
m_headerMenu->exec(QCursor::pos()); m_headerMenu->exec(QCursor::pos());
} }
void ReceiveWidget::setQrCode(const QString &address){ void ReceiveWidget::updateQrCode(){
QModelIndex index = ui->addresses->currentIndex();
if (!index.isValid()) {
ui->qrCode->clear();
return;
}
QString address = index.model()->data(index.siblingAtColumn(SubaddressModel::Address), Qt::UserRole).toString();
const QrCode qrc(address, QrCode::Version::AUTO, QrCode::ErrorCorrectionLevel::MEDIUM); const QrCode qrc(address, QrCode::Version::AUTO, QrCode::ErrorCorrectionLevel::MEDIUM);
int width = ui->qrCode->width() - 4; int width = ui->qrCode->width() - 4;
@ -140,6 +144,9 @@ void ReceiveWidget::setQrCode(const QString &address){
void ReceiveWidget::showQrCodeDialog() { void ReceiveWidget::showQrCodeDialog() {
QModelIndex index = ui->addresses->currentIndex(); QModelIndex index = ui->addresses->currentIndex();
if (!index.isValid()) {
return;
}
QString address = index.model()->data(index.siblingAtColumn(SubaddressModel::Address), Qt::UserRole).toString(); QString address = index.model()->data(index.siblingAtColumn(SubaddressModel::Address), Qt::UserRole).toString();
QrCode qr(address, QrCode::Version::AUTO, QrCode::ErrorCorrectionLevel::HIGH); QrCode qr(address, QrCode::Version::AUTO, QrCode::ErrorCorrectionLevel::HIGH);
auto *dialog = new QrCodeDialog(this, qr, "Address"); auto *dialog = new QrCodeDialog(this, qr, "Address");

View file

@ -54,7 +54,7 @@ private:
SubaddressModel * m_model; SubaddressModel * m_model;
SubaddressProxyModel * m_proxyModel; SubaddressProxyModel * m_proxyModel;
void setQrCode(const QString &address); void updateQrCode();
void showQrCodeDialog(); void showQrCodeDialog();
}; };