changeset 29482:67f1d5fc69bb

avoid warning about deprecated Qprinter::setPaperSize function * acinclude.m4 (OCTAVE_CHECK_FUNC_QPRINTER_SETPAGESIZE): New macro. (OCTAVE_CHECK_QT_VERSION): Use it. * octave-svgconvert.cc: Include config.h. Use QPrinter::setPageSize if it is available instead of the deprecated QPrinter::setPaperSize function.
author John W. Eaton <jwe@octave.org>
date Fri, 02 Apr 2021 01:32:39 -0400
parents 7b160bf6b897
children af41ebf3d1b3
files m4/acinclude.m4 src/octave-svgconvert.cc
diffstat 2 files changed, 40 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/m4/acinclude.m4	Thu Apr 01 19:42:37 2021 +0200
+++ b/m4/acinclude.m4	Fri Apr 02 01:32:39 2021 -0400
@@ -639,6 +639,37 @@
   fi
 ])
 dnl
+dnl Check whether the Qt class QPrinter has the setPageSize member function.
+dnl This member function was introduced in Qt 5.3.
+dnl
+dnl FIXME: remove this test when we drop support for Qt older than 5.3.
+dnl
+AC_DEFUN([OCTAVE_CHECK_FUNC_QPRINTER_SETPAGESIZE], [
+  AC_CACHE_CHECK([for QPrinter::setPageSize in <QPrinter>],
+    [octave_cv_func_qprinter_setpagesizes],
+    [AC_LANG_PUSH(C++)
+    ac_octave_save_CPPFLAGS="$CPPFLAGS"
+    ac_octave_save_CXXFLAGS="$CXXFLAGS"
+    CPPFLAGS="$QT_CPPFLAGS $CXXPICFLAG $CPPFLAGS"
+    CXXFLAGS="$CXXPICFLAG $CXXFLAGS"
+    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+        #include <QPrinter>
+        ]], [[
+        QPrinter printer;
+        printer.setPageSize (QPageSize (QSizeF (8.5, 11.0), QPageSize::Inch));
+        ]])],
+      octave_cv_func_qprinter_setpagesize=yes,
+      octave_cv_func_qprinter_setpagesize=no)
+    CPPFLAGS="$ac_octave_save_CPPFLAGS"
+    CXXFLAGS="$ac_octave_save_CXXFLAGS"
+    AC_LANG_POP(C++)
+  ])
+  if test $octave_cv_func_qprinter_setpagesize = yes; then
+    AC_DEFINE(HAVE_QPRINTER_SETPAGESIZE, 1,
+      [Define to 1 if you have the 'QPrinter::setPageSize' member function.])
+  fi
+])
+dnl
 dnl Check whether the Qt class QScreen has the devicePixelRatio member function.
 dnl This member function was introduced in Qt 5.5.
 dnl
@@ -2136,6 +2167,7 @@
     OCTAVE_CHECK_NEW_QHELPINDEXWIDGET_API
     OCTAVE_CHECK_FUNC_QLIST_ITERATOR_CONSTRUCTOR
     OCTAVE_CHECK_FUNC_QMAINWINDOW_RESIZEDOCKS
+    OCTAVE_CHECK_FUNC_QPRINTER_SETPAGESIZE
     OCTAVE_CHECK_FUNC_QSCREEN_DEVICEPIXELRATIO
     OCTAVE_CHECK_FUNC_QHELPENGINE_DOCUMENTSFORIDENTIFIER
     OCTAVE_CHECK_FUNC_QWHEELEVENT_ANGLEDELTA
--- a/src/octave-svgconvert.cc	Thu Apr 01 19:42:37 2021 +0200
+++ b/src/octave-svgconvert.cc	Fri Apr 02 01:32:39 2021 -0400
@@ -23,6 +23,10 @@
 //
 ////////////////////////////////////////////////////////////////////////
 
+#if defined (HAVE_CONFIG_H)
+#  include "config.h"
+#endif
+
 #include <iostream>
 
 #include <QtCore>
@@ -52,7 +56,11 @@
     m_printer.setFontEmbeddingEnabled (true);
     m_printer.setOutputFileName (fname);
     m_printer.setFullPage (true);
+#if defined (HAVE_QPRINTER_SETPAGESIZE)
+    m_printer.setPageSize (QPageSize (sz.size (), QPageSize::Point));
+#else
     m_printer.setPaperSize (sz.size (), QPrinter::DevicePixel);
+#endif
   }
 
   ~pdfpainter (void) { }