]> granicus.if.org Git - graphviz/commitdiff
gvedit: modernize 'QLabel::pixmap' calls
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Mon, 14 Nov 2022 03:52:37 +0000 (19:52 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Thu, 17 Nov 2022 05:09:01 +0000 (21:09 -0800)
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

cmd/gvedit/imageviewer.cpp

index e8ef3a60f9ef1cf61aeb3e00b28d37047e70408a..a19f6e7d0cb317b8d769fa64ec3fa80341801b56 100644 (file)
@@ -11,6 +11,7 @@
 
 #include "imageviewer.h"
 #include "mdichild.h"
+#include <QtGlobal>
 
 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);