Mercurial > octave
changeset 32008:4d15e1304a48
build: Check for Qt function QTextStream::setEncoding.
* m4/acinclude.m4 (OCTAVE_CHECK_FUNC_QTEXTSTREAM_SETENCODING): Check whether
the Qt class QTextStream has the member function setEncoding.
* libgui/src/m-editor/file-editor-tab.cc (file_editor_tab::do_save_file),
src/octave-svgconvert.cc (main): Use QTextStream::setCodec if
QTextStream::setEncoding isn't available.
* libgui/src/m-edit/file-editor-tab.h: Move including QTextCodec header from
file-editor-tab.cc to here.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Thu, 13 Apr 2023 16:17:45 +0200 |
parents | 21751aa15273 |
children | a96980ad4b57 |
files | libgui/src/m-editor/file-editor-tab.cc libgui/src/m-editor/file-editor-tab.h m4/acinclude.m4 src/octave-svgconvert.cc |
diffstat | 4 files changed, 44 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc Thu Apr 13 14:50:45 2023 +0200 +++ b/libgui/src/m-editor/file-editor-tab.cc Thu Apr 13 16:17:45 2023 +0200 @@ -50,9 +50,9 @@ #include <QStandardPaths> #include <QStyle> #include <QTextBlock> -#include <QTextCodec> #include <QTextStream> #include <QVBoxLayout> + #if defined (HAVE_QSCI_QSCILEXEROCTAVE_H) # define HAVE_LEXER_OCTAVE 1 # include <Qsci/qscilexeroctave.h> @@ -2351,6 +2351,9 @@ // write the file QTextStream out (&file); +#if HAVE_QTEXTSTREAM_SETENCODING + // FIXME: Check and set encoding! +#else // set the desired codec (if suitable for contents) QTextCodec *codec = check_valid_codec (); if (! codec) @@ -2358,6 +2361,7 @@ // Save the file out.setCodec (codec); +#endif QApplication::setOverrideCursor (Qt::WaitCursor);
--- a/libgui/src/m-editor/file-editor-tab.h Thu Apr 13 14:50:45 2023 +0200 +++ b/libgui/src/m-editor/file-editor-tab.h Thu Apr 13 16:17:45 2023 +0200 @@ -33,6 +33,7 @@ #include <QFileSystemWatcher> #include <QLabel> #include <QStatusBar> +#include <QTextCodec> #include <QWidget> #include <Qsci/qsciapis.h>
--- a/m4/acinclude.m4 Thu Apr 13 14:50:45 2023 +0200 +++ b/m4/acinclude.m4 Thu Apr 13 16:17:45 2023 +0200 @@ -464,7 +464,7 @@ ]) dnl dnl Check whether the Qt class QHelpEngine has the documentsForIdentifier -dnl function. dnl This member function was introduced in Qt 5.15. +dnl function. This member function was introduced in Qt 5.15. dnl dnl FIXME: Delete this entirely when we drop support for Qt 5.14 or older. dnl @@ -691,6 +691,38 @@ fi ]) dnl +dnl Check whether the Qt class QTextStream has the setEncoding function. +dnl This function was introduced replacing QTextStream::setCodec in Qt6. +dnl +dnl FIXME: Delete this check when we drop support for any version of Qt5. +dnl +AC_DEFUN([OCTAVE_CHECK_FUNC_QTEXTSTREAM_SETENCODING], [ + AC_CACHE_CHECK([for QTextStream::setEncoding], + [octave_cv_func_qtextstream_setencoding], + [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 <QStringConverter> + #include <QTextStream> + ]], [[ + QTextStream textstream; + textstream.setEncoding (QStringConverter::Utf8); + ]])], + octave_cv_func_qtextstream_setencoding=yes, + octave_cv_func_qtextstream_setencoding=no) + CPPFLAGS="$ac_octave_save_CPPFLAGS" + CXXFLAGS="$ac_octave_save_CXXFLAGS" + AC_LANG_POP(C++) + ]) + if test $octave_cv_func_qtextstream_setencoding = yes; then + AC_DEFINE(HAVE_QTEXTSTREAM_SETENCODING, 1, + [Define to 1 if you have the `QTextStream::setEncoding' member function.]) + fi +]) +dnl dnl Check whether HDF5 library has version 1.6 API functions. dnl AC_DEFUN([OCTAVE_CHECK_HDF5_HAS_VER_16_API], [ @@ -2026,6 +2058,7 @@ OCTAVE_CHECK_FUNC_QPAINTER_SETRENDERHINT_LOSSLESS OCTAVE_CHECK_FUNC_QCOLOR_FLOAT_TYPE OCTAVE_CHECK_CLASS_QSTRINGVIEW + OCTAVE_CHECK_FUNC_QTEXTSTREAM_SETENCODING OCTAVE_CHECK_QREGION_ITERATORS OCTAVE_CHECK_QT_IMCURSORRECTANGLE_ENUM_VALUE
--- a/src/octave-svgconvert.cc Thu Apr 13 14:50:45 2023 +0200 +++ b/src/octave-svgconvert.cc Thu Apr 13 16:17:45 2023 +0200 @@ -1009,7 +1009,11 @@ { // Return modified svg document QTextStream out (&fout); +#if HAVE_QTEXTSTREAM_SETENCODING + out.setEncoding (QStringConverter::Utf8); +#else out.setCodec ("UTF-8"); +#endif out << document.toByteArray (); }