From: Matthew Fernandez Date: Mon, 14 Nov 2022 03:52:37 +0000 (-0800) Subject: gvedit: modernize 'QLabel::pixmap' calls X-Git-Tag: 7.0.2~2^2~4 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=909cf594b91ae7c59c6eb22d8b9447ed05d99a79;p=graphviz gvedit: modernize 'QLabel::pixmap' calls Qt 5.15 deprecated the version of this function that returns a pointer and throws compiler warnings when calls to it are seen. This modernization is necessary to avoid the upcoming integration of Gvedit into the CMake build system failing in CI where `-Werror` is applied. Unfortunately we need to do this conditionally while retaining the old code for, e.g., CentOS 7 which has a version of Qt 5.15 that does not have the new API. Gitlab: #1836 --- diff --git a/cmd/gvedit/imageviewer.cpp b/cmd/gvedit/imageviewer.cpp index e8ef3a60f..a19f6e7d0 100644 --- a/cmd/gvedit/imageviewer.cpp +++ b/cmd/gvedit/imageviewer.cpp @@ -11,6 +11,7 @@ #include "imageviewer.h" #include "mdichild.h" +#include extern int errorPipe(char *errMsg); @@ -56,18 +57,25 @@ bool ImageViewer::open(QString fileName) void ImageViewer::print() { - Q_ASSERT(imageLabel->pixmap()); #ifndef QT_NO_PRINTER + auto get_pixmap = [&]() { +#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) + Q_ASSERT(imageLabel->pixmap()); + return *imageLabel->pixmap(); +#else + return imageLabel->pixmap(Qt::ReturnByValue); +#endif + }; QPrintDialog dialog(&printer, this); if (dialog.exec()) { QPainter painter(&printer); QRect rect = painter.viewport(); - QSize size = imageLabel->pixmap()->size(); + QSize size = get_pixmap().size(); size.scale(rect.size(), Qt::KeepAspectRatio); painter.setViewport(rect.x(), rect.y(), size.width(), size.height()); - painter.setWindow(imageLabel->pixmap()->rect()); - painter.drawPixmap(0, 0, *imageLabel->pixmap()); + painter.setWindow(get_pixmap().rect()); + painter.drawPixmap(0, 0, get_pixmap()); } #endif } @@ -178,9 +186,16 @@ void ImageViewer::updateActions() void ImageViewer::scaleImage(double factor) { - Q_ASSERT(imageLabel->pixmap()); + auto get_pixmap = [&]() { +#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) + Q_ASSERT(imageLabel->pixmap()); + return *imageLabel->pixmap(); +#else + return imageLabel->pixmap(Qt::ReturnByValue); +#endif + }; scaleFactor *= factor; - imageLabel->resize(scaleFactor * imageLabel->pixmap()->size()); + imageLabel->resize(scaleFactor * get_pixmap().size()); adjustScrollBar(scrollArea->horizontalScrollBar(), factor); adjustScrollBar(scrollArea->verticalScrollBar(), factor);