Mercurial > jwe > octave
changeset 29565:5b7e721844df
provide QOverload template if it is not in <QtGlobal> (bug #60416)
* libgui/src/octave-qtutils.h: New file.
* libgui/src/module.mk: Update.
* acinclude.m4 (OCTAVE_CHECK_QOVERLOAD_TEMPLATE): New macro.
(OCTAVE_CHECK_QT_VERSION): Use it.
* ButtonGroup.cc, PopupMenuControl.cc, documentation-bookmarks.cc,
files-dock-widget.cc, m-editor/file-editor-tab.cc,
m-editor/file-editor.cc, main-window.cc, set-path-dialog.cc,
settings-dialog.cc, variable-editor.cc, workspace-view.cc: Include
octave-qtutils.h in files that use the QOverload template.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 27 Apr 2021 11:11:54 -0400 |
parents | 4c85879e21b4 |
children | ed90a4d75f6d |
files | libgui/graphics/ButtonGroup.cc libgui/graphics/PopupMenuControl.cc libgui/src/documentation-bookmarks.cc libgui/src/files-dock-widget.cc libgui/src/m-editor/file-editor-tab.cc libgui/src/m-editor/file-editor.cc libgui/src/main-window.cc libgui/src/module.mk libgui/src/octave-qtutils.h libgui/src/set-path-dialog.cc libgui/src/settings-dialog.cc libgui/src/variable-editor.cc libgui/src/workspace-view.cc m4/acinclude.m4 |
diffstat | 14 files changed, 128 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/graphics/ButtonGroup.cc Tue Apr 27 11:08:38 2021 -0400 +++ b/libgui/graphics/ButtonGroup.cc Tue Apr 27 11:11:54 2021 -0400 @@ -46,6 +46,7 @@ #include "qt-graphics-toolkit.h" #include "octave-qobject.h" +#include "octave-qtutils.h" #include "interpreter.h" #include "oct-map.h"
--- a/libgui/graphics/PopupMenuControl.cc Tue Apr 27 11:08:38 2021 -0400 +++ b/libgui/graphics/PopupMenuControl.cc Tue Apr 27 11:11:54 2021 -0400 @@ -34,6 +34,7 @@ #include "QtHandlesUtils.h" #include "octave-qobject.h" +#include "octave-qtutils.h" namespace QtHandles {
--- a/libgui/src/documentation-bookmarks.cc Tue Apr 27 11:08:38 2021 -0400 +++ b/libgui/src/documentation-bookmarks.cc Tue Apr 27 11:11:54 2021 -0400 @@ -40,6 +40,7 @@ #include "gui-preferences-global.h" #include "gui-preferences-dc.h" #include "gui-preferences-sc.h" +#include "octave-qtutils.h" #include "shortcut-manager.h" #include "defaults.h"
--- a/libgui/src/files-dock-widget.cc Tue Apr 27 11:08:38 2021 -0400 +++ b/libgui/src/files-dock-widget.cc Tue Apr 27 11:11:54 2021 -0400 @@ -48,6 +48,7 @@ #include "gui-preferences-fb.h" #include "gui-preferences-global.h" #include "octave-qobject.h" +#include "octave-qtutils.h" #include "qt-interpreter-events.h" #include "interpreter.h"
--- a/libgui/src/m-editor/file-editor-tab.cc Tue Apr 27 11:08:38 2021 -0400 +++ b/libgui/src/m-editor/file-editor-tab.cc Tue Apr 27 11:11:54 2021 -0400 @@ -73,6 +73,7 @@ #include "gui-utils.h" #include "marker.h" #include "octave-qobject.h" +#include "octave-qtutils.h" #include "octave-txt-lexer.h" #include "cmd-edit.h"
--- a/libgui/src/m-editor/file-editor.cc Tue Apr 27 11:08:38 2021 -0400 +++ b/libgui/src/m-editor/file-editor.cc Tue Apr 27 11:11:54 2021 -0400 @@ -52,6 +52,7 @@ #include "gui-preferences-global.h" #include "main-window.h" #include "octave-qobject.h" +#include "octave-qtutils.h" #include "shortcut-manager.h" #include "oct-env.h"
--- a/libgui/src/main-window.cc Tue Apr 27 11:08:38 2021 -0400 +++ b/libgui/src/main-window.cc Tue Apr 27 11:11:54 2021 -0400 @@ -69,6 +69,7 @@ #include "main-window.h" #include "news-reader.h" #include "octave-qobject.h" +#include "octave-qtutils.h" #include "settings-dialog.h" #include "shortcut-manager.h" #include "welcome-wizard.h"
--- a/libgui/src/module.mk Tue Apr 27 11:08:38 2021 -0400 +++ b/libgui/src/module.mk Tue Apr 27 11:11:54 2021 -0400 @@ -229,6 +229,7 @@ %reldir%/main-window.h \ %reldir%/news-reader.h \ %reldir%/octave-qobject.h \ + %reldir%/octave-qtutils.h \ %reldir%/qt-application.h \ %reldir%/qt-interpreter-events.h \ %reldir%/qt-utils.h \
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/octave-qtutils.h Tue Apr 27 11:11:54 2021 -0400 @@ -0,0 +1,82 @@ +//////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2021 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_octave_qtutils_h) +#define octave_octave_qtutils_h 1 + +// This file should not be installed and should only be included in C++ +// source files after config.h is included, not in other header files. + +#if ! defined (HAVE_QOVERLOAD_TEMPLATE) + +// The following are copied directly from qglobal.h from Qt 5.15.2 with +// Q_DECL_CONSTEXPR replaced by constexpr so that we don't have to +// include any Qt headers or define any other special magic here. +// Octave requires C++11 so using constexpr should be OK. + +template <typename... Args> +struct QNonConstOverload +{ + template <typename R, typename T> + constexpr auto operator()(R (T::*ptr)(Args...)) const noexcept -> decltype(ptr) + { return ptr; } + + template <typename R, typename T> + static constexpr auto of(R (T::*ptr)(Args...)) noexcept -> decltype(ptr) + { return ptr; } +}; + +template <typename... Args> +struct QConstOverload +{ + template <typename R, typename T> + constexpr auto operator()(R (T::*ptr)(Args...) const) const noexcept -> decltype(ptr) + { return ptr; } + + template <typename R, typename T> + static constexpr auto of(R (T::*ptr)(Args...) const) noexcept -> decltype(ptr) + { return ptr; } +}; + +template <typename... Args> +struct QOverload : QConstOverload<Args...>, QNonConstOverload<Args...> +{ + using QConstOverload<Args...>::of; + using QConstOverload<Args...>::operator(); + using QNonConstOverload<Args...>::of; + using QNonConstOverload<Args...>::operator(); + + template <typename R> + constexpr auto operator()(R (*ptr)(Args...)) const noexcept -> decltype(ptr) + { return ptr; } + + template <typename R> + static constexpr auto of(R (*ptr)(Args...)) noexcept -> decltype(ptr) + { return ptr; } +}; + +#endif + +#endif
--- a/libgui/src/set-path-dialog.cc Tue Apr 27 11:08:38 2021 -0400 +++ b/libgui/src/set-path-dialog.cc Tue Apr 27 11:11:54 2021 -0400 @@ -51,6 +51,7 @@ #include "gui-preferences-pd.h" #include "octave-qobject.h" +#include "octave-qtutils.h" #include "set-path-dialog.h" #include "set-path-model.h"
--- a/libgui/src/settings-dialog.cc Tue Apr 27 11:08:38 2021 -0400 +++ b/libgui/src/settings-dialog.cc Tue Apr 27 11:11:54 2021 -0400 @@ -65,6 +65,7 @@ #include "gui-preferences-all.h" #include "octave-qobject.h" +#include "octave-qtutils.h" #include "settings-dialog.h" #include "variable-editor.h" #include "workspace-model.h"
--- a/libgui/src/variable-editor.cc Tue Apr 27 11:08:38 2021 -0400 +++ b/libgui/src/variable-editor.cc Tue Apr 27 11:11:54 2021 -0400 @@ -55,6 +55,7 @@ #include "gui-preferences-sc.h" #include "gui-preferences-ve.h" #include "octave-qobject.h" +#include "octave-qtutils.h" #include "ovl.h" #include "qt-utils.h" #include "shortcut-manager.h"
--- a/libgui/src/workspace-view.cc Tue Apr 27 11:08:38 2021 -0400 +++ b/libgui/src/workspace-view.cc Tue Apr 27 11:11:54 2021 -0400 @@ -43,6 +43,7 @@ #include "gui-preferences-ws.h" #include "octave-qobject.h" +#include "octave-qtutils.h" #include "workspace-view.h" #include "interpreter-private.h"
--- a/m4/acinclude.m4 Tue Apr 27 11:08:38 2021 -0400 +++ b/m4/acinclude.m4 Tue Apr 27 11:11:54 2021 -0400 @@ -1620,6 +1620,39 @@ fi ]) dnl +dnl Check whether Qt has the QOverload template introduced in Qt 5.7. +dnl +AC_DEFUN([OCTAVE_CHECK_QOVERLOAD_TEMPLATE], [ + AC_CACHE_CHECK([for QOverload template], + [octave_cv_qoverload_template], + [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 <QtGlobal> + ]], [[ + struct Foo + { + void overloadedFunction (int) const; + void overloadedFunction (int, const QString &) const; + }; + QOverload<int>::of (&Foo::overloadedFunction); + QOverload<int, const QString &>::of (&Foo::overloadedFunction); + ]])], + octave_cv_qoverload_template=yes, + octave_cv_qoverload_template=no) + CPPFLAGS="$ac_octave_save_CPPFLAGS" + CXXFLAGS="$ac_octave_save_CXXFLAGS" + AC_LANG_POP(C++) + ]) + if test $octave_cv_qoverload_template = yes; then + AC_DEFINE(HAVE_QOVERLOAD_TEMPLATE, 1, + [Define to 1 if you have the `QOverload' template.]) + fi +]) +dnl dnl Check whether the Qt class QRegion has the iterators and related dnl functions introduced in Qt 5.8. dnl @@ -2173,6 +2206,7 @@ OCTAVE_CHECK_FUNC_QWHEELEVENT_ANGLEDELTA OCTAVE_CHECK_FUNC_QWHEELEVENT_POSITION + OCTAVE_CHECK_QOVERLOAD_TEMPLATE OCTAVE_CHECK_QREGION_ITERATORS OCTAVE_CHECK_QT_SPLITBEHAVIOR_ENUM