Skip to content

Commit

Permalink
[Qt] Fix deprecated pixmap() return by pointer with Qt 5.15
Browse files Browse the repository at this point in the history
Summary:
The `pixmap()` method returning a `QImage *` is deprecated with Qt 5.15.
It is replaced by a new `pixmap(Qt::ReturnByValue)` call which returns
by value as its name implies.

Test Plan:
  ninja all check

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Subscribers: deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D6573
  • Loading branch information
Fabcien authored and ftrader committed Jul 3, 2020
1 parent 6342f98 commit cc158f3
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/qt/bitcoingui.cpp
Expand Up @@ -1285,7 +1285,7 @@ void BitcoinGUI::updateProxyIcon() {
bool proxy_enabled = clientModel->getProxyInfo(ip_port);

if (proxy_enabled) {
if (labelProxyIcon->pixmap() == nullptr) {
if (!labelProxyIcon->hasPixmap()) {
QString ip_port_q = QString::fromStdString(ip_port);
labelProxyIcon->setPixmap(
platformStyle->SingleColorIcon(":/icons/proxy")
Expand Down
8 changes: 8 additions & 0 deletions src/qt/guiutil.cpp
Expand Up @@ -951,6 +951,14 @@ QString formatBytes(uint64_t bytes) {
return QString(QObject::tr("%1 GB")).arg(bytes / 1024 / 1024 / 1024);
}

bool ClickableLabel::hasPixmap() const {
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
return !pixmap(Qt::ReturnByValue).isNull();
#else
return pixmap() != nullptr;
#endif
}

void ClickableLabel::mouseReleaseEvent(QMouseEvent *event) {
Q_EMIT clicked(event->pos());
}
Expand Down
3 changes: 3 additions & 0 deletions src/qt/guiutil.h
Expand Up @@ -241,6 +241,9 @@ QString formatBytes(uint64_t bytes);
class ClickableLabel : public QLabel {
Q_OBJECT

public:
bool hasPixmap() const;

Q_SIGNALS:
/** Emitted when the label is clicked. The relative mouse coordinates of the
* click are passed to the signal.
Expand Down
25 changes: 17 additions & 8 deletions src/qt/receiverequestdialog.cpp
Expand Up @@ -40,15 +40,24 @@ QRImageWidget::QRImageWidget(QWidget *parent)
contextMenu->addAction(copyImageAction);
}

bool QRImageWidget::hasPixmap() const {
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
return !pixmap(Qt::ReturnByValue).isNull();
#else
return pixmap() != nullptr;
#endif
}

QImage QRImageWidget::exportImage() {
if (!pixmap()) {
return QImage();
}
return pixmap()->toImage();
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
return pixmap(Qt::ReturnByValue).toImage();
#else
return hasPixmap() ? pixmap()->toImage() : QImage();
#endif
}

void QRImageWidget::mousePressEvent(QMouseEvent *event) {
if (event->button() == Qt::LeftButton && pixmap()) {
if (event->button() == Qt::LeftButton && hasPixmap()) {
event->accept();
QMimeData *mimeData = new QMimeData;
mimeData->setImageData(exportImage());
Expand All @@ -62,7 +71,7 @@ void QRImageWidget::mousePressEvent(QMouseEvent *event) {
}

void QRImageWidget::saveImage() {
if (!pixmap()) {
if (!hasPixmap()) {
return;
}
QString fn = GUIUtil::getSaveFileName(this, tr("Save QR Code"), QString(),
Expand All @@ -73,14 +82,14 @@ void QRImageWidget::saveImage() {
}

void QRImageWidget::copyImage() {
if (!pixmap()) {
if (!hasPixmap()) {
return;
}
QApplication::clipboard()->setImage(exportImage());
}

void QRImageWidget::contextMenuEvent(QContextMenuEvent *event) {
if (!pixmap()) {
if (!hasPixmap()) {
return;
}
contextMenu->exec(event->globalPos());
Expand Down
1 change: 1 addition & 0 deletions src/qt/receiverequestdialog.h
Expand Up @@ -29,6 +29,7 @@ class QRImageWidget : public QLabel {

public:
explicit QRImageWidget(QWidget *parent = nullptr);
bool hasPixmap() const;
QImage exportImage();

public Q_SLOTS:
Expand Down

0 comments on commit cc158f3

Please sign in to comment.