Mercurial > octave
changeset 28835:2735fb9007e9 stable
avoid QList deprecated function warnings
* libgui/src/qt-utils.h: New file.
* libgui/src/module.mk: Update.
* qt-interpreter-events.cc: Avoid deprecated QList<T>::fromStdList and
QList<T>::toStdList functions.
* acinclude.m4 (OCTAVE_CHECK_FUNC_QLIST_ITERATOR_CONSTRUCTOR): New macro.
(OCTAVE_CHECK_QT_VERSION): Use it.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 13 Jul 2020 14:57:22 -0400 |
parents | 27df9b38391d |
children | d0a64e67749e |
files | libgui/src/module.mk libgui/src/qt-interpreter-events.cc libgui/src/qt-utils.h m4/acinclude.m4 |
diffstat | 4 files changed, 85 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/module.mk Wed Sep 30 08:45:42 2020 +0200 +++ b/libgui/src/module.mk Mon Jul 13 14:57:22 2020 -0400 @@ -222,6 +222,7 @@ %reldir%/octave-qobject.h \ %reldir%/qt-application.h \ %reldir%/qt-interpreter-events.h \ + %reldir%/qt-utils.h \ %reldir%/resource-manager.h \ %reldir%/settings-dialog.h \ %reldir%/shortcut-manager.h \
--- a/libgui/src/qt-interpreter-events.cc Wed Sep 30 08:45:42 2020 +0200 +++ b/libgui/src/qt-interpreter-events.cc Mon Jul 13 14:57:22 2020 -0400 @@ -38,6 +38,7 @@ #include "gui-preferences-ed.h" #include "octave-qobject.h" #include "qt-interpreter-events.h" +#include "qt-utils.h" #include "localcharset-wrapper.h" #include "oct-env.h" @@ -161,8 +162,8 @@ QStringList lst = m_uiwidget_creator.input_dialog (make_qstring_list (prompt), QString::fromStdString (title), - QFloatList::fromStdList (nr), - QFloatList::fromStdList (nc), + std_list_to_qt_list<float> (nr), + std_list_to_qt_list<float> (nc), make_qstring_list (defaults)); std::list<std::string> retval; @@ -186,13 +187,15 @@ = m_uiwidget_creator.list_dialog (make_qstring_list (list), QString::fromStdString (mode), width, height, - QList<int>::fromStdList (initial), + std_list_to_qt_list<int> (initial), QString::fromStdString (name), make_qstring_list (prompt), QString::fromStdString (ok_string), QString::fromStdString (cancel_string)); - return std::pair<std::list<int>, int> (result.first.toStdList (), + QIntList& lst = result.first; + return std::pair<std::list<int>, int> (std::list<int> (lst.begin (), + lst.end ()), result.second); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/qt-utils.h Mon Jul 13 14:57:22 2020 -0400 @@ -0,0 +1,47 @@ +//////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2020 The Octave Project Developers +// +// See the file COPYRIGHT.md in the top-level directory of this +// distribution or <https://octave.org/copyright/>. +// +// This file is part of Octave. +// +// Octave is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Octave is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Octave; see the file COPYING. If not, see +// <https://www.gnu.org/licenses/>. +// +//////////////////////////////////////////////////////////////////////// + +#if ! defined (octave_qt_utils_h) +#define octave_qt_utils_h 1 + +#include <list> + +#include <QList> + +namespace octave +{ + template <typename T> + QList<T> + std_list_to_qt_list (const std::list<T>& lst) + { +#if defined (HAVE_QLIST_ITERATOR_CONSTRUCTOR) + return QList<T> (lst.begin (), lst.end ()); +#else + return QList<T>::fromStdList (lst); +#endif + } +} + +#endif
--- a/m4/acinclude.m4 Wed Sep 30 08:45:42 2020 +0200 +++ b/m4/acinclude.m4 Mon Jul 13 14:57:22 2020 -0400 @@ -867,6 +867,35 @@ fi ]) dnl +dnl Check whether the Qt class QList has a constructor that accepts +dnl a pair of iterators. This constructor was introduced in Qt 5.14. +dnl +AC_DEFUN([OCTAVE_CHECK_FUNC_QLIST_ITERATOR_CONSTRUCTOR], [ + AC_CACHE_CHECK([for QList<T>::QList (iterator, iterator) constructor], + [octave_cv_func_qlist_iterator_constructor], + [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 <QList> + ]], [[ + QList<int> lst_one; + QList<int> lst_two (lst_one.begin (), lst_one.end ()); + ]])], + octave_cv_func_qlist_iterator_constructor=yes, + octave_cv_func_qlist_iterator_constructor=no) + CPPFLAGS="$ac_octave_save_CPPFLAGS" + CXXFLAGS="$ac_octave_save_CXXFLAGS" + AC_LANG_POP(C++) + ]) + if test $octave_cv_func_qlist_iterator_constructor = yes; then + AC_DEFINE(HAVE_QLIST_ITERATOR_CONSTRUCTOR, 1, + [Define to 1 if you have the `QList<T>::QList (iterator, iterator)' constructor.]) + fi +]) +dnl dnl Check whether HDF5 library has version 1.6 API functions. dnl AC_DEFUN([OCTAVE_CHECK_HDF5_HAS_VER_16_API], [ @@ -2268,6 +2297,7 @@ OCTAVE_CHECK_FUNC_QHELPSEARCHQUERYWIDGET_SEARCHINPUT OCTAVE_CHECK_FUNC_QINSTALLMESSAGEHANDLER OCTAVE_CHECK_FUNC_QLINEEDIT_SETPLACEHOLDERTEXT + OCTAVE_CHECK_FUNC_QLIST_ITERATOR_CONSTRUCTOR OCTAVE_CHECK_FUNC_QMOUSEEVENT_LOCALPOS OCTAVE_CHECK_FUNC_QOBJECT_FINDCHILDREN_ACCEPTS_FINDCHILDOPTIONS OCTAVE_CHECK_FUNC_QSCREEN_DEVICEPIXELRATIO