# HG changeset patch # User Markus Mützel # Date 1683871394 -7200 # Node ID 212145b8e5f07dd53459c23849527a2cbd1fbf83 # Parent a4fbcbaa0aa2cc8f9ee2f275b99dbca87876d087# Parent e2911d0176dc7cb68fa9c8c6e528717ff8937f1d maint: Merge stable to default. diff -r e2911d0176dc -r 212145b8e5f0 .github/workflows/make.yaml --- a/.github/workflows/make.yaml Fri May 12 08:00:41 2023 +0200 +++ b/.github/workflows/make.yaml Fri May 12 08:03:14 2023 +0200 @@ -86,7 +86,7 @@ key: ${{ steps.ccache-prepare.outputs.key }} restore-keys: | ccache:${{ matrix.os }}:${{ matrix.compiler }}:${{ github.ref }} - ccache:${{ matrix.os }}:${{ matrix.compiler }}:refs/heads/stable + ccache:${{ matrix.os }}:${{ matrix.compiler }}:refs/heads/default - name: configure ccache env: @@ -252,7 +252,7 @@ key: ${{ steps.ccache-prepare.outputs.key }} restore-keys: | ccache:${{ matrix.os }}:${{ matrix.compiler }}:${{ github.ref }} - ccache:${{ matrix.os }}:${{ matrix.compiler }}:refs/heads/stable + ccache:${{ matrix.os }}:${{ matrix.compiler }}:refs/heads/default - name: configure ccache # The cache doesn't seem to compress well on macOS. Is it already compressed? @@ -358,6 +358,8 @@ mingw: runs-on: ${{ matrix.os }} + name: mingw-w64 ${{ matrix.msystem }} + defaults: run: # Use MSYS2 as default shell @@ -370,29 +372,37 @@ matrix: # For available GitHub-hosted runners, see: https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners os: [windows-latest] - msystem: [MINGW64, MINGW32] + msystem: [MINGW64, CLANG64] include: - msystem: MINGW64 mingw-prefix: mingw64 - target-triplet: x86_64-w64-mingw32 target-prefix: mingw-w64-x86_64 cc: gcc cxx: g++ f77: gfortran - - msystem: MINGW32 - mingw-prefix: mingw32 - target-triplet: i686-w64-mingw32 - target-prefix: mingw-w64-i686 - cc: gcc - cxx: g++ - f77: gfortran + extra-config-flags: "" + ccache-max: 0.9G + - msystem: CLANG64 + mingw-prefix: clang64 + target-prefix: mingw-w64-clang-x86_64 + cc: clang + # It looks like we and graphicsmagick++ aren't ready for C++17 yet. + cxx: "clang++ -std=gnu++14" + f77: flang + # Clang seems to require a different set of dllexport attributes than GCC. + # autoconf and libtool still need help to correctly invoke flang. + extra-config-flags: + --disable-lib-visibility-flags + --enable-fortran-calling-convention=gfortran + ac_cv_f77_compiler_gnu=yes + lt_cv_prog_gnu_ld=yes + ccache-max: 400M env: CHERE_INVOKING: 1 CC: ${{ matrix.cc }} CXX: ${{ matrix.cxx }} F77: ${{ matrix.f77 }} - TARGET_TRIPLET: ${{ matrix.target-triplet }} # perl uses cmd shell by default PERL5SHELL: bash -l -c @@ -423,9 +433,8 @@ base-devel ${{ matrix.target-prefix }}-autotools ${{ matrix.target-prefix }}-cc - ${{ matrix.target-prefix }}-gcc-fortran + ${{ matrix.target-prefix }}-fc ${{ matrix.target-prefix }}-gperf - ${{ matrix.target-prefix }}-lapack ${{ matrix.target-prefix }}-openblas ${{ matrix.target-prefix }}-pcre2 @@ -494,14 +503,14 @@ key: ${{ steps.ccache-prepare.outputs.key }} restore-keys: | ccache:${{ matrix.os }}:${{ matrix.msystem }}:${{ github.ref }} - ccache:${{ matrix.os }}:${{ matrix.msystem }}:refs/heads/stable + ccache:${{ matrix.os }}:${{ matrix.msystem }}:refs/heads/default - name: configure ccache # Limit the maximum size and switch on compression to avoid exceeding the total disk or cache quota. run: | which ccache test -d ${{ steps.ccache-prepare.outputs.ccachedir }} || mkdir -p ${{ steps.ccache-prepare.outputs.ccachedir }} - echo "max_size = 0.9G" > ${{ steps.ccache-prepare.outputs.ccachedir }}/ccache.conf + echo "max_size = ${{ matrix.ccache-max }}" > ${{ steps.ccache-prepare.outputs.ccachedir }}/ccache.conf echo "compression = true" >> ${{ steps.ccache-prepare.outputs.ccachedir }}/ccache.conf ccache -p ccache -s @@ -523,9 +532,9 @@ which $CC echo $CC --version $CC --version - which $CXX - echo $CXX --version - $CXX --version + which ${CXX% *} + echo ${CXX% *} --version + ${CXX% *} --version which $F77 echo $F77 --version $F77 --version @@ -533,6 +542,7 @@ cd .build && ../configure \ JAVA_HOME="" \ --disable-docs \ + ${{ matrix.extra-config-flags }} \ gl_cv_have_weak=no - name: build @@ -742,7 +752,7 @@ key: ${{ steps.ccache-prepare.outputs.key }} restore-keys: | ccache:${{ matrix.os }}:cygwin:${{ github.ref }} - ccache:${{ matrix.os }}:cygwin:refs/heads/stable + ccache:${{ matrix.os }}:cygwin:refs/heads/default - name: configure ccache run: | diff -r e2911d0176dc -r 212145b8e5f0 .hgignore --- a/.hgignore Fri May 12 08:00:41 2023 +0200 +++ b/.hgignore Fri May 12 08:03:14 2023 +0200 @@ -42,6 +42,8 @@ (^|/)build-aux/check-subst-vars\.sh$ ^build-aux/compile$ ^build-aux/depcomp$ +(^|/)build-aux/find-defun-files\.sh$ +(^|/)build-aux/find-files-with-tests\.sh$ ^build-aux/install-sh$ ^build-aux/ltmain\.sh$ ^build-aux/mdate-sh$ diff -r e2911d0176dc -r 212145b8e5f0 Makefile.am --- a/Makefile.am Fri May 12 08:00:41 2023 +0200 +++ b/Makefile.am Fri May 12 08:03:14 2023 +0200 @@ -302,12 +302,6 @@ run-octave \ $(DIRSTAMP_FILES) -if AMCOND_HAVE_BROKEN_STL_ALGO_H - BUILT_SOURCES += bits/stl_algo.h -else - BUILT_SOURCES += nonexistent-file -endif - noinst_SCRIPTS = run-octave CLEANFILES += \ @@ -359,10 +353,6 @@ $(AM_V_GEN)$(SHELL) $(srcdir)/build-aux/mk-octave-config-h.sh $< > $@-t && \ $(simple_move_if_change_rule) -bits/stl_algo.h: build-aux/stl_algo.h-fixed - $(AM_V_GEN)$(MKDIR_P) bits && \ - $(INSTALL_HEADER) $< $@ - config-vars: $(GEN_CONFIG_SHELL) $(AM_V_GEN)rm -f $@-t $@ && \ $(SED) -n 's/ *"$$/"/; s/^\([A-Za-z_][A-Za-z0-9_]*\)=" *\(.*\)" *$$/\1 \2/p' $^ | sort -u > $@-t && \ @@ -380,13 +370,6 @@ @$(SHELL) -f build-aux/check-subst-vars.sh make-vars config-vars .PHONY: check-subst-vars -## If we aren't trying to fix stl_algo.h, then try to ensure that -## there isn't a stray copy sitting in the build tree. - -nonexistent-file: - $(AM_V_at)rm -f bits/stl_algo.h -.PHONY: nonexistent-file - .gdbinit: etc/gdbinit $(AM_V_GEN)$(gdbinit-install-rule) diff -r e2911d0176dc -r 212145b8e5f0 bootstrap.conf --- a/bootstrap.conf Fri May 12 08:00:41 2023 +0200 +++ b/bootstrap.conf Fri May 12 08:03:14 2023 +0200 @@ -105,6 +105,8 @@ uname unicase/u8-tolower unicase/u8-toupper + uniconv/u16-conv-from-enc + uniconv/u16-conv-to-enc uniconv/u32-conv-to-enc uniconv/u8-conv-from-enc uniconv/u8-conv-to-enc diff -r e2911d0176dc -r 212145b8e5f0 build-aux/find-defun-files.in.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/build-aux/find-defun-files.in.sh Fri May 12 08:03:14 2023 +0200 @@ -0,0 +1,56 @@ +#! /bin/sh + +######################################################################## +## +## Copyright (C) 2009-2023 The Octave Project Developers +## +## See the file COPYRIGHT.md in the top-level directory of this +## distribution or . +## +## 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 +## . +## +######################################################################## + +set -e + +: ${SED=@SED@} +: ${EGREP=@EGREP@} + +# Some stupid egreps don't like empty elements in alternation patterns, +# so we have to repeat ourselves because some stupid egreps don't like +# empty elements in alternation patterns. + +DEFUN_PATTERN="^[ \t]*DEF(CONSTFUN|CONSTMETHOD|METHOD|METHOD(_|_STATIC_)DLD|METHODX|METHODX(_|_STATIC_)DLD|UN|UN(_|_STATIC_)DLD|UNX|UNX(_|_STATIC_)DLD)[ \t]*\\(" + +srcdir="$1" +if [ "$1" ]; then + shift +fi + +for arg +do + if [ -f "$arg" ]; then + file="$arg" + else + file="$srcdir/$arg" + fi + if [ -f "$file" ]; then + if [ "`$EGREP -l "$DEFUN_PATTERN" $file`" ]; then + echo "$file" | $SED "s,\\$srcdir/,," + fi + fi +done diff -r e2911d0176dc -r 212145b8e5f0 build-aux/find-defun-files.sh --- a/build-aux/find-defun-files.sh Fri May 12 08:00:41 2023 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -#! /bin/sh - -######################################################################## -## -## Copyright (C) 2009-2023 The Octave Project Developers -## -## See the file COPYRIGHT.md in the top-level directory of this -## distribution or . -## -## 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 -## . -## -######################################################################## - -set -e - -SED=${SED:-sed} -EGREP=${EGREP:-egrep} - -# Some stupid egreps don't like empty elements in alternation patterns, -# so we have to repeat ourselves because some stupid egreps don't like -# empty elements in alternation patterns. - -DEFUN_PATTERN="^[ \t]*DEF(CONSTFUN|CONSTMETHOD|METHOD|METHOD(_|_STATIC_)DLD|METHODX|METHODX(_|_STATIC_)DLD|UN|UN(_|_STATIC_)DLD|UNX|UNX(_|_STATIC_)DLD)[ \t]*\\(" - -srcdir="$1" -if [ "$1" ]; then - shift -fi - -for arg -do - if [ -f "$arg" ]; then - file="$arg" - else - file="$srcdir/$arg" - fi - if [ -f "$file" ]; then - if [ "`$EGREP -l "$DEFUN_PATTERN" $file`" ]; then - echo "$file" | $SED "s,\\$srcdir/,," - fi - fi -done diff -r e2911d0176dc -r 212145b8e5f0 build-aux/find-files-with-tests.in.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/build-aux/find-files-with-tests.in.sh Fri May 12 08:03:14 2023 +0200 @@ -0,0 +1,50 @@ +#! /bin/sh + +######################################################################## +## +## Copyright (C) 2013-2023 The Octave Project Developers +## +## See the file COPYRIGHT.md in the top-level directory of this +## distribution or . +## +## 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 +## . +## +######################################################################## + +set -e + +: ${GREP=@GREP@} +: ${SED=@SED@} + +srcdir="$1" +if [ "$1" ]; then + shift +fi + +for arg +do + if [ -f "$arg" ]; then + file="$arg" + else + file="$srcdir/$arg" + fi + if [ -f "$file" ]; then + if [ "`$GREP -l '^%!' $file`" ]; then + echo "$file" | $SED "s,\\$srcdir/,," + fi + fi +done diff -r e2911d0176dc -r 212145b8e5f0 build-aux/find-files-with-tests.sh --- a/build-aux/find-files-with-tests.sh Fri May 12 08:00:41 2023 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -#! /bin/sh - -######################################################################## -## -## Copyright (C) 2013-2023 The Octave Project Developers -## -## See the file COPYRIGHT.md in the top-level directory of this -## distribution or . -## -## 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 -## . -## -######################################################################## - -set -e - -GREP=${GREP:-grep} -SED=${SED:-sed} - -srcdir="$1" -if [ "$1" ]; then - shift -fi - -for arg -do - if [ -f "$arg" ]; then - file="$arg" - else - file="$srcdir/$arg" - fi - if [ -f "$file" ]; then - if [ "`$GREP -l '^%!' $file`" ]; then - echo "$file" | $SED "s,\\$srcdir/,," - fi - fi -done diff -r e2911d0176dc -r 212145b8e5f0 build-aux/mk-octave-config-h.sh --- a/build-aux/mk-octave-config-h.sh Fri May 12 08:00:41 2023 +0200 +++ b/build-aux/mk-octave-config-h.sh Fri May 12 08:03:14 2023 +0200 @@ -105,6 +105,7 @@ $SED -n 's/#\(\(undef\|define\) OCTAVE_ENABLE_64.*$\)/# \1/p' $config_h_file $SED -n 's/#\(\(undef\|define\) OCTAVE_ENABLE_BOUNDS_CHECK.*$\)/# \1/p' $config_h_file $SED -n 's/#\(\(undef\|define\) OCTAVE_ENABLE_FLOAT_TRUNCATE.*$\)/# \1/p' $config_h_file +$SED -n 's/#\(\(undef\|define\) OCTAVE_ENABLE_INTERNAL_CHECKS.*$\)/# \1/p' $config_h_file $SED -n 's/#\(\(undef\|define\) OCTAVE_ENABLE_LIB_VISIBILITY_FLAGS.*$\)/# \1/p' $config_h_file $SED -n 's/#\(\(undef\|define\) OCTAVE_ENABLE_OPENMP.*$\)/# \1/p' $config_h_file $SED -n 's/#\(\(undef\|define\) OCTAVE_F77_INT_TYPE.*$\)/# \1/p' $config_h_file diff -r e2911d0176dc -r 212145b8e5f0 build-aux/mk-opts.pl --- a/build-aux/mk-opts.pl Fri May 12 08:00:41 2023 +0200 +++ b/build-aux/mk-opts.pl Fri May 12 08:03:14 2023 +0200 @@ -392,7 +392,7 @@ { public: - $CLASS_NAME (void) + $CLASS_NAME () _END_EMIT_OPT_CLASS_HEADER_ print ' : '; @@ -421,9 +421,9 @@ return *this; } - ~$CLASS_NAME (void) { }\n"; + ~$CLASS_NAME () { }\n"; - print "\n void init (void)\n {\n"; + print "\n void init ()\n {\n"; for ($i = 0; $i < $OPT_NUM; $i++) { @@ -452,7 +452,7 @@ emit_copy_body (' ', 'opt'); - print " }\n\n void set_default_options (void) { init (); }\n"; + print " }\n\n void set_default_options () { init (); }\n"; for ($i = 0; $i < $OPT_NUM; $i++) { @@ -484,7 +484,7 @@ for ($i = 0; $i < $OPT_NUM; $i++) { - print " $TYPE[$i] $OPT[$i] (void) const\n { return $OPTVAR[$i]; }\n\n"; + print " $TYPE[$i] $OPT[$i] () const\n { return $OPTVAR[$i]; }\n\n"; } print "private:\n\n"; diff -r e2911d0176dc -r 212145b8e5f0 build-aux/module.mk --- a/build-aux/module.mk Fri May 12 08:00:41 2023 +0200 +++ b/build-aux/module.mk Fri May 12 08:03:14 2023 +0200 @@ -3,8 +3,8 @@ %reldir%/OctJavaQry.java \ %reldir%/changelog.tmpl \ %reldir%/check-subst-vars.in.sh \ - %reldir%/find-defun-files.sh \ - %reldir%/find-files-with-tests.sh \ + %reldir%/find-defun-files.in.sh \ + %reldir%/find-files-with-tests.in.sh \ %reldir%/get-source-mtime.sh \ %reldir%/inplace_edit.pl \ %reldir%/mk-hg-id.sh \ @@ -12,7 +12,6 @@ %reldir%/mk-opts.pl \ %reldir%/mk-pkg-add.sh \ %reldir%/move-if-change \ - %reldir%/stl_algo.h-fixed \ %reldir%/subst-config-vals.in.sh \ %reldir%/subst-cross-config-vals.in.sh \ %reldir%/subst-script-vals.in.sh \ diff -r e2911d0176dc -r 212145b8e5f0 build-aux/stl_algo.h-fixed --- a/build-aux/stl_algo.h-fixed Fri May 12 08:00:41 2023 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6322 +0,0 @@ -// Algorithm implementation -*- C++ -*- - -// Copyright (C) 2001-2013 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library 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, or (at your option) -// any later version. - -// This library 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. - -// Under Section 7 of GPL version 3, you are granted additional -// permissions described in the GCC Runtime Library Exception, version -// 3.1, as published by the Free Software Foundation. - -// You should have received a copy of the GNU General Public License and -// a copy of the GCC Runtime Library Exception along with this program; -// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -// . - -/* - * - * Copyright (c) 1994 - * Hewlett-Packard Company - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Hewlett-Packard Company makes no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - * - * - * Copyright (c) 1996 - * Silicon Graphics Computer Systems, Inc. - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Silicon Graphics makes no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - */ - -/** @file bits/stl_algo.h - * This is an internal header file, included by other library headers. - * Do not attempt to use it directly. @headername{algorithm} - */ - -#ifndef _STL_ALGO_H -#define _STL_ALGO_H 1 - -#include // for rand -#include -#include -#include // for _Temporary_buffer - -#if __cplusplus >= 201103L -#include // for std::uniform_int_distribution -#include // for std::bind -#endif - -// See concept_check.h for the __glibcxx_*_requires macros. - -namespace std _GLIBCXX_VISIBILITY(default) -{ -_GLIBCXX_BEGIN_NAMESPACE_VERSION - - /// Swaps the median value of *__a, *__b and *__c to *__result - template - void - __move_median_to_first(_Iterator __result, _Iterator __a, - _Iterator __b, _Iterator __c) - { - // concept requirements - __glibcxx_function_requires(_LessThanComparableConcept< - typename iterator_traits<_Iterator>::value_type>) - - if (*__a < *__b) - { - if (*__b < *__c) - std::iter_swap(__result, __b); - else if (*__a < *__c) - std::iter_swap(__result, __c); - else - std::iter_swap(__result, __a); - } - else if (*__a < *__c) - std::iter_swap(__result, __a); - else if (*__b < *__c) - std::iter_swap(__result, __c); - else - std::iter_swap(__result, __b); - } - - /// Swaps the median value of *__a, *__b and *__c under __comp to *__result - template - void - __move_median_to_first(_Iterator __result, _Iterator __a, - _Iterator __b, _Iterator __c, - _Compare __comp) - { - // concept requirements - __glibcxx_function_requires(_BinaryFunctionConcept<_Compare, bool, - typename iterator_traits<_Iterator>::value_type, - typename iterator_traits<_Iterator>::value_type>) - - if (__comp(*__a, *__b)) - { - if (__comp(*__b, *__c)) - std::iter_swap(__result, __b); - else if (__comp(*__a, *__c)) - std::iter_swap(__result, __c); - else - std::iter_swap(__result, __a); - } - else if (__comp(*__a, *__c)) - std::iter_swap(__result, __a); - else if (__comp(*__b, *__c)) - std::iter_swap(__result, __c); - else - std::iter_swap(__result, __b); - } - - // for_each - - /// This is an overload used by find() for the Input Iterator case. - template - inline _InputIterator - __find(_InputIterator __first, _InputIterator __last, - const _Tp& __val, input_iterator_tag) - { - while (__first != __last && !(*__first == __val)) - ++__first; - return __first; - } - - /// This is an overload used by find_if() for the Input Iterator case. - template - inline _InputIterator - __find_if(_InputIterator __first, _InputIterator __last, - _Predicate __pred, input_iterator_tag) - { - while (__first != __last && !bool(__pred(*__first))) - ++__first; - return __first; - } - - /// This is an overload used by find() for the RAI case. - template - _RandomAccessIterator - __find(_RandomAccessIterator __first, _RandomAccessIterator __last, - const _Tp& __val, random_access_iterator_tag) - { - typename iterator_traits<_RandomAccessIterator>::difference_type - __trip_count = (__last - __first) >> 2; - - for (; __trip_count > 0; --__trip_count) - { - if (*__first == __val) - return __first; - ++__first; - - if (*__first == __val) - return __first; - ++__first; - - if (*__first == __val) - return __first; - ++__first; - - if (*__first == __val) - return __first; - ++__first; - } - - switch (__last - __first) - { - case 3: - if (*__first == __val) - return __first; - ++__first; - case 2: - if (*__first == __val) - return __first; - ++__first; - case 1: - if (*__first == __val) - return __first; - ++__first; - case 0: - default: - return __last; - } - } - - /// This is an overload used by find_if() for the RAI case. - template - _RandomAccessIterator - __find_if(_RandomAccessIterator __first, _RandomAccessIterator __last, - _Predicate __pred, random_access_iterator_tag) - { - typename iterator_traits<_RandomAccessIterator>::difference_type - __trip_count = (__last - __first) >> 2; - - for (; __trip_count > 0; --__trip_count) - { - if (__pred(*__first)) - return __first; - ++__first; - - if (__pred(*__first)) - return __first; - ++__first; - - if (__pred(*__first)) - return __first; - ++__first; - - if (__pred(*__first)) - return __first; - ++__first; - } - - switch (__last - __first) - { - case 3: - if (__pred(*__first)) - return __first; - ++__first; - case 2: - if (__pred(*__first)) - return __first; - ++__first; - case 1: - if (__pred(*__first)) - return __first; - ++__first; - case 0: - default: - return __last; - } - } - - /// This is an overload used by find_if_not() for the Input Iterator case. - template - inline _InputIterator - __find_if_not(_InputIterator __first, _InputIterator __last, - _Predicate __pred, input_iterator_tag) - { - while (__first != __last && bool(__pred(*__first))) - ++__first; - return __first; - } - - /// This is an overload used by find_if_not() for the RAI case. - template - _RandomAccessIterator - __find_if_not(_RandomAccessIterator __first, _RandomAccessIterator __last, - _Predicate __pred, random_access_iterator_tag) - { - typename iterator_traits<_RandomAccessIterator>::difference_type - __trip_count = (__last - __first) >> 2; - - for (; __trip_count > 0; --__trip_count) - { - if (!bool(__pred(*__first))) - return __first; - ++__first; - - if (!bool(__pred(*__first))) - return __first; - ++__first; - - if (!bool(__pred(*__first))) - return __first; - ++__first; - - if (!bool(__pred(*__first))) - return __first; - ++__first; - } - - switch (__last - __first) - { - case 3: - if (!bool(__pred(*__first))) - return __first; - ++__first; - case 2: - if (!bool(__pred(*__first))) - return __first; - ++__first; - case 1: - if (!bool(__pred(*__first))) - return __first; - ++__first; - case 0: - default: - return __last; - } - } - - /// Provided for stable_partition to use. - template - inline _InputIterator - __find_if_not(_InputIterator __first, _InputIterator __last, - _Predicate __pred) - { - return std::__find_if_not(__first, __last, __pred, - std::__iterator_category(__first)); - } - - /// Like find_if_not(), but uses and updates a count of the - /// remaining range length instead of comparing against an end - /// iterator. - template - _InputIterator - __find_if_not_n(_InputIterator __first, _Distance& __len, _Predicate __pred) - { - for (; __len; --__len, ++__first) - if (!bool(__pred(*__first))) - break; - return __first; - } - - // set_difference - // set_intersection - // set_symmetric_difference - // set_union - // for_each - // find - // find_if - // find_first_of - // adjacent_find - // count - // count_if - // search - - /** - * This is an uglified - * search_n(_ForwardIterator, _ForwardIterator, _Integer, const _Tp&) - * overloaded for forward iterators. - */ - template - _ForwardIterator - __search_n(_ForwardIterator __first, _ForwardIterator __last, - _Integer __count, const _Tp& __val, - std::forward_iterator_tag) - { - __first = _GLIBCXX_STD_A::find(__first, __last, __val); - while (__first != __last) - { - typename iterator_traits<_ForwardIterator>::difference_type - __n = __count; - _ForwardIterator __i = __first; - ++__i; - while (__i != __last && __n != 1 && *__i == __val) - { - ++__i; - --__n; - } - if (__n == 1) - return __first; - if (__i == __last) - return __last; - __first = _GLIBCXX_STD_A::find(++__i, __last, __val); - } - return __last; - } - - /** - * This is an uglified - * search_n(_ForwardIterator, _ForwardIterator, _Integer, const _Tp&) - * overloaded for random access iterators. - */ - template - _RandomAccessIter - __search_n(_RandomAccessIter __first, _RandomAccessIter __last, - _Integer __count, const _Tp& __val, - std::random_access_iterator_tag) - { - - typedef typename std::iterator_traits<_RandomAccessIter>::difference_type - _DistanceType; - - _DistanceType __tailSize = __last - __first; - _DistanceType __remainder = __count; - - while (__remainder <= __tailSize) // the main loop... - { - __first += __remainder; - __tailSize -= __remainder; - // __first here is always pointing to one past the last element of - // next possible match. - _RandomAccessIter __backTrack = __first; - while (*--__backTrack == __val) - { - if (--__remainder == 0) - return (__first - __count); // Success - } - __remainder = __count + 1 - (__first - __backTrack); - } - return __last; // Failure - } - - // search_n - - /** - * This is an uglified - * search_n(_ForwardIterator, _ForwardIterator, _Integer, const _Tp&, - * _BinaryPredicate) - * overloaded for forward iterators. - */ - template - _ForwardIterator - __search_n(_ForwardIterator __first, _ForwardIterator __last, - _Integer __count, const _Tp& __val, - _BinaryPredicate __binary_pred, std::forward_iterator_tag) - { - while (__first != __last && !bool(__binary_pred(*__first, __val))) - ++__first; - - while (__first != __last) - { - typename iterator_traits<_ForwardIterator>::difference_type - __n = __count; - _ForwardIterator __i = __first; - ++__i; - while (__i != __last && __n != 1 && bool(__binary_pred(*__i, __val))) - { - ++__i; - --__n; - } - if (__n == 1) - return __first; - if (__i == __last) - return __last; - __first = ++__i; - while (__first != __last - && !bool(__binary_pred(*__first, __val))) - ++__first; - } - return __last; - } - - /** - * This is an uglified - * search_n(_ForwardIterator, _ForwardIterator, _Integer, const _Tp&, - * _BinaryPredicate) - * overloaded for random access iterators. - */ - template - _RandomAccessIter - __search_n(_RandomAccessIter __first, _RandomAccessIter __last, - _Integer __count, const _Tp& __val, - _BinaryPredicate __binary_pred, std::random_access_iterator_tag) - { - - typedef typename std::iterator_traits<_RandomAccessIter>::difference_type - _DistanceType; - - _DistanceType __tailSize = __last - __first; - _DistanceType __remainder = __count; - - while (__remainder <= __tailSize) // the main loop... - { - __first += __remainder; - __tailSize -= __remainder; - // __first here is always pointing to one past the last element of - // next possible match. - _RandomAccessIter __backTrack = __first; - while (__binary_pred(*--__backTrack, __val)) - { - if (--__remainder == 0) - return (__first - __count); // Success - } - __remainder = __count + 1 - (__first - __backTrack); - } - return __last; // Failure - } - - // find_end for forward iterators. - template - _ForwardIterator1 - __find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1, - _ForwardIterator2 __first2, _ForwardIterator2 __last2, - forward_iterator_tag, forward_iterator_tag) - { - if (__first2 == __last2) - return __last1; - else - { - _ForwardIterator1 __result = __last1; - while (1) - { - _ForwardIterator1 __new_result - = _GLIBCXX_STD_A::search(__first1, __last1, __first2, __last2); - if (__new_result == __last1) - return __result; - else - { - __result = __new_result; - __first1 = __new_result; - ++__first1; - } - } - } - } - - template - _ForwardIterator1 - __find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1, - _ForwardIterator2 __first2, _ForwardIterator2 __last2, - forward_iterator_tag, forward_iterator_tag, - _BinaryPredicate __comp) - { - if (__first2 == __last2) - return __last1; - else - { - _ForwardIterator1 __result = __last1; - while (1) - { - _ForwardIterator1 __new_result - = _GLIBCXX_STD_A::search(__first1, __last1, __first2, - __last2, __comp); - if (__new_result == __last1) - return __result; - else - { - __result = __new_result; - __first1 = __new_result; - ++__first1; - } - } - } - } - - // find_end for bidirectional iterators (much faster). - template - _BidirectionalIterator1 - __find_end(_BidirectionalIterator1 __first1, - _BidirectionalIterator1 __last1, - _BidirectionalIterator2 __first2, - _BidirectionalIterator2 __last2, - bidirectional_iterator_tag, bidirectional_iterator_tag) - { - // concept requirements - __glibcxx_function_requires(_BidirectionalIteratorConcept< - _BidirectionalIterator1>) - __glibcxx_function_requires(_BidirectionalIteratorConcept< - _BidirectionalIterator2>) - - typedef reverse_iterator<_BidirectionalIterator1> _RevIterator1; - typedef reverse_iterator<_BidirectionalIterator2> _RevIterator2; - - _RevIterator1 __rlast1(__first1); - _RevIterator2 __rlast2(__first2); - _RevIterator1 __rresult = _GLIBCXX_STD_A::search(_RevIterator1(__last1), - __rlast1, - _RevIterator2(__last2), - __rlast2); - - if (__rresult == __rlast1) - return __last1; - else - { - _BidirectionalIterator1 __result = __rresult.base(); - std::advance(__result, -std::distance(__first2, __last2)); - return __result; - } - } - - template - _BidirectionalIterator1 - __find_end(_BidirectionalIterator1 __first1, - _BidirectionalIterator1 __last1, - _BidirectionalIterator2 __first2, - _BidirectionalIterator2 __last2, - bidirectional_iterator_tag, bidirectional_iterator_tag, - _BinaryPredicate __comp) - { - // concept requirements - __glibcxx_function_requires(_BidirectionalIteratorConcept< - _BidirectionalIterator1>) - __glibcxx_function_requires(_BidirectionalIteratorConcept< - _BidirectionalIterator2>) - - typedef reverse_iterator<_BidirectionalIterator1> _RevIterator1; - typedef reverse_iterator<_BidirectionalIterator2> _RevIterator2; - - _RevIterator1 __rlast1(__first1); - _RevIterator2 __rlast2(__first2); - _RevIterator1 __rresult = std::search(_RevIterator1(__last1), __rlast1, - _RevIterator2(__last2), __rlast2, - __comp); - - if (__rresult == __rlast1) - return __last1; - else - { - _BidirectionalIterator1 __result = __rresult.base(); - std::advance(__result, -std::distance(__first2, __last2)); - return __result; - } - } - - /** - * @brief Find last matching subsequence in a sequence. - * @ingroup non_mutating_algorithms - * @param __first1 Start of range to search. - * @param __last1 End of range to search. - * @param __first2 Start of sequence to match. - * @param __last2 End of sequence to match. - * @return The last iterator @c i in the range - * @p [__first1,__last1-(__last2-__first2)) such that @c *(i+N) == - * @p *(__first2+N) for each @c N in the range @p - * [0,__last2-__first2), or @p __last1 if no such iterator exists. - * - * Searches the range @p [__first1,__last1) for a sub-sequence that - * compares equal value-by-value with the sequence given by @p - * [__first2,__last2) and returns an iterator to the __first - * element of the sub-sequence, or @p __last1 if the sub-sequence - * is not found. The sub-sequence will be the last such - * subsequence contained in [__first,__last1). - * - * Because the sub-sequence must lie completely within the range @p - * [__first1,__last1) it must start at a position less than @p - * __last1-(__last2-__first2) where @p __last2-__first2 is the - * length of the sub-sequence. This means that the returned - * iterator @c i will be in the range @p - * [__first1,__last1-(__last2-__first2)) - */ - template - inline _ForwardIterator1 - find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1, - _ForwardIterator2 __first2, _ForwardIterator2 __last2) - { - // concept requirements - __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>) - __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>) - __glibcxx_function_requires(_EqualOpConcept< - typename iterator_traits<_ForwardIterator1>::value_type, - typename iterator_traits<_ForwardIterator2>::value_type>) - __glibcxx_requires_valid_range(__first1, __last1); - __glibcxx_requires_valid_range(__first2, __last2); - - return std::__find_end(__first1, __last1, __first2, __last2, - std::__iterator_category(__first1), - std::__iterator_category(__first2)); - } - - /** - * @brief Find last matching subsequence in a sequence using a predicate. - * @ingroup non_mutating_algorithms - * @param __first1 Start of range to search. - * @param __last1 End of range to search. - * @param __first2 Start of sequence to match. - * @param __last2 End of sequence to match. - * @param __comp The predicate to use. - * @return The last iterator @c i in the range @p - * [__first1,__last1-(__last2-__first2)) such that @c - * predicate(*(i+N), @p (__first2+N)) is true for each @c N in the - * range @p [0,__last2-__first2), or @p __last1 if no such iterator - * exists. - * - * Searches the range @p [__first1,__last1) for a sub-sequence that - * compares equal value-by-value with the sequence given by @p - * [__first2,__last2) using comp as a predicate and returns an - * iterator to the first element of the sub-sequence, or @p __last1 - * if the sub-sequence is not found. The sub-sequence will be the - * last such subsequence contained in [__first,__last1). - * - * Because the sub-sequence must lie completely within the range @p - * [__first1,__last1) it must start at a position less than @p - * __last1-(__last2-__first2) where @p __last2-__first2 is the - * length of the sub-sequence. This means that the returned - * iterator @c i will be in the range @p - * [__first1,__last1-(__last2-__first2)) - */ - template - inline _ForwardIterator1 - find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1, - _ForwardIterator2 __first2, _ForwardIterator2 __last2, - _BinaryPredicate __comp) - { - // concept requirements - __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>) - __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>) - __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate, - typename iterator_traits<_ForwardIterator1>::value_type, - typename iterator_traits<_ForwardIterator2>::value_type>) - __glibcxx_requires_valid_range(__first1, __last1); - __glibcxx_requires_valid_range(__first2, __last2); - - return std::__find_end(__first1, __last1, __first2, __last2, - std::__iterator_category(__first1), - std::__iterator_category(__first2), - __comp); - } - -#if __cplusplus >= 201103L - /** - * @brief Checks that a predicate is true for all the elements - * of a sequence. - * @ingroup non_mutating_algorithms - * @param __first An input iterator. - * @param __last An input iterator. - * @param __pred A predicate. - * @return True if the check is true, false otherwise. - * - * Returns true if @p __pred is true for each element in the range - * @p [__first,__last), and false otherwise. - */ - template - inline bool - all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) - { return __last == std::find_if_not(__first, __last, __pred); } - - /** - * @brief Checks that a predicate is false for all the elements - * of a sequence. - * @ingroup non_mutating_algorithms - * @param __first An input iterator. - * @param __last An input iterator. - * @param __pred A predicate. - * @return True if the check is true, false otherwise. - * - * Returns true if @p __pred is false for each element in the range - * @p [__first,__last), and false otherwise. - */ - template - inline bool - none_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) - { return __last == _GLIBCXX_STD_A::find_if(__first, __last, __pred); } - - /** - * @brief Checks that a predicate is false for at least an element - * of a sequence. - * @ingroup non_mutating_algorithms - * @param __first An input iterator. - * @param __last An input iterator. - * @param __pred A predicate. - * @return True if the check is true, false otherwise. - * - * Returns true if an element exists in the range @p - * [__first,__last) such that @p __pred is true, and false - * otherwise. - */ - template - inline bool - any_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) - { return !std::none_of(__first, __last, __pred); } - - /** - * @brief Find the first element in a sequence for which a - * predicate is false. - * @ingroup non_mutating_algorithms - * @param __first An input iterator. - * @param __last An input iterator. - * @param __pred A predicate. - * @return The first iterator @c i in the range @p [__first,__last) - * such that @p __pred(*i) is false, or @p __last if no such iterator exists. - */ - template - inline _InputIterator - find_if_not(_InputIterator __first, _InputIterator __last, - _Predicate __pred) - { - // concept requirements - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>) - __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate, - typename iterator_traits<_InputIterator>::value_type>) - __glibcxx_requires_valid_range(__first, __last); - return std::__find_if_not(__first, __last, __pred); - } - - /** - * @brief Checks whether the sequence is partitioned. - * @ingroup mutating_algorithms - * @param __first An input iterator. - * @param __last An input iterator. - * @param __pred A predicate. - * @return True if the range @p [__first,__last) is partitioned by @p __pred, - * i.e. if all elements that satisfy @p __pred appear before those that - * do not. - */ - template - inline bool - is_partitioned(_InputIterator __first, _InputIterator __last, - _Predicate __pred) - { - __first = std::find_if_not(__first, __last, __pred); - return std::none_of(__first, __last, __pred); - } - - /** - * @brief Find the partition point of a partitioned range. - * @ingroup mutating_algorithms - * @param __first An iterator. - * @param __last Another iterator. - * @param __pred A predicate. - * @return An iterator @p mid such that @p all_of(__first, mid, __pred) - * and @p none_of(mid, __last, __pred) are both true. - */ - template - _ForwardIterator - partition_point(_ForwardIterator __first, _ForwardIterator __last, - _Predicate __pred) - { - // concept requirements - __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>) - __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate, - typename iterator_traits<_ForwardIterator>::value_type>) - - // A specific debug-mode test will be necessary... - __glibcxx_requires_valid_range(__first, __last); - - typedef typename iterator_traits<_ForwardIterator>::difference_type - _DistanceType; - - _DistanceType __len = std::distance(__first, __last); - _DistanceType __half; - _ForwardIterator __middle; - - while (__len > 0) - { - __half = __len >> 1; - __middle = __first; - std::advance(__middle, __half); - if (__pred(*__middle)) - { - __first = __middle; - ++__first; - __len = __len - __half - 1; - } - else - __len = __half; - } - return __first; - } -#endif - - - /** - * @brief Copy a sequence, removing elements of a given value. - * @ingroup mutating_algorithms - * @param __first An input iterator. - * @param __last An input iterator. - * @param __result An output iterator. - * @param __value The value to be removed. - * @return An iterator designating the end of the resulting sequence. - * - * Copies each element in the range @p [__first,__last) not equal - * to @p __value to the range beginning at @p __result. - * remove_copy() is stable, so the relative order of elements that - * are copied is unchanged. - */ - template - _OutputIterator - remove_copy(_InputIterator __first, _InputIterator __last, - _OutputIterator __result, const _Tp& __value) - { - // concept requirements - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>) - __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, - typename iterator_traits<_InputIterator>::value_type>) - __glibcxx_function_requires(_EqualOpConcept< - typename iterator_traits<_InputIterator>::value_type, _Tp>) - __glibcxx_requires_valid_range(__first, __last); - - for (; __first != __last; ++__first) - if (!(*__first == __value)) - { - *__result = *__first; - ++__result; - } - return __result; - } - - /** - * @brief Copy a sequence, removing elements for which a predicate is true. - * @ingroup mutating_algorithms - * @param __first An input iterator. - * @param __last An input iterator. - * @param __result An output iterator. - * @param __pred A predicate. - * @return An iterator designating the end of the resulting sequence. - * - * Copies each element in the range @p [__first,__last) for which - * @p __pred returns false to the range beginning at @p __result. - * - * remove_copy_if() is stable, so the relative order of elements that are - * copied is unchanged. - */ - template - _OutputIterator - remove_copy_if(_InputIterator __first, _InputIterator __last, - _OutputIterator __result, _Predicate __pred) - { - // concept requirements - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>) - __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, - typename iterator_traits<_InputIterator>::value_type>) - __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate, - typename iterator_traits<_InputIterator>::value_type>) - __glibcxx_requires_valid_range(__first, __last); - - for (; __first != __last; ++__first) - if (!bool(__pred(*__first))) - { - *__result = *__first; - ++__result; - } - return __result; - } - -#if __cplusplus >= 201103L - /** - * @brief Copy the elements of a sequence for which a predicate is true. - * @ingroup mutating_algorithms - * @param __first An input iterator. - * @param __last An input iterator. - * @param __result An output iterator. - * @param __pred A predicate. - * @return An iterator designating the end of the resulting sequence. - * - * Copies each element in the range @p [__first,__last) for which - * @p __pred returns true to the range beginning at @p __result. - * - * copy_if() is stable, so the relative order of elements that are - * copied is unchanged. - */ - template - _OutputIterator - copy_if(_InputIterator __first, _InputIterator __last, - _OutputIterator __result, _Predicate __pred) - { - // concept requirements - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>) - __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, - typename iterator_traits<_InputIterator>::value_type>) - __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate, - typename iterator_traits<_InputIterator>::value_type>) - __glibcxx_requires_valid_range(__first, __last); - - for (; __first != __last; ++__first) - if (__pred(*__first)) - { - *__result = *__first; - ++__result; - } - return __result; - } - - - template - _OutputIterator - __copy_n(_InputIterator __first, _Size __n, - _OutputIterator __result, input_iterator_tag) - { - if (__n > 0) - { - while (true) - { - *__result = *__first; - ++__result; - if (--__n > 0) - ++__first; - else - break; - } - } - return __result; - } - - template - inline _OutputIterator - __copy_n(_RandomAccessIterator __first, _Size __n, - _OutputIterator __result, random_access_iterator_tag) - { return std::copy(__first, __first + __n, __result); } - - /** - * @brief Copies the range [first,first+n) into [result,result+n). - * @ingroup mutating_algorithms - * @param __first An input iterator. - * @param __n The number of elements to copy. - * @param __result An output iterator. - * @return result+n. - * - * This inline function will boil down to a call to @c memmove whenever - * possible. Failing that, if random access iterators are passed, then the - * loop count will be known (and therefore a candidate for compiler - * optimizations such as unrolling). - */ - template - inline _OutputIterator - copy_n(_InputIterator __first, _Size __n, _OutputIterator __result) - { - // concept requirements - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>) - __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, - typename iterator_traits<_InputIterator>::value_type>) - - return std::__copy_n(__first, __n, __result, - std::__iterator_category(__first)); - } - - /** - * @brief Copy the elements of a sequence to separate output sequences - * depending on the truth value of a predicate. - * @ingroup mutating_algorithms - * @param __first An input iterator. - * @param __last An input iterator. - * @param __out_true An output iterator. - * @param __out_false An output iterator. - * @param __pred A predicate. - * @return A pair designating the ends of the resulting sequences. - * - * Copies each element in the range @p [__first,__last) for which - * @p __pred returns true to the range beginning at @p out_true - * and each element for which @p __pred returns false to @p __out_false. - */ - template - pair<_OutputIterator1, _OutputIterator2> - partition_copy(_InputIterator __first, _InputIterator __last, - _OutputIterator1 __out_true, _OutputIterator2 __out_false, - _Predicate __pred) - { - // concept requirements - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>) - __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator1, - typename iterator_traits<_InputIterator>::value_type>) - __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator2, - typename iterator_traits<_InputIterator>::value_type>) - __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate, - typename iterator_traits<_InputIterator>::value_type>) - __glibcxx_requires_valid_range(__first, __last); - - for (; __first != __last; ++__first) - if (__pred(*__first)) - { - *__out_true = *__first; - ++__out_true; - } - else - { - *__out_false = *__first; - ++__out_false; - } - - return pair<_OutputIterator1, _OutputIterator2>(__out_true, __out_false); - } -#endif - - /** - * @brief Remove elements from a sequence. - * @ingroup mutating_algorithms - * @param __first An input iterator. - * @param __last An input iterator. - * @param __value The value to be removed. - * @return An iterator designating the end of the resulting sequence. - * - * All elements equal to @p __value are removed from the range - * @p [__first,__last). - * - * remove() is stable, so the relative order of elements that are - * not removed is unchanged. - * - * Elements between the end of the resulting sequence and @p __last - * are still present, but their value is unspecified. - */ - template - _ForwardIterator - remove(_ForwardIterator __first, _ForwardIterator __last, - const _Tp& __value) - { - // concept requirements - __glibcxx_function_requires(_Mutable_ForwardIteratorConcept< - _ForwardIterator>) - __glibcxx_function_requires(_EqualOpConcept< - typename iterator_traits<_ForwardIterator>::value_type, _Tp>) - __glibcxx_requires_valid_range(__first, __last); - - __first = _GLIBCXX_STD_A::find(__first, __last, __value); - if(__first == __last) - return __first; - _ForwardIterator __result = __first; - ++__first; - for(; __first != __last; ++__first) - if(!(*__first == __value)) - { - *__result = _GLIBCXX_MOVE(*__first); - ++__result; - } - return __result; - } - - /** - * @brief Remove elements from a sequence using a predicate. - * @ingroup mutating_algorithms - * @param __first A forward iterator. - * @param __last A forward iterator. - * @param __pred A predicate. - * @return An iterator designating the end of the resulting sequence. - * - * All elements for which @p __pred returns true are removed from the range - * @p [__first,__last). - * - * remove_if() is stable, so the relative order of elements that are - * not removed is unchanged. - * - * Elements between the end of the resulting sequence and @p __last - * are still present, but their value is unspecified. - */ - template - _ForwardIterator - remove_if(_ForwardIterator __first, _ForwardIterator __last, - _Predicate __pred) - { - // concept requirements - __glibcxx_function_requires(_Mutable_ForwardIteratorConcept< - _ForwardIterator>) - __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate, - typename iterator_traits<_ForwardIterator>::value_type>) - __glibcxx_requires_valid_range(__first, __last); - - __first = _GLIBCXX_STD_A::find_if(__first, __last, __pred); - if(__first == __last) - return __first; - _ForwardIterator __result = __first; - ++__first; - for(; __first != __last; ++__first) - if(!bool(__pred(*__first))) - { - *__result = _GLIBCXX_MOVE(*__first); - ++__result; - } - return __result; - } - - /** - * @brief Remove consecutive duplicate values from a sequence. - * @ingroup mutating_algorithms - * @param __first A forward iterator. - * @param __last A forward iterator. - * @return An iterator designating the end of the resulting sequence. - * - * Removes all but the first element from each group of consecutive - * values that compare equal. - * unique() is stable, so the relative order of elements that are - * not removed is unchanged. - * Elements between the end of the resulting sequence and @p __last - * are still present, but their value is unspecified. - */ - template - _ForwardIterator - unique(_ForwardIterator __first, _ForwardIterator __last) - { - // concept requirements - __glibcxx_function_requires(_Mutable_ForwardIteratorConcept< - _ForwardIterator>) - __glibcxx_function_requires(_EqualityComparableConcept< - typename iterator_traits<_ForwardIterator>::value_type>) - __glibcxx_requires_valid_range(__first, __last); - - // Skip the beginning, if already unique. - __first = _GLIBCXX_STD_A::adjacent_find(__first, __last); - if (__first == __last) - return __last; - - // Do the real copy work. - _ForwardIterator __dest = __first; - ++__first; - while (++__first != __last) - if (!(*__dest == *__first)) - *++__dest = _GLIBCXX_MOVE(*__first); - return ++__dest; - } - - /** - * @brief Remove consecutive values from a sequence using a predicate. - * @ingroup mutating_algorithms - * @param __first A forward iterator. - * @param __last A forward iterator. - * @param __binary_pred A binary predicate. - * @return An iterator designating the end of the resulting sequence. - * - * Removes all but the first element from each group of consecutive - * values for which @p __binary_pred returns true. - * unique() is stable, so the relative order of elements that are - * not removed is unchanged. - * Elements between the end of the resulting sequence and @p __last - * are still present, but their value is unspecified. - */ - template - _ForwardIterator - unique(_ForwardIterator __first, _ForwardIterator __last, - _BinaryPredicate __binary_pred) - { - // concept requirements - __glibcxx_function_requires(_Mutable_ForwardIteratorConcept< - _ForwardIterator>) - __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate, - typename iterator_traits<_ForwardIterator>::value_type, - typename iterator_traits<_ForwardIterator>::value_type>) - __glibcxx_requires_valid_range(__first, __last); - - // Skip the beginning, if already unique. - __first = _GLIBCXX_STD_A::adjacent_find(__first, __last, __binary_pred); - if (__first == __last) - return __last; - - // Do the real copy work. - _ForwardIterator __dest = __first; - ++__first; - while (++__first != __last) - if (!bool(__binary_pred(*__dest, *__first))) - *++__dest = _GLIBCXX_MOVE(*__first); - return ++__dest; - } - - /** - * This is an uglified unique_copy(_InputIterator, _InputIterator, - * _OutputIterator) - * overloaded for forward iterators and output iterator as result. - */ - template - _OutputIterator - __unique_copy(_ForwardIterator __first, _ForwardIterator __last, - _OutputIterator __result, - forward_iterator_tag, output_iterator_tag) - { - // concept requirements -- taken care of in dispatching function - _ForwardIterator __next = __first; - *__result = *__first; - while (++__next != __last) - if (!(*__first == *__next)) - { - __first = __next; - *++__result = *__first; - } - return ++__result; - } - - /** - * This is an uglified unique_copy(_InputIterator, _InputIterator, - * _OutputIterator) - * overloaded for input iterators and output iterator as result. - */ - template - _OutputIterator - __unique_copy(_InputIterator __first, _InputIterator __last, - _OutputIterator __result, - input_iterator_tag, output_iterator_tag) - { - // concept requirements -- taken care of in dispatching function - typename iterator_traits<_InputIterator>::value_type __value = *__first; - *__result = __value; - while (++__first != __last) - if (!(__value == *__first)) - { - __value = *__first; - *++__result = __value; - } - return ++__result; - } - - /** - * This is an uglified unique_copy(_InputIterator, _InputIterator, - * _OutputIterator) - * overloaded for input iterators and forward iterator as result. - */ - template - _ForwardIterator - __unique_copy(_InputIterator __first, _InputIterator __last, - _ForwardIterator __result, - input_iterator_tag, forward_iterator_tag) - { - // concept requirements -- taken care of in dispatching function - *__result = *__first; - while (++__first != __last) - if (!(*__result == *__first)) - *++__result = *__first; - return ++__result; - } - - /** - * This is an uglified - * unique_copy(_InputIterator, _InputIterator, _OutputIterator, - * _BinaryPredicate) - * overloaded for forward iterators and output iterator as result. - */ - template - _OutputIterator - __unique_copy(_ForwardIterator __first, _ForwardIterator __last, - _OutputIterator __result, _BinaryPredicate __binary_pred, - forward_iterator_tag, output_iterator_tag) - { - // concept requirements -- iterators already checked - __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate, - typename iterator_traits<_ForwardIterator>::value_type, - typename iterator_traits<_ForwardIterator>::value_type>) - - _ForwardIterator __next = __first; - *__result = *__first; - while (++__next != __last) - if (!bool(__binary_pred(*__first, *__next))) - { - __first = __next; - *++__result = *__first; - } - return ++__result; - } - - /** - * This is an uglified - * unique_copy(_InputIterator, _InputIterator, _OutputIterator, - * _BinaryPredicate) - * overloaded for input iterators and output iterator as result. - */ - template - _OutputIterator - __unique_copy(_InputIterator __first, _InputIterator __last, - _OutputIterator __result, _BinaryPredicate __binary_pred, - input_iterator_tag, output_iterator_tag) - { - // concept requirements -- iterators already checked - __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate, - typename iterator_traits<_InputIterator>::value_type, - typename iterator_traits<_InputIterator>::value_type>) - - typename iterator_traits<_InputIterator>::value_type __value = *__first; - *__result = __value; - while (++__first != __last) - if (!bool(__binary_pred(__value, *__first))) - { - __value = *__first; - *++__result = __value; - } - return ++__result; - } - - /** - * This is an uglified - * unique_copy(_InputIterator, _InputIterator, _OutputIterator, - * _BinaryPredicate) - * overloaded for input iterators and forward iterator as result. - */ - template - _ForwardIterator - __unique_copy(_InputIterator __first, _InputIterator __last, - _ForwardIterator __result, _BinaryPredicate __binary_pred, - input_iterator_tag, forward_iterator_tag) - { - // concept requirements -- iterators already checked - __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate, - typename iterator_traits<_ForwardIterator>::value_type, - typename iterator_traits<_InputIterator>::value_type>) - - *__result = *__first; - while (++__first != __last) - if (!bool(__binary_pred(*__result, *__first))) - *++__result = *__first; - return ++__result; - } - - /** - * This is an uglified reverse(_BidirectionalIterator, - * _BidirectionalIterator) - * overloaded for bidirectional iterators. - */ - template - void - __reverse(_BidirectionalIterator __first, _BidirectionalIterator __last, - bidirectional_iterator_tag) - { - while (true) - if (__first == __last || __first == --__last) - return; - else - { - std::iter_swap(__first, __last); - ++__first; - } - } - - /** - * This is an uglified reverse(_BidirectionalIterator, - * _BidirectionalIterator) - * overloaded for random access iterators. - */ - template - void - __reverse(_RandomAccessIterator __first, _RandomAccessIterator __last, - random_access_iterator_tag) - { - if (__first == __last) - return; - --__last; - while (__first < __last) - { - std::iter_swap(__first, __last); - ++__first; - --__last; - } - } - - /** - * @brief Reverse a sequence. - * @ingroup mutating_algorithms - * @param __first A bidirectional iterator. - * @param __last A bidirectional iterator. - * @return reverse() returns no value. - * - * Reverses the order of the elements in the range @p [__first,__last), - * so that the first element becomes the last etc. - * For every @c i such that @p 0<=i<=(__last-__first)/2), @p reverse() - * swaps @p *(__first+i) and @p *(__last-(i+1)) - */ - template - inline void - reverse(_BidirectionalIterator __first, _BidirectionalIterator __last) - { - // concept requirements - __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept< - _BidirectionalIterator>) - __glibcxx_requires_valid_range(__first, __last); - std::__reverse(__first, __last, std::__iterator_category(__first)); - } - - /** - * @brief Copy a sequence, reversing its elements. - * @ingroup mutating_algorithms - * @param __first A bidirectional iterator. - * @param __last A bidirectional iterator. - * @param __result An output iterator. - * @return An iterator designating the end of the resulting sequence. - * - * Copies the elements in the range @p [__first,__last) to the - * range @p [__result,__result+(__last-__first)) such that the - * order of the elements is reversed. For every @c i such that @p - * 0<=i<=(__last-__first), @p reverse_copy() performs the - * assignment @p *(__result+(__last-__first)-1-i) = *(__first+i). - * The ranges @p [__first,__last) and @p - * [__result,__result+(__last-__first)) must not overlap. - */ - template - _OutputIterator - reverse_copy(_BidirectionalIterator __first, _BidirectionalIterator __last, - _OutputIterator __result) - { - // concept requirements - __glibcxx_function_requires(_BidirectionalIteratorConcept< - _BidirectionalIterator>) - __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, - typename iterator_traits<_BidirectionalIterator>::value_type>) - __glibcxx_requires_valid_range(__first, __last); - - while (__first != __last) - { - --__last; - *__result = *__last; - ++__result; - } - return __result; - } - - /** - * This is a helper function for the rotate algorithm specialized on RAIs. - * It returns the greatest common divisor of two integer values. - */ - template - _EuclideanRingElement - __gcd(_EuclideanRingElement __m, _EuclideanRingElement __n) - { - while (__n != 0) - { - _EuclideanRingElement __t = __m % __n; - __m = __n; - __n = __t; - } - return __m; - } - - /// This is a helper function for the rotate algorithm. - template - void - __rotate(_ForwardIterator __first, - _ForwardIterator __middle, - _ForwardIterator __last, - forward_iterator_tag) - { - if (__first == __middle || __last == __middle) - return; - - _ForwardIterator __first2 = __middle; - do - { - std::iter_swap(__first, __first2); - ++__first; - ++__first2; - if (__first == __middle) - __middle = __first2; - } - while (__first2 != __last); - - __first2 = __middle; - - while (__first2 != __last) - { - std::iter_swap(__first, __first2); - ++__first; - ++__first2; - if (__first == __middle) - __middle = __first2; - else if (__first2 == __last) - __first2 = __middle; - } - } - - /// This is a helper function for the rotate algorithm. - template - void - __rotate(_BidirectionalIterator __first, - _BidirectionalIterator __middle, - _BidirectionalIterator __last, - bidirectional_iterator_tag) - { - // concept requirements - __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept< - _BidirectionalIterator>) - - if (__first == __middle || __last == __middle) - return; - - std::__reverse(__first, __middle, bidirectional_iterator_tag()); - std::__reverse(__middle, __last, bidirectional_iterator_tag()); - - while (__first != __middle && __middle != __last) - { - std::iter_swap(__first, --__last); - ++__first; - } - - if (__first == __middle) - std::__reverse(__middle, __last, bidirectional_iterator_tag()); - else - std::__reverse(__first, __middle, bidirectional_iterator_tag()); - } - - /// This is a helper function for the rotate algorithm. - template - void - __rotate(_RandomAccessIterator __first, - _RandomAccessIterator __middle, - _RandomAccessIterator __last, - random_access_iterator_tag) - { - // concept requirements - __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept< - _RandomAccessIterator>) - - if (__first == __middle || __last == __middle) - return; - - typedef typename iterator_traits<_RandomAccessIterator>::difference_type - _Distance; - typedef typename iterator_traits<_RandomAccessIterator>::value_type - _ValueType; - - _Distance __n = __last - __first; - _Distance __k = __middle - __first; - - if (__k == __n - __k) - { - std::swap_ranges(__first, __middle, __middle); - return; - } - - _RandomAccessIterator __p = __first; - - for (;;) - { - if (__k < __n - __k) - { - if (__is_pod(_ValueType) && __k == 1) - { - _ValueType __t = _GLIBCXX_MOVE(*__p); - _GLIBCXX_MOVE3(__p + 1, __p + __n, __p); - *(__p + __n - 1) = _GLIBCXX_MOVE(__t); - return; - } - _RandomAccessIterator __q = __p + __k; - for (_Distance __i = 0; __i < __n - __k; ++ __i) - { - std::iter_swap(__p, __q); - ++__p; - ++__q; - } - __n %= __k; - if (__n == 0) - return; - std::swap(__n, __k); - __k = __n - __k; - } - else - { - __k = __n - __k; - if (__is_pod(_ValueType) && __k == 1) - { - _ValueType __t = _GLIBCXX_MOVE(*(__p + __n - 1)); - _GLIBCXX_MOVE_BACKWARD3(__p, __p + __n - 1, __p + __n); - *__p = _GLIBCXX_MOVE(__t); - return; - } - _RandomAccessIterator __q = __p + __n; - __p = __q - __k; - for (_Distance __i = 0; __i < __n - __k; ++ __i) - { - --__p; - --__q; - std::iter_swap(__p, __q); - } - __n %= __k; - if (__n == 0) - return; - std::swap(__n, __k); - } - } - } - - /** - * @brief Rotate the elements of a sequence. - * @ingroup mutating_algorithms - * @param __first A forward iterator. - * @param __middle A forward iterator. - * @param __last A forward iterator. - * @return Nothing. - * - * Rotates the elements of the range @p [__first,__last) by - * @p (__middle - __first) positions so that the element at @p __middle - * is moved to @p __first, the element at @p __middle+1 is moved to - * @p __first+1 and so on for each element in the range - * @p [__first,__last). - * - * This effectively swaps the ranges @p [__first,__middle) and - * @p [__middle,__last). - * - * Performs - * @p *(__first+(n+(__last-__middle))%(__last-__first))=*(__first+n) - * for each @p n in the range @p [0,__last-__first). - */ - template - inline void - rotate(_ForwardIterator __first, _ForwardIterator __middle, - _ForwardIterator __last) - { - // concept requirements - __glibcxx_function_requires(_Mutable_ForwardIteratorConcept< - _ForwardIterator>) - __glibcxx_requires_valid_range(__first, __middle); - __glibcxx_requires_valid_range(__middle, __last); - - typedef typename iterator_traits<_ForwardIterator>::iterator_category - _IterType; - std::__rotate(__first, __middle, __last, _IterType()); - } - - /** - * @brief Copy a sequence, rotating its elements. - * @ingroup mutating_algorithms - * @param __first A forward iterator. - * @param __middle A forward iterator. - * @param __last A forward iterator. - * @param __result An output iterator. - * @return An iterator designating the end of the resulting sequence. - * - * Copies the elements of the range @p [__first,__last) to the - * range beginning at @result, rotating the copied elements by - * @p (__middle-__first) positions so that the element at @p __middle - * is moved to @p __result, the element at @p __middle+1 is moved - * to @p __result+1 and so on for each element in the range @p - * [__first,__last). - * - * Performs - * @p *(__result+(n+(__last-__middle))%(__last-__first))=*(__first+n) - * for each @p n in the range @p [0,__last-__first). - */ - template - _OutputIterator - rotate_copy(_ForwardIterator __first, _ForwardIterator __middle, - _ForwardIterator __last, _OutputIterator __result) - { - // concept requirements - __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>) - __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, - typename iterator_traits<_ForwardIterator>::value_type>) - __glibcxx_requires_valid_range(__first, __middle); - __glibcxx_requires_valid_range(__middle, __last); - - return std::copy(__first, __middle, - std::copy(__middle, __last, __result)); - } - - /// This is a helper function... - template - _ForwardIterator - __partition(_ForwardIterator __first, _ForwardIterator __last, - _Predicate __pred, forward_iterator_tag) - { - if (__first == __last) - return __first; - - while (__pred(*__first)) - if (++__first == __last) - return __first; - - _ForwardIterator __next = __first; - - while (++__next != __last) - if (__pred(*__next)) - { - std::iter_swap(__first, __next); - ++__first; - } - - return __first; - } - - /// This is a helper function... - template - _BidirectionalIterator - __partition(_BidirectionalIterator __first, _BidirectionalIterator __last, - _Predicate __pred, bidirectional_iterator_tag) - { - while (true) - { - while (true) - if (__first == __last) - return __first; - else if (__pred(*__first)) - ++__first; - else - break; - --__last; - while (true) - if (__first == __last) - return __first; - else if (!bool(__pred(*__last))) - --__last; - else - break; - std::iter_swap(__first, __last); - ++__first; - } - } - - // partition - - /// This is a helper function... - /// Requires __len != 0 and !__pred(*__first), - /// same as __stable_partition_adaptive. - template - _ForwardIterator - __inplace_stable_partition(_ForwardIterator __first, - _Predicate __pred, _Distance __len) - { - if (__len == 1) - return __first; - _ForwardIterator __middle = __first; - std::advance(__middle, __len / 2); - _ForwardIterator __left_split = - std::__inplace_stable_partition(__first, __pred, __len / 2); - // Advance past true-predicate values to satisfy this - // function's preconditions. - _Distance __right_len = __len - __len / 2; - _ForwardIterator __right_split = - std::__find_if_not_n(__middle, __right_len, __pred); - if (__right_len) - __right_split = std::__inplace_stable_partition(__middle, - __pred, - __right_len); - std::rotate(__left_split, __middle, __right_split); - std::advance(__left_split, std::distance(__middle, __right_split)); - return __left_split; - } - - /// This is a helper function... - /// Requires __first != __last and !__pred(*__first) - /// and __len == distance(__first, __last). - /// - /// !__pred(*__first) allows us to guarantee that we don't - /// move-assign an element onto itself. - template - _ForwardIterator - __stable_partition_adaptive(_ForwardIterator __first, - _ForwardIterator __last, - _Predicate __pred, _Distance __len, - _Pointer __buffer, - _Distance __buffer_size) - { - if (__len <= __buffer_size) - { - _ForwardIterator __result1 = __first; - _Pointer __result2 = __buffer; - // The precondition guarantees that !__pred(*__first), so - // move that element to the buffer before starting the loop. - // This ensures that we only call __pred once per element. - *__result2 = _GLIBCXX_MOVE(*__first); - ++__result2; - ++__first; - for (; __first != __last; ++__first) - if (__pred(*__first)) - { - *__result1 = _GLIBCXX_MOVE(*__first); - ++__result1; - } - else - { - *__result2 = _GLIBCXX_MOVE(*__first); - ++__result2; - } - _GLIBCXX_MOVE3(__buffer, __result2, __result1); - return __result1; - } - else - { - _ForwardIterator __middle = __first; - std::advance(__middle, __len / 2); - _ForwardIterator __left_split = - std::__stable_partition_adaptive(__first, __middle, __pred, - __len / 2, __buffer, - __buffer_size); - // Advance past true-predicate values to satisfy this - // function's preconditions. - _Distance __right_len = __len - __len / 2; - _ForwardIterator __right_split = - std::__find_if_not_n(__middle, __right_len, __pred); - if (__right_len) - __right_split = - std::__stable_partition_adaptive(__right_split, __last, __pred, - __right_len, - __buffer, __buffer_size); - std::rotate(__left_split, __middle, __right_split); - std::advance(__left_split, std::distance(__middle, __right_split)); - return __left_split; - } - } - - /** - * @brief Move elements for which a predicate is true to the beginning - * of a sequence, preserving relative ordering. - * @ingroup mutating_algorithms - * @param __first A forward iterator. - * @param __last A forward iterator. - * @param __pred A predicate functor. - * @return An iterator @p middle such that @p __pred(i) is true for each - * iterator @p i in the range @p [first,middle) and false for each @p i - * in the range @p [middle,last). - * - * Performs the same function as @p partition() with the additional - * guarantee that the relative ordering of elements in each group is - * preserved, so any two elements @p x and @p y in the range - * @p [__first,__last) such that @p __pred(x)==__pred(y) will have the same - * relative ordering after calling @p stable_partition(). - */ - template - _ForwardIterator - stable_partition(_ForwardIterator __first, _ForwardIterator __last, - _Predicate __pred) - { - // concept requirements - __glibcxx_function_requires(_Mutable_ForwardIteratorConcept< - _ForwardIterator>) - __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate, - typename iterator_traits<_ForwardIterator>::value_type>) - __glibcxx_requires_valid_range(__first, __last); - - __first = std::__find_if_not(__first, __last, __pred); - - if (__first == __last) - return __first; - else - { - typedef typename iterator_traits<_ForwardIterator>::value_type - _ValueType; - typedef typename iterator_traits<_ForwardIterator>::difference_type - _DistanceType; - - _Temporary_buffer<_ForwardIterator, _ValueType> __buf(__first, - __last); - if (__buf.size() > 0) - return - std::__stable_partition_adaptive(__first, __last, __pred, - _DistanceType(__buf.requested_size()), - __buf.begin(), - _DistanceType(__buf.size())); - else - return - std::__inplace_stable_partition(__first, __pred, - _DistanceType(__buf.requested_size())); - } - } - - /// This is a helper function for the sort routines. - template - void - __heap_select(_RandomAccessIterator __first, - _RandomAccessIterator __middle, - _RandomAccessIterator __last) - { - std::make_heap(__first, __middle); - for (_RandomAccessIterator __i = __middle; __i < __last; ++__i) - if (*__i < *__first) - std::__pop_heap(__first, __middle, __i); - } - - /// This is a helper function for the sort routines. - template - void - __heap_select(_RandomAccessIterator __first, - _RandomAccessIterator __middle, - _RandomAccessIterator __last, _Compare __comp) - { - std::make_heap(__first, __middle, __comp); - for (_RandomAccessIterator __i = __middle; __i < __last; ++__i) - if (__comp(*__i, *__first)) - std::__pop_heap(__first, __middle, __i, __comp); - } - - // partial_sort - - /** - * @brief Copy the smallest elements of a sequence. - * @ingroup sorting_algorithms - * @param __first An iterator. - * @param __last Another iterator. - * @param __result_first A random-access iterator. - * @param __result_last Another random-access iterator. - * @return An iterator indicating the end of the resulting sequence. - * - * Copies and sorts the smallest N values from the range @p [__first,__last) - * to the range beginning at @p __result_first, where the number of - * elements to be copied, @p N, is the smaller of @p (__last-__first) and - * @p (__result_last-__result_first). - * After the sort if @e i and @e j are iterators in the range - * @p [__result_first,__result_first+N) such that i precedes j then - * *j<*i is false. - * The value returned is @p __result_first+N. - */ - template - _RandomAccessIterator - partial_sort_copy(_InputIterator __first, _InputIterator __last, - _RandomAccessIterator __result_first, - _RandomAccessIterator __result_last) - { - typedef typename iterator_traits<_InputIterator>::value_type - _InputValueType; - typedef typename iterator_traits<_RandomAccessIterator>::value_type - _OutputValueType; - typedef typename iterator_traits<_RandomAccessIterator>::difference_type - _DistanceType; - - // concept requirements - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>) - __glibcxx_function_requires(_ConvertibleConcept<_InputValueType, - _OutputValueType>) - __glibcxx_function_requires(_LessThanOpConcept<_InputValueType, - _OutputValueType>) - __glibcxx_function_requires(_LessThanComparableConcept<_OutputValueType>) - __glibcxx_requires_valid_range(__first, __last); - __glibcxx_requires_valid_range(__result_first, __result_last); - - if (__result_first == __result_last) - return __result_last; - _RandomAccessIterator __result_real_last = __result_first; - while(__first != __last && __result_real_last != __result_last) - { - *__result_real_last = *__first; - ++__result_real_last; - ++__first; - } - std::make_heap(__result_first, __result_real_last); - while (__first != __last) - { - if (*__first < *__result_first) - std::__adjust_heap(__result_first, _DistanceType(0), - _DistanceType(__result_real_last - - __result_first), - _InputValueType(*__first)); - ++__first; - } - std::sort_heap(__result_first, __result_real_last); - return __result_real_last; - } - - /** - * @brief Copy the smallest elements of a sequence using a predicate for - * comparison. - * @ingroup sorting_algorithms - * @param __first An input iterator. - * @param __last Another input iterator. - * @param __result_first A random-access iterator. - * @param __result_last Another random-access iterator. - * @param __comp A comparison functor. - * @return An iterator indicating the end of the resulting sequence. - * - * Copies and sorts the smallest N values from the range @p [__first,__last) - * to the range beginning at @p result_first, where the number of - * elements to be copied, @p N, is the smaller of @p (__last-__first) and - * @p (__result_last-__result_first). - * After the sort if @e i and @e j are iterators in the range - * @p [__result_first,__result_first+N) such that i precedes j then - * @p __comp(*j,*i) is false. - * The value returned is @p __result_first+N. - */ - template - _RandomAccessIterator - partial_sort_copy(_InputIterator __first, _InputIterator __last, - _RandomAccessIterator __result_first, - _RandomAccessIterator __result_last, - _Compare __comp) - { - typedef typename iterator_traits<_InputIterator>::value_type - _InputValueType; - typedef typename iterator_traits<_RandomAccessIterator>::value_type - _OutputValueType; - typedef typename iterator_traits<_RandomAccessIterator>::difference_type - _DistanceType; - - // concept requirements - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>) - __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept< - _RandomAccessIterator>) - __glibcxx_function_requires(_ConvertibleConcept<_InputValueType, - _OutputValueType>) - __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, - _InputValueType, _OutputValueType>) - __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, - _OutputValueType, _OutputValueType>) - __glibcxx_requires_valid_range(__first, __last); - __glibcxx_requires_valid_range(__result_first, __result_last); - - if (__result_first == __result_last) - return __result_last; - _RandomAccessIterator __result_real_last = __result_first; - while(__first != __last && __result_real_last != __result_last) - { - *__result_real_last = *__first; - ++__result_real_last; - ++__first; - } - std::make_heap(__result_first, __result_real_last, __comp); - while (__first != __last) - { - if (__comp(*__first, *__result_first)) - std::__adjust_heap(__result_first, _DistanceType(0), - _DistanceType(__result_real_last - - __result_first), - _InputValueType(*__first), - __comp); - ++__first; - } - std::sort_heap(__result_first, __result_real_last, __comp); - return __result_real_last; - } - - /// This is a helper function for the sort routine. - template - void - __unguarded_linear_insert(_RandomAccessIterator __last) - { - typename iterator_traits<_RandomAccessIterator>::value_type - __val = _GLIBCXX_MOVE(*__last); - _RandomAccessIterator __next = __last; - --__next; - while (__val < *__next) - { - *__last = _GLIBCXX_MOVE(*__next); - __last = __next; - --__next; - } - *__last = _GLIBCXX_MOVE(__val); - } - - /// This is a helper function for the sort routine. - template - void - __unguarded_linear_insert(_RandomAccessIterator __last, - _Compare __comp) - { - typename iterator_traits<_RandomAccessIterator>::value_type - __val = _GLIBCXX_MOVE(*__last); - _RandomAccessIterator __next = __last; - --__next; - while (__comp(__val, *__next)) - { - *__last = _GLIBCXX_MOVE(*__next); - __last = __next; - --__next; - } - *__last = _GLIBCXX_MOVE(__val); - } - - /// This is a helper function for the sort routine. - template - void - __insertion_sort(_RandomAccessIterator __first, - _RandomAccessIterator __last) - { - if (__first == __last) - return; - - for (_RandomAccessIterator __i = __first + 1; __i != __last; ++__i) - { - if (*__i < *__first) - { - typename iterator_traits<_RandomAccessIterator>::value_type - __val = _GLIBCXX_MOVE(*__i); - _GLIBCXX_MOVE_BACKWARD3(__first, __i, __i + 1); - *__first = _GLIBCXX_MOVE(__val); - } - else - std::__unguarded_linear_insert(__i); - } - } - - /// This is a helper function for the sort routine. - template - void - __insertion_sort(_RandomAccessIterator __first, - _RandomAccessIterator __last, _Compare __comp) - { - if (__first == __last) return; - - for (_RandomAccessIterator __i = __first + 1; __i != __last; ++__i) - { - if (__comp(*__i, *__first)) - { - typename iterator_traits<_RandomAccessIterator>::value_type - __val = _GLIBCXX_MOVE(*__i); - _GLIBCXX_MOVE_BACKWARD3(__first, __i, __i + 1); - *__first = _GLIBCXX_MOVE(__val); - } - else - std::__unguarded_linear_insert(__i, __comp); - } - } - - /// This is a helper function for the sort routine. - template - inline void - __unguarded_insertion_sort(_RandomAccessIterator __first, - _RandomAccessIterator __last) - { - typedef typename iterator_traits<_RandomAccessIterator>::value_type - _ValueType; - - for (_RandomAccessIterator __i = __first; __i != __last; ++__i) - std::__unguarded_linear_insert(__i); - } - - /// This is a helper function for the sort routine. - template - inline void - __unguarded_insertion_sort(_RandomAccessIterator __first, - _RandomAccessIterator __last, _Compare __comp) - { - typedef typename iterator_traits<_RandomAccessIterator>::value_type - _ValueType; - - for (_RandomAccessIterator __i = __first; __i != __last; ++__i) - std::__unguarded_linear_insert(__i, __comp); - } - - /** - * @doctodo - * This controls some aspect of the sort routines. - */ - enum { _S_threshold = 16 }; - - /// This is a helper function for the sort routine. - template - void - __final_insertion_sort(_RandomAccessIterator __first, - _RandomAccessIterator __last) - { - if (__last - __first > int(_S_threshold)) - { - std::__insertion_sort(__first, __first + int(_S_threshold)); - std::__unguarded_insertion_sort(__first + int(_S_threshold), __last); - } - else - std::__insertion_sort(__first, __last); - } - - /// This is a helper function for the sort routine. - template - void - __final_insertion_sort(_RandomAccessIterator __first, - _RandomAccessIterator __last, _Compare __comp) - { - if (__last - __first > int(_S_threshold)) - { - std::__insertion_sort(__first, __first + int(_S_threshold), __comp); - std::__unguarded_insertion_sort(__first + int(_S_threshold), __last, - __comp); - } - else - std::__insertion_sort(__first, __last, __comp); - } - - /// This is a helper function... - template - _RandomAccessIterator - __unguarded_partition(_RandomAccessIterator __first, - _RandomAccessIterator __last, const _Tp& __pivot) - { - while (true) - { - while (*__first < __pivot) - ++__first; - --__last; - while (__pivot < *__last) - --__last; - if (!(__first < __last)) - return __first; - std::iter_swap(__first, __last); - ++__first; - } - } - - /// This is a helper function... - template - _RandomAccessIterator - __unguarded_partition(_RandomAccessIterator __first, - _RandomAccessIterator __last, - const _Tp& __pivot, _Compare __comp) - { - while (true) - { - while (__comp(*__first, __pivot)) - ++__first; - --__last; - while (__comp(__pivot, *__last)) - --__last; - if (!(__first < __last)) - return __first; - std::iter_swap(__first, __last); - ++__first; - } - } - - /// This is a helper function... - template - inline _RandomAccessIterator - __unguarded_partition_pivot(_RandomAccessIterator __first, - _RandomAccessIterator __last) - { - _RandomAccessIterator __mid = __first + (__last - __first) / 2; - std::__move_median_to_first(__first, __first + 1, __mid, __last - 1); - return std::__unguarded_partition(__first + 1, __last, *__first); - } - - - /// This is a helper function... - template - inline _RandomAccessIterator - __unguarded_partition_pivot(_RandomAccessIterator __first, - _RandomAccessIterator __last, _Compare __comp) - { - _RandomAccessIterator __mid = __first + (__last - __first) / 2; - std::__move_median_to_first(__first, __first + 1, __mid, __last - 1, - __comp); - return std::__unguarded_partition(__first + 1, __last, *__first, __comp); - } - - /// This is a helper function for the sort routine. - template - void - __introsort_loop(_RandomAccessIterator __first, - _RandomAccessIterator __last, - _Size __depth_limit) - { - while (__last - __first > int(_S_threshold)) - { - if (__depth_limit == 0) - { - _GLIBCXX_STD_A::partial_sort(__first, __last, __last); - return; - } - --__depth_limit; - _RandomAccessIterator __cut = - std::__unguarded_partition_pivot(__first, __last); - std::__introsort_loop(__cut, __last, __depth_limit); - __last = __cut; - } - } - - /// This is a helper function for the sort routine. - template - void - __introsort_loop(_RandomAccessIterator __first, - _RandomAccessIterator __last, - _Size __depth_limit, _Compare __comp) - { - while (__last - __first > int(_S_threshold)) - { - if (__depth_limit == 0) - { - _GLIBCXX_STD_A::partial_sort(__first, __last, __last, __comp); - return; - } - --__depth_limit; - _RandomAccessIterator __cut = - std::__unguarded_partition_pivot(__first, __last, __comp); - std::__introsort_loop(__cut, __last, __depth_limit, __comp); - __last = __cut; - } - } - - // sort - - template - void - __introselect(_RandomAccessIterator __first, _RandomAccessIterator __nth, - _RandomAccessIterator __last, _Size __depth_limit) - { - typedef typename iterator_traits<_RandomAccessIterator>::value_type - _ValueType; - - while (__last - __first > 3) - { - if (__depth_limit == 0) - { - std::__heap_select(__first, __nth + 1, __last); - - // Place the nth largest element in its final position. - std::iter_swap(__first, __nth); - return; - } - --__depth_limit; - _RandomAccessIterator __cut = - std::__unguarded_partition_pivot(__first, __last); - if (__cut <= __nth) - __first = __cut; - else - __last = __cut; - } - std::__insertion_sort(__first, __last); - } - - template - void - __introselect(_RandomAccessIterator __first, _RandomAccessIterator __nth, - _RandomAccessIterator __last, _Size __depth_limit, - _Compare __comp) - { - typedef typename iterator_traits<_RandomAccessIterator>::value_type - _ValueType; - - while (__last - __first > 3) - { - if (__depth_limit == 0) - { - std::__heap_select(__first, __nth + 1, __last, __comp); - // Place the nth largest element in its final position. - std::iter_swap(__first, __nth); - return; - } - --__depth_limit; - _RandomAccessIterator __cut = - std::__unguarded_partition_pivot(__first, __last, __comp); - if (__cut <= __nth) - __first = __cut; - else - __last = __cut; - } - std::__insertion_sort(__first, __last, __comp); - } - - // nth_element - - // lower_bound moved to stl_algobase.h - - /** - * @brief Finds the first position in which @p __val could be inserted - * without changing the ordering. - * @ingroup binary_search_algorithms - * @param __first An iterator. - * @param __last Another iterator. - * @param __val The search term. - * @param __comp A functor to use for comparisons. - * @return An iterator pointing to the first element not less - * than @p __val, or end() if every element is less - * than @p __val. - * @ingroup binary_search_algorithms - * - * The comparison function should have the same effects on ordering as - * the function used for the initial sort. - */ - template - _ForwardIterator - lower_bound(_ForwardIterator __first, _ForwardIterator __last, - const _Tp& __val, _Compare __comp) - { - typedef typename iterator_traits<_ForwardIterator>::value_type - _ValueType; - typedef typename iterator_traits<_ForwardIterator>::difference_type - _DistanceType; - - // concept requirements - __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>) - __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, - _ValueType, _Tp>) - __glibcxx_requires_partitioned_lower_pred(__first, __last, - __val, __comp); - - _DistanceType __len = std::distance(__first, __last); - - while (__len > 0) - { - _DistanceType __half = __len >> 1; - _ForwardIterator __middle = __first; - std::advance(__middle, __half); - if (__comp(*__middle, __val)) - { - __first = __middle; - ++__first; - __len = __len - __half - 1; - } - else - __len = __half; - } - return __first; - } - - /** - * @brief Finds the last position in which @p __val could be inserted - * without changing the ordering. - * @ingroup binary_search_algorithms - * @param __first An iterator. - * @param __last Another iterator. - * @param __val The search term. - * @return An iterator pointing to the first element greater than @p __val, - * or end() if no elements are greater than @p __val. - * @ingroup binary_search_algorithms - */ - template - _ForwardIterator - upper_bound(_ForwardIterator __first, _ForwardIterator __last, - const _Tp& __val) - { - typedef typename iterator_traits<_ForwardIterator>::value_type - _ValueType; - typedef typename iterator_traits<_ForwardIterator>::difference_type - _DistanceType; - - // concept requirements - __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>) - __glibcxx_function_requires(_LessThanOpConcept<_Tp, _ValueType>) - __glibcxx_requires_partitioned_upper(__first, __last, __val); - - _DistanceType __len = std::distance(__first, __last); - - while (__len > 0) - { - _DistanceType __half = __len >> 1; - _ForwardIterator __middle = __first; - std::advance(__middle, __half); - if (__val < *__middle) - __len = __half; - else - { - __first = __middle; - ++__first; - __len = __len - __half - 1; - } - } - return __first; - } - - /** - * @brief Finds the last position in which @p __val could be inserted - * without changing the ordering. - * @ingroup binary_search_algorithms - * @param __first An iterator. - * @param __last Another iterator. - * @param __val The search term. - * @param __comp A functor to use for comparisons. - * @return An iterator pointing to the first element greater than @p __val, - * or end() if no elements are greater than @p __val. - * @ingroup binary_search_algorithms - * - * The comparison function should have the same effects on ordering as - * the function used for the initial sort. - */ - template - _ForwardIterator - upper_bound(_ForwardIterator __first, _ForwardIterator __last, - const _Tp& __val, _Compare __comp) - { - typedef typename iterator_traits<_ForwardIterator>::value_type - _ValueType; - typedef typename iterator_traits<_ForwardIterator>::difference_type - _DistanceType; - - // concept requirements - __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>) - __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, - _Tp, _ValueType>) - __glibcxx_requires_partitioned_upper_pred(__first, __last, - __val, __comp); - - _DistanceType __len = std::distance(__first, __last); - - while (__len > 0) - { - _DistanceType __half = __len >> 1; - _ForwardIterator __middle = __first; - std::advance(__middle, __half); - if (__comp(__val, *__middle)) - __len = __half; - else - { - __first = __middle; - ++__first; - __len = __len - __half - 1; - } - } - return __first; - } - - /** - * @brief Finds the largest subrange in which @p __val could be inserted - * at any place in it without changing the ordering. - * @ingroup binary_search_algorithms - * @param __first An iterator. - * @param __last Another iterator. - * @param __val The search term. - * @return An pair of iterators defining the subrange. - * @ingroup binary_search_algorithms - * - * This is equivalent to - * @code - * std::make_pair(lower_bound(__first, __last, __val), - * upper_bound(__first, __last, __val)) - * @endcode - * but does not actually call those functions. - */ - template - pair<_ForwardIterator, _ForwardIterator> - equal_range(_ForwardIterator __first, _ForwardIterator __last, - const _Tp& __val) - { - typedef typename iterator_traits<_ForwardIterator>::value_type - _ValueType; - typedef typename iterator_traits<_ForwardIterator>::difference_type - _DistanceType; - - // concept requirements - __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>) - __glibcxx_function_requires(_LessThanOpConcept<_ValueType, _Tp>) - __glibcxx_function_requires(_LessThanOpConcept<_Tp, _ValueType>) - __glibcxx_requires_partitioned_lower(__first, __last, __val); - __glibcxx_requires_partitioned_upper(__first, __last, __val); - - _DistanceType __len = std::distance(__first, __last); - - while (__len > 0) - { - _DistanceType __half = __len >> 1; - _ForwardIterator __middle = __first; - std::advance(__middle, __half); - if (*__middle < __val) - { - __first = __middle; - ++__first; - __len = __len - __half - 1; - } - else if (__val < *__middle) - __len = __half; - else - { - _ForwardIterator __left = std::lower_bound(__first, __middle, - __val); - std::advance(__first, __len); - _ForwardIterator __right = std::upper_bound(++__middle, __first, - __val); - return pair<_ForwardIterator, _ForwardIterator>(__left, __right); - } - } - return pair<_ForwardIterator, _ForwardIterator>(__first, __first); - } - - /** - * @brief Finds the largest subrange in which @p __val could be inserted - * at any place in it without changing the ordering. - * @param __first An iterator. - * @param __last Another iterator. - * @param __val The search term. - * @param __comp A functor to use for comparisons. - * @return An pair of iterators defining the subrange. - * @ingroup binary_search_algorithms - * - * This is equivalent to - * @code - * std::make_pair(lower_bound(__first, __last, __val, __comp), - * upper_bound(__first, __last, __val, __comp)) - * @endcode - * but does not actually call those functions. - */ - template - pair<_ForwardIterator, _ForwardIterator> - equal_range(_ForwardIterator __first, _ForwardIterator __last, - const _Tp& __val, _Compare __comp) - { - typedef typename iterator_traits<_ForwardIterator>::value_type - _ValueType; - typedef typename iterator_traits<_ForwardIterator>::difference_type - _DistanceType; - - // concept requirements - __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>) - __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, - _ValueType, _Tp>) - __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, - _Tp, _ValueType>) - __glibcxx_requires_partitioned_lower_pred(__first, __last, - __val, __comp); - __glibcxx_requires_partitioned_upper_pred(__first, __last, - __val, __comp); - - _DistanceType __len = std::distance(__first, __last); - - while (__len > 0) - { - _DistanceType __half = __len >> 1; - _ForwardIterator __middle = __first; - std::advance(__middle, __half); - if (__comp(*__middle, __val)) - { - __first = __middle; - ++__first; - __len = __len - __half - 1; - } - else if (__comp(__val, *__middle)) - __len = __half; - else - { - _ForwardIterator __left = std::lower_bound(__first, __middle, - __val, __comp); - std::advance(__first, __len); - _ForwardIterator __right = std::upper_bound(++__middle, __first, - __val, __comp); - return pair<_ForwardIterator, _ForwardIterator>(__left, __right); - } - } - return pair<_ForwardIterator, _ForwardIterator>(__first, __first); - } - - /** - * @brief Determines whether an element exists in a range. - * @ingroup binary_search_algorithms - * @param __first An iterator. - * @param __last Another iterator. - * @param __val The search term. - * @return True if @p __val (or its equivalent) is in [@p - * __first,@p __last ]. - * - * Note that this does not actually return an iterator to @p __val. For - * that, use std::find or a container's specialized find member functions. - */ - template - bool - binary_search(_ForwardIterator __first, _ForwardIterator __last, - const _Tp& __val) - { - typedef typename iterator_traits<_ForwardIterator>::value_type - _ValueType; - - // concept requirements - __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>) - __glibcxx_function_requires(_LessThanOpConcept<_Tp, _ValueType>) - __glibcxx_requires_partitioned_lower(__first, __last, __val); - __glibcxx_requires_partitioned_upper(__first, __last, __val); - - _ForwardIterator __i = std::lower_bound(__first, __last, __val); - return __i != __last && !(__val < *__i); - } - - /** - * @brief Determines whether an element exists in a range. - * @ingroup binary_search_algorithms - * @param __first An iterator. - * @param __last Another iterator. - * @param __val The search term. - * @param __comp A functor to use for comparisons. - * @return True if @p __val (or its equivalent) is in @p [__first,__last]. - * - * Note that this does not actually return an iterator to @p __val. For - * that, use std::find or a container's specialized find member functions. - * - * The comparison function should have the same effects on ordering as - * the function used for the initial sort. - */ - template - bool - binary_search(_ForwardIterator __first, _ForwardIterator __last, - const _Tp& __val, _Compare __comp) - { - typedef typename iterator_traits<_ForwardIterator>::value_type - _ValueType; - - // concept requirements - __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>) - __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, - _Tp, _ValueType>) - __glibcxx_requires_partitioned_lower_pred(__first, __last, - __val, __comp); - __glibcxx_requires_partitioned_upper_pred(__first, __last, - __val, __comp); - - _ForwardIterator __i = std::lower_bound(__first, __last, __val, __comp); - return __i != __last && !bool(__comp(__val, *__i)); - } - - // merge - - /// This is a helper function for the __merge_adaptive routines. - template - void - __move_merge_adaptive(_InputIterator1 __first1, _InputIterator1 __last1, - _InputIterator2 __first2, _InputIterator2 __last2, - _OutputIterator __result) - { - while (__first1 != __last1 && __first2 != __last2) - { - if (*__first2 < *__first1) - { - *__result = _GLIBCXX_MOVE(*__first2); - ++__first2; - } - else - { - *__result = _GLIBCXX_MOVE(*__first1); - ++__first1; - } - ++__result; - } - if (__first1 != __last1) - _GLIBCXX_MOVE3(__first1, __last1, __result); - } - - /// This is a helper function for the __merge_adaptive routines. - template - void - __move_merge_adaptive(_InputIterator1 __first1, _InputIterator1 __last1, - _InputIterator2 __first2, _InputIterator2 __last2, - _OutputIterator __result, _Compare __comp) - { - while (__first1 != __last1 && __first2 != __last2) - { - if (__comp(*__first2, *__first1)) - { - *__result = _GLIBCXX_MOVE(*__first2); - ++__first2; - } - else - { - *__result = _GLIBCXX_MOVE(*__first1); - ++__first1; - } - ++__result; - } - if (__first1 != __last1) - _GLIBCXX_MOVE3(__first1, __last1, __result); - } - - /// This is a helper function for the __merge_adaptive routines. - template - void - __move_merge_adaptive_backward(_BidirectionalIterator1 __first1, - _BidirectionalIterator1 __last1, - _BidirectionalIterator2 __first2, - _BidirectionalIterator2 __last2, - _BidirectionalIterator3 __result) - { - if (__first1 == __last1) - { - _GLIBCXX_MOVE_BACKWARD3(__first2, __last2, __result); - return; - } - else if (__first2 == __last2) - return; - - --__last1; - --__last2; - while (true) - { - if (*__last2 < *__last1) - { - *--__result = _GLIBCXX_MOVE(*__last1); - if (__first1 == __last1) - { - _GLIBCXX_MOVE_BACKWARD3(__first2, ++__last2, __result); - return; - } - --__last1; - } - else - { - *--__result = _GLIBCXX_MOVE(*__last2); - if (__first2 == __last2) - return; - --__last2; - } - } - } - - /// This is a helper function for the __merge_adaptive routines. - template - void - __move_merge_adaptive_backward(_BidirectionalIterator1 __first1, - _BidirectionalIterator1 __last1, - _BidirectionalIterator2 __first2, - _BidirectionalIterator2 __last2, - _BidirectionalIterator3 __result, - _Compare __comp) - { - if (__first1 == __last1) - { - _GLIBCXX_MOVE_BACKWARD3(__first2, __last2, __result); - return; - } - else if (__first2 == __last2) - return; - - --__last1; - --__last2; - while (true) - { - if (__comp(*__last2, *__last1)) - { - *--__result = _GLIBCXX_MOVE(*__last1); - if (__first1 == __last1) - { - _GLIBCXX_MOVE_BACKWARD3(__first2, ++__last2, __result); - return; - } - --__last1; - } - else - { - *--__result = _GLIBCXX_MOVE(*__last2); - if (__first2 == __last2) - return; - --__last2; - } - } - } - - /// This is a helper function for the merge routines. - template - _BidirectionalIterator1 - __rotate_adaptive(_BidirectionalIterator1 __first, - _BidirectionalIterator1 __middle, - _BidirectionalIterator1 __last, - _Distance __len1, _Distance __len2, - _BidirectionalIterator2 __buffer, - _Distance __buffer_size) - { - _BidirectionalIterator2 __buffer_end; - if (__len1 > __len2 && __len2 <= __buffer_size) - { - if (__len2) - { - __buffer_end = _GLIBCXX_MOVE3(__middle, __last, __buffer); - _GLIBCXX_MOVE_BACKWARD3(__first, __middle, __last); - return _GLIBCXX_MOVE3(__buffer, __buffer_end, __first); - } - else - return __first; - } - else if (__len1 <= __buffer_size) - { - if (__len1) - { - __buffer_end = _GLIBCXX_MOVE3(__first, __middle, __buffer); - _GLIBCXX_MOVE3(__middle, __last, __first); - return _GLIBCXX_MOVE_BACKWARD3(__buffer, __buffer_end, __last); - } - else - return __last; - } - else - { - std::rotate(__first, __middle, __last); - std::advance(__first, std::distance(__middle, __last)); - return __first; - } - } - - /// This is a helper function for the merge routines. - template - void - __merge_adaptive(_BidirectionalIterator __first, - _BidirectionalIterator __middle, - _BidirectionalIterator __last, - _Distance __len1, _Distance __len2, - _Pointer __buffer, _Distance __buffer_size) - { - if (__len1 <= __len2 && __len1 <= __buffer_size) - { - _Pointer __buffer_end = _GLIBCXX_MOVE3(__first, __middle, __buffer); - std::__move_merge_adaptive(__buffer, __buffer_end, __middle, __last, - __first); - } - else if (__len2 <= __buffer_size) - { - _Pointer __buffer_end = _GLIBCXX_MOVE3(__middle, __last, __buffer); - std::__move_merge_adaptive_backward(__first, __middle, __buffer, - __buffer_end, __last); - } - else - { - _BidirectionalIterator __first_cut = __first; - _BidirectionalIterator __second_cut = __middle; - _Distance __len11 = 0; - _Distance __len22 = 0; - if (__len1 > __len2) - { - __len11 = __len1 / 2; - std::advance(__first_cut, __len11); - __second_cut = std::lower_bound(__middle, __last, - *__first_cut); - __len22 = std::distance(__middle, __second_cut); - } - else - { - __len22 = __len2 / 2; - std::advance(__second_cut, __len22); - __first_cut = std::upper_bound(__first, __middle, - *__second_cut); - __len11 = std::distance(__first, __first_cut); - } - _BidirectionalIterator __new_middle = - std::__rotate_adaptive(__first_cut, __middle, __second_cut, - __len1 - __len11, __len22, __buffer, - __buffer_size); - std::__merge_adaptive(__first, __first_cut, __new_middle, __len11, - __len22, __buffer, __buffer_size); - std::__merge_adaptive(__new_middle, __second_cut, __last, - __len1 - __len11, - __len2 - __len22, __buffer, __buffer_size); - } - } - - /// This is a helper function for the merge routines. - template - void - __merge_adaptive(_BidirectionalIterator __first, - _BidirectionalIterator __middle, - _BidirectionalIterator __last, - _Distance __len1, _Distance __len2, - _Pointer __buffer, _Distance __buffer_size, - _Compare __comp) - { - if (__len1 <= __len2 && __len1 <= __buffer_size) - { - _Pointer __buffer_end = _GLIBCXX_MOVE3(__first, __middle, __buffer); - std::__move_merge_adaptive(__buffer, __buffer_end, __middle, __last, - __first, __comp); - } - else if (__len2 <= __buffer_size) - { - _Pointer __buffer_end = _GLIBCXX_MOVE3(__middle, __last, __buffer); - std::__move_merge_adaptive_backward(__first, __middle, __buffer, - __buffer_end, __last, __comp); - } - else - { - _BidirectionalIterator __first_cut = __first; - _BidirectionalIterator __second_cut = __middle; - _Distance __len11 = 0; - _Distance __len22 = 0; - if (__len1 > __len2) - { - __len11 = __len1 / 2; - std::advance(__first_cut, __len11); - __second_cut = std::lower_bound(__middle, __last, *__first_cut, - __comp); - __len22 = std::distance(__middle, __second_cut); - } - else - { - __len22 = __len2 / 2; - std::advance(__second_cut, __len22); - __first_cut = std::upper_bound(__first, __middle, *__second_cut, - __comp); - __len11 = std::distance(__first, __first_cut); - } - _BidirectionalIterator __new_middle = - std::__rotate_adaptive(__first_cut, __middle, __second_cut, - __len1 - __len11, __len22, __buffer, - __buffer_size); - std::__merge_adaptive(__first, __first_cut, __new_middle, __len11, - __len22, __buffer, __buffer_size, __comp); - std::__merge_adaptive(__new_middle, __second_cut, __last, - __len1 - __len11, - __len2 - __len22, __buffer, - __buffer_size, __comp); - } - } - - /// This is a helper function for the merge routines. - template - void - __merge_without_buffer(_BidirectionalIterator __first, - _BidirectionalIterator __middle, - _BidirectionalIterator __last, - _Distance __len1, _Distance __len2) - { - if (__len1 == 0 || __len2 == 0) - return; - if (__len1 + __len2 == 2) - { - if (*__middle < *__first) - std::iter_swap(__first, __middle); - return; - } - _BidirectionalIterator __first_cut = __first; - _BidirectionalIterator __second_cut = __middle; - _Distance __len11 = 0; - _Distance __len22 = 0; - if (__len1 > __len2) - { - __len11 = __len1 / 2; - std::advance(__first_cut, __len11); - __second_cut = std::lower_bound(__middle, __last, *__first_cut); - __len22 = std::distance(__middle, __second_cut); - } - else - { - __len22 = __len2 / 2; - std::advance(__second_cut, __len22); - __first_cut = std::upper_bound(__first, __middle, *__second_cut); - __len11 = std::distance(__first, __first_cut); - } - std::rotate(__first_cut, __middle, __second_cut); - _BidirectionalIterator __new_middle = __first_cut; - std::advance(__new_middle, std::distance(__middle, __second_cut)); - std::__merge_without_buffer(__first, __first_cut, __new_middle, - __len11, __len22); - std::__merge_without_buffer(__new_middle, __second_cut, __last, - __len1 - __len11, __len2 - __len22); - } - - /// This is a helper function for the merge routines. - template - void - __merge_without_buffer(_BidirectionalIterator __first, - _BidirectionalIterator __middle, - _BidirectionalIterator __last, - _Distance __len1, _Distance __len2, - _Compare __comp) - { - if (__len1 == 0 || __len2 == 0) - return; - if (__len1 + __len2 == 2) - { - if (__comp(*__middle, *__first)) - std::iter_swap(__first, __middle); - return; - } - _BidirectionalIterator __first_cut = __first; - _BidirectionalIterator __second_cut = __middle; - _Distance __len11 = 0; - _Distance __len22 = 0; - if (__len1 > __len2) - { - __len11 = __len1 / 2; - std::advance(__first_cut, __len11); - __second_cut = std::lower_bound(__middle, __last, *__first_cut, - __comp); - __len22 = std::distance(__middle, __second_cut); - } - else - { - __len22 = __len2 / 2; - std::advance(__second_cut, __len22); - __first_cut = std::upper_bound(__first, __middle, *__second_cut, - __comp); - __len11 = std::distance(__first, __first_cut); - } - std::rotate(__first_cut, __middle, __second_cut); - _BidirectionalIterator __new_middle = __first_cut; - std::advance(__new_middle, std::distance(__middle, __second_cut)); - std::__merge_without_buffer(__first, __first_cut, __new_middle, - __len11, __len22, __comp); - std::__merge_without_buffer(__new_middle, __second_cut, __last, - __len1 - __len11, __len2 - __len22, __comp); - } - - /** - * @brief Merges two sorted ranges in place. - * @ingroup sorting_algorithms - * @param __first An iterator. - * @param __middle Another iterator. - * @param __last Another iterator. - * @return Nothing. - * - * Merges two sorted and consecutive ranges, [__first,__middle) and - * [__middle,__last), and puts the result in [__first,__last). The - * output will be sorted. The sort is @e stable, that is, for - * equivalent elements in the two ranges, elements from the first - * range will always come before elements from the second. - * - * If enough additional memory is available, this takes (__last-__first)-1 - * comparisons. Otherwise an NlogN algorithm is used, where N is - * distance(__first,__last). - */ - template - void - inplace_merge(_BidirectionalIterator __first, - _BidirectionalIterator __middle, - _BidirectionalIterator __last) - { - typedef typename iterator_traits<_BidirectionalIterator>::value_type - _ValueType; - typedef typename iterator_traits<_BidirectionalIterator>::difference_type - _DistanceType; - - // concept requirements - __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept< - _BidirectionalIterator>) - __glibcxx_function_requires(_LessThanComparableConcept<_ValueType>) - __glibcxx_requires_sorted(__first, __middle); - __glibcxx_requires_sorted(__middle, __last); - - if (__first == __middle || __middle == __last) - return; - - _DistanceType __len1 = std::distance(__first, __middle); - _DistanceType __len2 = std::distance(__middle, __last); - - _Temporary_buffer<_BidirectionalIterator, _ValueType> __buf(__first, - __last); - if (__buf.begin() == 0) - std::__merge_without_buffer(__first, __middle, __last, __len1, __len2); - else - std::__merge_adaptive(__first, __middle, __last, __len1, __len2, - __buf.begin(), _DistanceType(__buf.size())); - } - - /** - * @brief Merges two sorted ranges in place. - * @ingroup sorting_algorithms - * @param __first An iterator. - * @param __middle Another iterator. - * @param __last Another iterator. - * @param __comp A functor to use for comparisons. - * @return Nothing. - * - * Merges two sorted and consecutive ranges, [__first,__middle) and - * [middle,last), and puts the result in [__first,__last). The output will - * be sorted. The sort is @e stable, that is, for equivalent - * elements in the two ranges, elements from the first range will always - * come before elements from the second. - * - * If enough additional memory is available, this takes (__last-__first)-1 - * comparisons. Otherwise an NlogN algorithm is used, where N is - * distance(__first,__last). - * - * The comparison function should have the same effects on ordering as - * the function used for the initial sort. - */ - template - void - inplace_merge(_BidirectionalIterator __first, - _BidirectionalIterator __middle, - _BidirectionalIterator __last, - _Compare __comp) - { - typedef typename iterator_traits<_BidirectionalIterator>::value_type - _ValueType; - typedef typename iterator_traits<_BidirectionalIterator>::difference_type - _DistanceType; - - // concept requirements - __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept< - _BidirectionalIterator>) - __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, - _ValueType, _ValueType>) - __glibcxx_requires_sorted_pred(__first, __middle, __comp); - __glibcxx_requires_sorted_pred(__middle, __last, __comp); - - if (__first == __middle || __middle == __last) - return; - - const _DistanceType __len1 = std::distance(__first, __middle); - const _DistanceType __len2 = std::distance(__middle, __last); - - _Temporary_buffer<_BidirectionalIterator, _ValueType> __buf(__first, - __last); - if (__buf.begin() == 0) - std::__merge_without_buffer(__first, __middle, __last, __len1, - __len2, __comp); - else - std::__merge_adaptive(__first, __middle, __last, __len1, __len2, - __buf.begin(), _DistanceType(__buf.size()), - __comp); - } - - - /// This is a helper function for the __merge_sort_loop routines. - template - _OutputIterator - __move_merge(_InputIterator1 __first1, _InputIterator1 __last1, - _InputIterator2 __first2, _InputIterator2 __last2, - _OutputIterator __result) - { - while (__first1 != __last1 && __first2 != __last2) - { - if (*__first2 < *__first1) - { - *__result = _GLIBCXX_MOVE(*__first2); - ++__first2; - } - else - { - *__result = _GLIBCXX_MOVE(*__first1); - ++__first1; - } - ++__result; - } - return _GLIBCXX_MOVE3(__first2, __last2, - _GLIBCXX_MOVE3(__first1, __last1, - __result)); - } - - /// This is a helper function for the __merge_sort_loop routines. - template - _OutputIterator - __move_merge(_InputIterator1 __first1, _InputIterator1 __last1, - _InputIterator2 __first2, _InputIterator2 __last2, - _OutputIterator __result, _Compare __comp) - { - while (__first1 != __last1 && __first2 != __last2) - { - if (__comp(*__first2, *__first1)) - { - *__result = _GLIBCXX_MOVE(*__first2); - ++__first2; - } - else - { - *__result = _GLIBCXX_MOVE(*__first1); - ++__first1; - } - ++__result; - } - return _GLIBCXX_MOVE3(__first2, __last2, - _GLIBCXX_MOVE3(__first1, __last1, - __result)); - } - - template - void - __merge_sort_loop(_RandomAccessIterator1 __first, - _RandomAccessIterator1 __last, - _RandomAccessIterator2 __result, - _Distance __step_size) - { - const _Distance __two_step = 2 * __step_size; - - while (__last - __first >= __two_step) - { - __result = std::__move_merge(__first, __first + __step_size, - __first + __step_size, - __first + __two_step, __result); - __first += __two_step; - } - - __step_size = std::min(_Distance(__last - __first), __step_size); - std::__move_merge(__first, __first + __step_size, - __first + __step_size, __last, __result); - } - - template - void - __merge_sort_loop(_RandomAccessIterator1 __first, - _RandomAccessIterator1 __last, - _RandomAccessIterator2 __result, _Distance __step_size, - _Compare __comp) - { - const _Distance __two_step = 2 * __step_size; - - while (__last - __first >= __two_step) - { - __result = std::__move_merge(__first, __first + __step_size, - __first + __step_size, - __first + __two_step, - __result, __comp); - __first += __two_step; - } - __step_size = std::min(_Distance(__last - __first), __step_size); - - std::__move_merge(__first,__first + __step_size, - __first + __step_size, __last, __result, __comp); - } - - template - void - __chunk_insertion_sort(_RandomAccessIterator __first, - _RandomAccessIterator __last, - _Distance __chunk_size) - { - while (__last - __first >= __chunk_size) - { - std::__insertion_sort(__first, __first + __chunk_size); - __first += __chunk_size; - } - std::__insertion_sort(__first, __last); - } - - template - void - __chunk_insertion_sort(_RandomAccessIterator __first, - _RandomAccessIterator __last, - _Distance __chunk_size, _Compare __comp) - { - while (__last - __first >= __chunk_size) - { - std::__insertion_sort(__first, __first + __chunk_size, __comp); - __first += __chunk_size; - } - std::__insertion_sort(__first, __last, __comp); - } - - enum { _S_chunk_size = 7 }; - - template - void - __merge_sort_with_buffer(_RandomAccessIterator __first, - _RandomAccessIterator __last, - _Pointer __buffer) - { - typedef typename iterator_traits<_RandomAccessIterator>::difference_type - _Distance; - - const _Distance __len = __last - __first; - const _Pointer __buffer_last = __buffer + __len; - - _Distance __step_size = _S_chunk_size; - std::__chunk_insertion_sort(__first, __last, __step_size); - - while (__step_size < __len) - { - std::__merge_sort_loop(__first, __last, __buffer, __step_size); - __step_size *= 2; - std::__merge_sort_loop(__buffer, __buffer_last, __first, __step_size); - __step_size *= 2; - } - } - - template - void - __merge_sort_with_buffer(_RandomAccessIterator __first, - _RandomAccessIterator __last, - _Pointer __buffer, _Compare __comp) - { - typedef typename iterator_traits<_RandomAccessIterator>::difference_type - _Distance; - - const _Distance __len = __last - __first; - const _Pointer __buffer_last = __buffer + __len; - - _Distance __step_size = _S_chunk_size; - std::__chunk_insertion_sort(__first, __last, __step_size, __comp); - - while (__step_size < __len) - { - std::__merge_sort_loop(__first, __last, __buffer, - __step_size, __comp); - __step_size *= 2; - std::__merge_sort_loop(__buffer, __buffer_last, __first, - __step_size, __comp); - __step_size *= 2; - } - } - - template - void - __stable_sort_adaptive(_RandomAccessIterator __first, - _RandomAccessIterator __last, - _Pointer __buffer, _Distance __buffer_size) - { - const _Distance __len = (__last - __first + 1) / 2; - const _RandomAccessIterator __middle = __first + __len; - if (__len > __buffer_size) - { - std::__stable_sort_adaptive(__first, __middle, - __buffer, __buffer_size); - std::__stable_sort_adaptive(__middle, __last, - __buffer, __buffer_size); - } - else - { - std::__merge_sort_with_buffer(__first, __middle, __buffer); - std::__merge_sort_with_buffer(__middle, __last, __buffer); - } - std::__merge_adaptive(__first, __middle, __last, - _Distance(__middle - __first), - _Distance(__last - __middle), - __buffer, __buffer_size); - } - - template - void - __stable_sort_adaptive(_RandomAccessIterator __first, - _RandomAccessIterator __last, - _Pointer __buffer, _Distance __buffer_size, - _Compare __comp) - { - const _Distance __len = (__last - __first + 1) / 2; - const _RandomAccessIterator __middle = __first + __len; - if (__len > __buffer_size) - { - std::__stable_sort_adaptive(__first, __middle, __buffer, - __buffer_size, __comp); - std::__stable_sort_adaptive(__middle, __last, __buffer, - __buffer_size, __comp); - } - else - { - std::__merge_sort_with_buffer(__first, __middle, __buffer, __comp); - std::__merge_sort_with_buffer(__middle, __last, __buffer, __comp); - } - std::__merge_adaptive(__first, __middle, __last, - _Distance(__middle - __first), - _Distance(__last - __middle), - __buffer, __buffer_size, - __comp); - } - - /// This is a helper function for the stable sorting routines. - template - void - __inplace_stable_sort(_RandomAccessIterator __first, - _RandomAccessIterator __last) - { - if (__last - __first < 15) - { - std::__insertion_sort(__first, __last); - return; - } - _RandomAccessIterator __middle = __first + (__last - __first) / 2; - std::__inplace_stable_sort(__first, __middle); - std::__inplace_stable_sort(__middle, __last); - std::__merge_without_buffer(__first, __middle, __last, - __middle - __first, - __last - __middle); - } - - /// This is a helper function for the stable sorting routines. - template - void - __inplace_stable_sort(_RandomAccessIterator __first, - _RandomAccessIterator __last, _Compare __comp) - { - if (__last - __first < 15) - { - std::__insertion_sort(__first, __last, __comp); - return; - } - _RandomAccessIterator __middle = __first + (__last - __first) / 2; - std::__inplace_stable_sort(__first, __middle, __comp); - std::__inplace_stable_sort(__middle, __last, __comp); - std::__merge_without_buffer(__first, __middle, __last, - __middle - __first, - __last - __middle, - __comp); - } - - // stable_sort - - // Set algorithms: includes, set_union, set_intersection, set_difference, - // set_symmetric_difference. All of these algorithms have the precondition - // that their input ranges are sorted and the postcondition that their output - // ranges are sorted. - - /** - * @brief Determines whether all elements of a sequence exists in a range. - * @param __first1 Start of search range. - * @param __last1 End of search range. - * @param __first2 Start of sequence - * @param __last2 End of sequence. - * @return True if each element in [__first2,__last2) is contained in order - * within [__first1,__last1). False otherwise. - * @ingroup set_algorithms - * - * This operation expects both [__first1,__last1) and - * [__first2,__last2) to be sorted. Searches for the presence of - * each element in [__first2,__last2) within [__first1,__last1). - * The iterators over each range only move forward, so this is a - * linear algorithm. If an element in [__first2,__last2) is not - * found before the search iterator reaches @p __last2, false is - * returned. - */ - template - bool - includes(_InputIterator1 __first1, _InputIterator1 __last1, - _InputIterator2 __first2, _InputIterator2 __last2) - { - typedef typename iterator_traits<_InputIterator1>::value_type - _ValueType1; - typedef typename iterator_traits<_InputIterator2>::value_type - _ValueType2; - - // concept requirements - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>) - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>) - __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>) - __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>) - __glibcxx_requires_sorted_set(__first1, __last1, __first2); - __glibcxx_requires_sorted_set(__first2, __last2, __first1); - - while (__first1 != __last1 && __first2 != __last2) - if (*__first2 < *__first1) - return false; - else if(*__first1 < *__first2) - ++__first1; - else - ++__first1, ++__first2; - - return __first2 == __last2; - } - - /** - * @brief Determines whether all elements of a sequence exists in a range - * using comparison. - * @ingroup set_algorithms - * @param __first1 Start of search range. - * @param __last1 End of search range. - * @param __first2 Start of sequence - * @param __last2 End of sequence. - * @param __comp Comparison function to use. - * @return True if each element in [__first2,__last2) is contained - * in order within [__first1,__last1) according to comp. False - * otherwise. @ingroup set_algorithms - * - * This operation expects both [__first1,__last1) and - * [__first2,__last2) to be sorted. Searches for the presence of - * each element in [__first2,__last2) within [__first1,__last1), - * using comp to decide. The iterators over each range only move - * forward, so this is a linear algorithm. If an element in - * [__first2,__last2) is not found before the search iterator - * reaches @p __last2, false is returned. - */ - template - bool - includes(_InputIterator1 __first1, _InputIterator1 __last1, - _InputIterator2 __first2, _InputIterator2 __last2, - _Compare __comp) - { - typedef typename iterator_traits<_InputIterator1>::value_type - _ValueType1; - typedef typename iterator_traits<_InputIterator2>::value_type - _ValueType2; - - // concept requirements - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>) - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>) - __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, - _ValueType1, _ValueType2>) - __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, - _ValueType2, _ValueType1>) - __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp); - __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp); - - while (__first1 != __last1 && __first2 != __last2) - if (__comp(*__first2, *__first1)) - return false; - else if(__comp(*__first1, *__first2)) - ++__first1; - else - ++__first1, ++__first2; - - return __first2 == __last2; - } - - // nth_element - // merge - // set_difference - // set_intersection - // set_union - // stable_sort - // set_symmetric_difference - // min_element - // max_element - - /** - * @brief Permute range into the next @e dictionary ordering. - * @ingroup sorting_algorithms - * @param __first Start of range. - * @param __last End of range. - * @return False if wrapped to first permutation, true otherwise. - * - * Treats all permutations of the range as a set of @e dictionary sorted - * sequences. Permutes the current sequence into the next one of this set. - * Returns true if there are more sequences to generate. If the sequence - * is the largest of the set, the smallest is generated and false returned. - */ - template - bool - next_permutation(_BidirectionalIterator __first, - _BidirectionalIterator __last) - { - // concept requirements - __glibcxx_function_requires(_BidirectionalIteratorConcept< - _BidirectionalIterator>) - __glibcxx_function_requires(_LessThanComparableConcept< - typename iterator_traits<_BidirectionalIterator>::value_type>) - __glibcxx_requires_valid_range(__first, __last); - - if (__first == __last) - return false; - _BidirectionalIterator __i = __first; - ++__i; - if (__i == __last) - return false; - __i = __last; - --__i; - - for(;;) - { - _BidirectionalIterator __ii = __i; - --__i; - if (*__i < *__ii) - { - _BidirectionalIterator __j = __last; - while (!(*__i < *--__j)) - {} - std::iter_swap(__i, __j); - std::reverse(__ii, __last); - return true; - } - if (__i == __first) - { - std::reverse(__first, __last); - return false; - } - } - } - - /** - * @brief Permute range into the next @e dictionary ordering using - * comparison functor. - * @ingroup sorting_algorithms - * @param __first Start of range. - * @param __last End of range. - * @param __comp A comparison functor. - * @return False if wrapped to first permutation, true otherwise. - * - * Treats all permutations of the range [__first,__last) as a set of - * @e dictionary sorted sequences ordered by @p __comp. Permutes the current - * sequence into the next one of this set. Returns true if there are more - * sequences to generate. If the sequence is the largest of the set, the - * smallest is generated and false returned. - */ - template - bool - next_permutation(_BidirectionalIterator __first, - _BidirectionalIterator __last, _Compare __comp) - { - // concept requirements - __glibcxx_function_requires(_BidirectionalIteratorConcept< - _BidirectionalIterator>) - __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, - typename iterator_traits<_BidirectionalIterator>::value_type, - typename iterator_traits<_BidirectionalIterator>::value_type>) - __glibcxx_requires_valid_range(__first, __last); - - if (__first == __last) - return false; - _BidirectionalIterator __i = __first; - ++__i; - if (__i == __last) - return false; - __i = __last; - --__i; - - for(;;) - { - _BidirectionalIterator __ii = __i; - --__i; - if (__comp(*__i, *__ii)) - { - _BidirectionalIterator __j = __last; - while (!bool(__comp(*__i, *--__j))) - {} - std::iter_swap(__i, __j); - std::reverse(__ii, __last); - return true; - } - if (__i == __first) - { - std::reverse(__first, __last); - return false; - } - } - } - - /** - * @brief Permute range into the previous @e dictionary ordering. - * @ingroup sorting_algorithms - * @param __first Start of range. - * @param __last End of range. - * @return False if wrapped to last permutation, true otherwise. - * - * Treats all permutations of the range as a set of @e dictionary sorted - * sequences. Permutes the current sequence into the previous one of this - * set. Returns true if there are more sequences to generate. If the - * sequence is the smallest of the set, the largest is generated and false - * returned. - */ - template - bool - prev_permutation(_BidirectionalIterator __first, - _BidirectionalIterator __last) - { - // concept requirements - __glibcxx_function_requires(_BidirectionalIteratorConcept< - _BidirectionalIterator>) - __glibcxx_function_requires(_LessThanComparableConcept< - typename iterator_traits<_BidirectionalIterator>::value_type>) - __glibcxx_requires_valid_range(__first, __last); - - if (__first == __last) - return false; - _BidirectionalIterator __i = __first; - ++__i; - if (__i == __last) - return false; - __i = __last; - --__i; - - for(;;) - { - _BidirectionalIterator __ii = __i; - --__i; - if (*__ii < *__i) - { - _BidirectionalIterator __j = __last; - while (!(*--__j < *__i)) - {} - std::iter_swap(__i, __j); - std::reverse(__ii, __last); - return true; - } - if (__i == __first) - { - std::reverse(__first, __last); - return false; - } - } - } - - /** - * @brief Permute range into the previous @e dictionary ordering using - * comparison functor. - * @ingroup sorting_algorithms - * @param __first Start of range. - * @param __last End of range. - * @param __comp A comparison functor. - * @return False if wrapped to last permutation, true otherwise. - * - * Treats all permutations of the range [__first,__last) as a set of - * @e dictionary sorted sequences ordered by @p __comp. Permutes the current - * sequence into the previous one of this set. Returns true if there are - * more sequences to generate. If the sequence is the smallest of the set, - * the largest is generated and false returned. - */ - template - bool - prev_permutation(_BidirectionalIterator __first, - _BidirectionalIterator __last, _Compare __comp) - { - // concept requirements - __glibcxx_function_requires(_BidirectionalIteratorConcept< - _BidirectionalIterator>) - __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, - typename iterator_traits<_BidirectionalIterator>::value_type, - typename iterator_traits<_BidirectionalIterator>::value_type>) - __glibcxx_requires_valid_range(__first, __last); - - if (__first == __last) - return false; - _BidirectionalIterator __i = __first; - ++__i; - if (__i == __last) - return false; - __i = __last; - --__i; - - for(;;) - { - _BidirectionalIterator __ii = __i; - --__i; - if (__comp(*__ii, *__i)) - { - _BidirectionalIterator __j = __last; - while (!bool(__comp(*--__j, *__i))) - {} - std::iter_swap(__i, __j); - std::reverse(__ii, __last); - return true; - } - if (__i == __first) - { - std::reverse(__first, __last); - return false; - } - } - } - - // replace - // replace_if - - /** - * @brief Copy a sequence, replacing each element of one value with another - * value. - * @param __first An input iterator. - * @param __last An input iterator. - * @param __result An output iterator. - * @param __old_value The value to be replaced. - * @param __new_value The replacement value. - * @return The end of the output sequence, @p result+(last-first). - * - * Copies each element in the input range @p [__first,__last) to the - * output range @p [__result,__result+(__last-__first)) replacing elements - * equal to @p __old_value with @p __new_value. - */ - template - _OutputIterator - replace_copy(_InputIterator __first, _InputIterator __last, - _OutputIterator __result, - const _Tp& __old_value, const _Tp& __new_value) - { - // concept requirements - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>) - __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, - typename iterator_traits<_InputIterator>::value_type>) - __glibcxx_function_requires(_EqualOpConcept< - typename iterator_traits<_InputIterator>::value_type, _Tp>) - __glibcxx_requires_valid_range(__first, __last); - - for (; __first != __last; ++__first, ++__result) - if (*__first == __old_value) - *__result = __new_value; - else - *__result = *__first; - return __result; - } - - /** - * @brief Copy a sequence, replacing each value for which a predicate - * returns true with another value. - * @ingroup mutating_algorithms - * @param __first An input iterator. - * @param __last An input iterator. - * @param __result An output iterator. - * @param __pred A predicate. - * @param __new_value The replacement value. - * @return The end of the output sequence, @p __result+(__last-__first). - * - * Copies each element in the range @p [__first,__last) to the range - * @p [__result,__result+(__last-__first)) replacing elements for which - * @p __pred returns true with @p __new_value. - */ - template - _OutputIterator - replace_copy_if(_InputIterator __first, _InputIterator __last, - _OutputIterator __result, - _Predicate __pred, const _Tp& __new_value) - { - // concept requirements - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>) - __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, - typename iterator_traits<_InputIterator>::value_type>) - __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate, - typename iterator_traits<_InputIterator>::value_type>) - __glibcxx_requires_valid_range(__first, __last); - - for (; __first != __last; ++__first, ++__result) - if (__pred(*__first)) - *__result = __new_value; - else - *__result = *__first; - return __result; - } - -#if __cplusplus >= 201103L - /** - * @brief Determines whether the elements of a sequence are sorted. - * @ingroup sorting_algorithms - * @param __first An iterator. - * @param __last Another iterator. - * @return True if the elements are sorted, false otherwise. - */ - template - inline bool - is_sorted(_ForwardIterator __first, _ForwardIterator __last) - { return std::is_sorted_until(__first, __last) == __last; } - - /** - * @brief Determines whether the elements of a sequence are sorted - * according to a comparison functor. - * @ingroup sorting_algorithms - * @param __first An iterator. - * @param __last Another iterator. - * @param __comp A comparison functor. - * @return True if the elements are sorted, false otherwise. - */ - template - inline bool - is_sorted(_ForwardIterator __first, _ForwardIterator __last, - _Compare __comp) - { return std::is_sorted_until(__first, __last, __comp) == __last; } - - /** - * @brief Determines the end of a sorted sequence. - * @ingroup sorting_algorithms - * @param __first An iterator. - * @param __last Another iterator. - * @return An iterator pointing to the last iterator i in [__first, __last) - * for which the range [__first, i) is sorted. - */ - template - _ForwardIterator - is_sorted_until(_ForwardIterator __first, _ForwardIterator __last) - { - // concept requirements - __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>) - __glibcxx_function_requires(_LessThanComparableConcept< - typename iterator_traits<_ForwardIterator>::value_type>) - __glibcxx_requires_valid_range(__first, __last); - - if (__first == __last) - return __last; - - _ForwardIterator __next = __first; - for (++__next; __next != __last; __first = __next, ++__next) - if (*__next < *__first) - return __next; - return __next; - } - - /** - * @brief Determines the end of a sorted sequence using comparison functor. - * @ingroup sorting_algorithms - * @param __first An iterator. - * @param __last Another iterator. - * @param __comp A comparison functor. - * @return An iterator pointing to the last iterator i in [__first, __last) - * for which the range [__first, i) is sorted. - */ - template - _ForwardIterator - is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, - _Compare __comp) - { - // concept requirements - __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>) - __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, - typename iterator_traits<_ForwardIterator>::value_type, - typename iterator_traits<_ForwardIterator>::value_type>) - __glibcxx_requires_valid_range(__first, __last); - - if (__first == __last) - return __last; - - _ForwardIterator __next = __first; - for (++__next; __next != __last; __first = __next, ++__next) - if (__comp(*__next, *__first)) - return __next; - return __next; - } - - /** - * @brief Determines min and max at once as an ordered pair. - * @ingroup sorting_algorithms - * @param __a A thing of arbitrary type. - * @param __b Another thing of arbitrary type. - * @return A pair(__b, __a) if __b is smaller than __a, pair(__a, - * __b) otherwise. - */ - template - inline pair - minmax(const _Tp& __a, const _Tp& __b) - { - // concept requirements - __glibcxx_function_requires(_LessThanComparableConcept<_Tp>) - - return __b < __a ? pair(__b, __a) - : pair(__a, __b); - } - - /** - * @brief Determines min and max at once as an ordered pair. - * @ingroup sorting_algorithms - * @param __a A thing of arbitrary type. - * @param __b Another thing of arbitrary type. - * @param __comp A @link comparison_functors comparison functor @endlink. - * @return A pair(__b, __a) if __b is smaller than __a, pair(__a, - * __b) otherwise. - */ - template - inline pair - minmax(const _Tp& __a, const _Tp& __b, _Compare __comp) - { - return __comp(__b, __a) ? pair(__b, __a) - : pair(__a, __b); - } - - /** - * @brief Return a pair of iterators pointing to the minimum and maximum - * elements in a range. - * @ingroup sorting_algorithms - * @param __first Start of range. - * @param __last End of range. - * @return make_pair(m, M), where m is the first iterator i in - * [__first, __last) such that no other element in the range is - * smaller, and where M is the last iterator i in [__first, __last) - * such that no other element in the range is larger. - */ - template - pair<_ForwardIterator, _ForwardIterator> - minmax_element(_ForwardIterator __first, _ForwardIterator __last) - { - // concept requirements - __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>) - __glibcxx_function_requires(_LessThanComparableConcept< - typename iterator_traits<_ForwardIterator>::value_type>) - __glibcxx_requires_valid_range(__first, __last); - - _ForwardIterator __next = __first; - if (__first == __last - || ++__next == __last) - return std::make_pair(__first, __first); - - _ForwardIterator __min, __max; - if (*__next < *__first) - { - __min = __next; - __max = __first; - } - else - { - __min = __first; - __max = __next; - } - - __first = __next; - ++__first; - - while (__first != __last) - { - __next = __first; - if (++__next == __last) - { - if (*__first < *__min) - __min = __first; - else if (!(*__first < *__max)) - __max = __first; - break; - } - - if (*__next < *__first) - { - if (*__next < *__min) - __min = __next; - if (!(*__first < *__max)) - __max = __first; - } - else - { - if (*__first < *__min) - __min = __first; - if (!(*__next < *__max)) - __max = __next; - } - - __first = __next; - ++__first; - } - - return std::make_pair(__min, __max); - } - - /** - * @brief Return a pair of iterators pointing to the minimum and maximum - * elements in a range. - * @ingroup sorting_algorithms - * @param __first Start of range. - * @param __last End of range. - * @param __comp Comparison functor. - * @return make_pair(m, M), where m is the first iterator i in - * [__first, __last) such that no other element in the range is - * smaller, and where M is the last iterator i in [__first, __last) - * such that no other element in the range is larger. - */ - template - pair<_ForwardIterator, _ForwardIterator> - minmax_element(_ForwardIterator __first, _ForwardIterator __last, - _Compare __comp) - { - // concept requirements - __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>) - __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, - typename iterator_traits<_ForwardIterator>::value_type, - typename iterator_traits<_ForwardIterator>::value_type>) - __glibcxx_requires_valid_range(__first, __last); - - _ForwardIterator __next = __first; - if (__first == __last - || ++__next == __last) - return std::make_pair(__first, __first); - - _ForwardIterator __min, __max; - if (__comp(*__next, *__first)) - { - __min = __next; - __max = __first; - } - else - { - __min = __first; - __max = __next; - } - - __first = __next; - ++__first; - - while (__first != __last) - { - __next = __first; - if (++__next == __last) - { - if (__comp(*__first, *__min)) - __min = __first; - else if (!__comp(*__first, *__max)) - __max = __first; - break; - } - - if (__comp(*__next, *__first)) - { - if (__comp(*__next, *__min)) - __min = __next; - if (!__comp(*__first, *__max)) - __max = __first; - } - else - { - if (__comp(*__first, *__min)) - __min = __first; - if (!__comp(*__next, *__max)) - __max = __next; - } - - __first = __next; - ++__first; - } - - return std::make_pair(__min, __max); - } - - // N2722 + DR 915. - template - inline _Tp - min(initializer_list<_Tp> __l) - { return *std::min_element(__l.begin(), __l.end()); } - - template - inline _Tp - min(initializer_list<_Tp> __l, _Compare __comp) - { return *std::min_element(__l.begin(), __l.end(), __comp); } - - template - inline _Tp - max(initializer_list<_Tp> __l) - { return *std::max_element(__l.begin(), __l.end()); } - - template - inline _Tp - max(initializer_list<_Tp> __l, _Compare __comp) - { return *std::max_element(__l.begin(), __l.end(), __comp); } - - template - inline pair<_Tp, _Tp> - minmax(initializer_list<_Tp> __l) - { - pair __p = - std::minmax_element(__l.begin(), __l.end()); - return std::make_pair(*__p.first, *__p.second); - } - - template - inline pair<_Tp, _Tp> - minmax(initializer_list<_Tp> __l, _Compare __comp) - { - pair __p = - std::minmax_element(__l.begin(), __l.end(), __comp); - return std::make_pair(*__p.first, *__p.second); - } - - /** - * @brief Checks whether a permutation of the second sequence is equal - * to the first sequence. - * @ingroup non_mutating_algorithms - * @param __first1 Start of first range. - * @param __last1 End of first range. - * @param __first2 Start of second range. - * @return true if there exists a permutation of the elements in the range - * [__first2, __first2 + (__last1 - __first1)), beginning with - * ForwardIterator2 begin, such that equal(__first1, __last1, begin) - * returns true; otherwise, returns false. - */ - template - bool - is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, - _ForwardIterator2 __first2) - { - // Efficiently compare identical prefixes: O(N) if sequences - // have the same elements in the same order. - for (; __first1 != __last1; ++__first1, ++__first2) - if (!(*__first1 == *__first2)) - break; - - if (__first1 == __last1) - return true; - - // Establish __last2 assuming equal ranges by iterating over the - // rest of the list. - _ForwardIterator2 __last2 = __first2; - std::advance(__last2, std::distance(__first1, __last1)); - for (_ForwardIterator1 __scan = __first1; __scan != __last1; ++__scan) - { - if (__scan != _GLIBCXX_STD_A::find(__first1, __scan, *__scan)) - continue; // We've seen this one before. - - auto __matches = std::count(__first2, __last2, *__scan); - if (0 == __matches - || std::count(__scan, __last1, *__scan) != __matches) - return false; - } - return true; - } - - /** - * @brief Checks whether a permutation of the second sequence is equal - * to the first sequence. - * @ingroup non_mutating_algorithms - * @param __first1 Start of first range. - * @param __last1 End of first range. - * @param __first2 Start of second range. - * @param __pred A binary predicate. - * @return true if there exists a permutation of the elements in - * the range [__first2, __first2 + (__last1 - __first1)), - * beginning with ForwardIterator2 begin, such that - * equal(__first1, __last1, __begin, __pred) returns true; - * otherwise, returns false. - */ - template - bool - is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, - _ForwardIterator2 __first2, _BinaryPredicate __pred) - { - // Efficiently compare identical prefixes: O(N) if sequences - // have the same elements in the same order. - for (; __first1 != __last1; ++__first1, ++__first2) - if (!bool(__pred(*__first1, *__first2))) - break; - - if (__first1 == __last1) - return true; - - // Establish __last2 assuming equal ranges by iterating over the - // rest of the list. - _ForwardIterator2 __last2 = __first2; - std::advance(__last2, std::distance(__first1, __last1)); - for (_ForwardIterator1 __scan = __first1; __scan != __last1; ++__scan) - { - using std::placeholders::_1; - - if (__scan != _GLIBCXX_STD_A::find_if(__first1, __scan, - std::bind(__pred, _1, *__scan))) - continue; // We've seen this one before. - - auto __matches = std::count_if(__first2, __last2, - std::bind(__pred, _1, *__scan)); - if (0 == __matches - || std::count_if(__scan, __last1, - std::bind(__pred, _1, *__scan)) != __matches) - return false; - } - return true; - } - -#ifdef _GLIBCXX_USE_C99_STDINT_TR1 - /** - * @brief Shuffle the elements of a sequence using a uniform random - * number generator. - * @ingroup mutating_algorithms - * @param __first A forward iterator. - * @param __last A forward iterator. - * @param __g A UniformRandomNumberGenerator (26.5.1.3). - * @return Nothing. - * - * Reorders the elements in the range @p [__first,__last) using @p __g to - * provide random numbers. - */ - template - void - shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last, - _UniformRandomNumberGenerator&& __g) - { - // concept requirements - __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept< - _RandomAccessIterator>) - __glibcxx_requires_valid_range(__first, __last); - - if (__first == __last) - return; - - typedef typename iterator_traits<_RandomAccessIterator>::difference_type - _DistanceType; - - typedef typename std::make_unsigned<_DistanceType>::type __ud_type; - typedef typename std::uniform_int_distribution<__ud_type> __distr_type; - typedef typename __distr_type::param_type __p_type; - __distr_type __d; - - for (_RandomAccessIterator __i = __first + 1; __i != __last; ++__i) - std::iter_swap(__i, __first + __d(__g, __p_type(0, __i - __first))); - } -#endif - -#endif // C++11 - -_GLIBCXX_END_NAMESPACE_VERSION - -_GLIBCXX_BEGIN_NAMESPACE_ALGO - - /** - * @brief Apply a function to every element of a sequence. - * @ingroup non_mutating_algorithms - * @param __first An input iterator. - * @param __last An input iterator. - * @param __f A unary function object. - * @return @p __f (std::move(@p __f) in C++0x). - * - * Applies the function object @p __f to each element in the range - * @p [first,last). @p __f must not modify the order of the sequence. - * If @p __f has a return value it is ignored. - */ - template - _Function - for_each(_InputIterator __first, _InputIterator __last, _Function __f) - { - // concept requirements - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>) - __glibcxx_requires_valid_range(__first, __last); - for (; __first != __last; ++__first) - __f(*__first); - return _GLIBCXX_MOVE(__f); - } - - /** - * @brief Find the first occurrence of a value in a sequence. - * @ingroup non_mutating_algorithms - * @param __first An input iterator. - * @param __last An input iterator. - * @param __val The value to find. - * @return The first iterator @c i in the range @p [__first,__last) - * such that @c *i == @p __val, or @p __last if no such iterator exists. - */ - template - inline _InputIterator - find(_InputIterator __first, _InputIterator __last, - const _Tp& __val) - { - // concept requirements - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>) - __glibcxx_function_requires(_EqualOpConcept< - typename iterator_traits<_InputIterator>::value_type, _Tp>) - __glibcxx_requires_valid_range(__first, __last); - return std::__find(__first, __last, __val, - std::__iterator_category(__first)); - } - - /** - * @brief Find the first element in a sequence for which a - * predicate is true. - * @ingroup non_mutating_algorithms - * @param __first An input iterator. - * @param __last An input iterator. - * @param __pred A predicate. - * @return The first iterator @c i in the range @p [__first,__last) - * such that @p __pred(*i) is true, or @p __last if no such iterator exists. - */ - template - inline _InputIterator - find_if(_InputIterator __first, _InputIterator __last, - _Predicate __pred) - { - // concept requirements - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>) - __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate, - typename iterator_traits<_InputIterator>::value_type>) - __glibcxx_requires_valid_range(__first, __last); - return std::__find_if(__first, __last, __pred, - std::__iterator_category(__first)); - } - - /** - * @brief Find element from a set in a sequence. - * @ingroup non_mutating_algorithms - * @param __first1 Start of range to search. - * @param __last1 End of range to search. - * @param __first2 Start of match candidates. - * @param __last2 End of match candidates. - * @return The first iterator @c i in the range - * @p [__first1,__last1) such that @c *i == @p *(i2) such that i2 is an - * iterator in [__first2,__last2), or @p __last1 if no such iterator exists. - * - * Searches the range @p [__first1,__last1) for an element that is - * equal to some element in the range [__first2,__last2). If - * found, returns an iterator in the range [__first1,__last1), - * otherwise returns @p __last1. - */ - template - _InputIterator - find_first_of(_InputIterator __first1, _InputIterator __last1, - _ForwardIterator __first2, _ForwardIterator __last2) - { - // concept requirements - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>) - __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>) - __glibcxx_function_requires(_EqualOpConcept< - typename iterator_traits<_InputIterator>::value_type, - typename iterator_traits<_ForwardIterator>::value_type>) - __glibcxx_requires_valid_range(__first1, __last1); - __glibcxx_requires_valid_range(__first2, __last2); - - for (; __first1 != __last1; ++__first1) - for (_ForwardIterator __iter = __first2; __iter != __last2; ++__iter) - if (*__first1 == *__iter) - return __first1; - return __last1; - } - - /** - * @brief Find element from a set in a sequence using a predicate. - * @ingroup non_mutating_algorithms - * @param __first1 Start of range to search. - * @param __last1 End of range to search. - * @param __first2 Start of match candidates. - * @param __last2 End of match candidates. - * @param __comp Predicate to use. - * @return The first iterator @c i in the range - * @p [__first1,__last1) such that @c comp(*i, @p *(i2)) is true - * and i2 is an iterator in [__first2,__last2), or @p __last1 if no - * such iterator exists. - * - - * Searches the range @p [__first1,__last1) for an element that is - * equal to some element in the range [__first2,__last2). If - * found, returns an iterator in the range [__first1,__last1), - * otherwise returns @p __last1. - */ - template - _InputIterator - find_first_of(_InputIterator __first1, _InputIterator __last1, - _ForwardIterator __first2, _ForwardIterator __last2, - _BinaryPredicate __comp) - { - // concept requirements - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>) - __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>) - __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate, - typename iterator_traits<_InputIterator>::value_type, - typename iterator_traits<_ForwardIterator>::value_type>) - __glibcxx_requires_valid_range(__first1, __last1); - __glibcxx_requires_valid_range(__first2, __last2); - - for (; __first1 != __last1; ++__first1) - for (_ForwardIterator __iter = __first2; __iter != __last2; ++__iter) - if (__comp(*__first1, *__iter)) - return __first1; - return __last1; - } - - /** - * @brief Find two adjacent values in a sequence that are equal. - * @ingroup non_mutating_algorithms - * @param __first A forward iterator. - * @param __last A forward iterator. - * @return The first iterator @c i such that @c i and @c i+1 are both - * valid iterators in @p [__first,__last) and such that @c *i == @c *(i+1), - * or @p __last if no such iterator exists. - */ - template - _ForwardIterator - adjacent_find(_ForwardIterator __first, _ForwardIterator __last) - { - // concept requirements - __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>) - __glibcxx_function_requires(_EqualityComparableConcept< - typename iterator_traits<_ForwardIterator>::value_type>) - __glibcxx_requires_valid_range(__first, __last); - if (__first == __last) - return __last; - _ForwardIterator __next = __first; - while(++__next != __last) - { - if (*__first == *__next) - return __first; - __first = __next; - } - return __last; - } - - /** - * @brief Find two adjacent values in a sequence using a predicate. - * @ingroup non_mutating_algorithms - * @param __first A forward iterator. - * @param __last A forward iterator. - * @param __binary_pred A binary predicate. - * @return The first iterator @c i such that @c i and @c i+1 are both - * valid iterators in @p [__first,__last) and such that - * @p __binary_pred(*i,*(i+1)) is true, or @p __last if no such iterator - * exists. - */ - template - _ForwardIterator - adjacent_find(_ForwardIterator __first, _ForwardIterator __last, - _BinaryPredicate __binary_pred) - { - // concept requirements - __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>) - __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate, - typename iterator_traits<_ForwardIterator>::value_type, - typename iterator_traits<_ForwardIterator>::value_type>) - __glibcxx_requires_valid_range(__first, __last); - if (__first == __last) - return __last; - _ForwardIterator __next = __first; - while(++__next != __last) - { - if (__binary_pred(*__first, *__next)) - return __first; - __first = __next; - } - return __last; - } - - /** - * @brief Count the number of copies of a value in a sequence. - * @ingroup non_mutating_algorithms - * @param __first An input iterator. - * @param __last An input iterator. - * @param __value The value to be counted. - * @return The number of iterators @c i in the range @p [__first,__last) - * for which @c *i == @p __value - */ - template - typename iterator_traits<_InputIterator>::difference_type - count(_InputIterator __first, _InputIterator __last, const _Tp& __value) - { - // concept requirements - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>) - __glibcxx_function_requires(_EqualOpConcept< - typename iterator_traits<_InputIterator>::value_type, _Tp>) - __glibcxx_requires_valid_range(__first, __last); - typename iterator_traits<_InputIterator>::difference_type __n = 0; - for (; __first != __last; ++__first) - if (*__first == __value) - ++__n; - return __n; - } - - /** - * @brief Count the elements of a sequence for which a predicate is true. - * @ingroup non_mutating_algorithms - * @param __first An input iterator. - * @param __last An input iterator. - * @param __pred A predicate. - * @return The number of iterators @c i in the range @p [__first,__last) - * for which @p __pred(*i) is true. - */ - template - typename iterator_traits<_InputIterator>::difference_type - count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred) - { - // concept requirements - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>) - __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate, - typename iterator_traits<_InputIterator>::value_type>) - __glibcxx_requires_valid_range(__first, __last); - typename iterator_traits<_InputIterator>::difference_type __n = 0; - for (; __first != __last; ++__first) - if (__pred(*__first)) - ++__n; - return __n; - } - - /** - * @brief Search a sequence for a matching sub-sequence. - * @ingroup non_mutating_algorithms - * @param __first1 A forward iterator. - * @param __last1 A forward iterator. - * @param __first2 A forward iterator. - * @param __last2 A forward iterator. - * @return The first iterator @c i in the range @p - * [__first1,__last1-(__last2-__first2)) such that @c *(i+N) == @p - * *(__first2+N) for each @c N in the range @p - * [0,__last2-__first2), or @p __last1 if no such iterator exists. - * - * Searches the range @p [__first1,__last1) for a sub-sequence that - * compares equal value-by-value with the sequence given by @p - * [__first2,__last2) and returns an iterator to the first element - * of the sub-sequence, or @p __last1 if the sub-sequence is not - * found. - * - * Because the sub-sequence must lie completely within the range @p - * [__first1,__last1) it must start at a position less than @p - * __last1-(__last2-__first2) where @p __last2-__first2 is the - * length of the sub-sequence. - * - * This means that the returned iterator @c i will be in the range - * @p [__first1,__last1-(__last2-__first2)) - */ - template - _ForwardIterator1 - search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, - _ForwardIterator2 __first2, _ForwardIterator2 __last2) - { - // concept requirements - __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>) - __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>) - __glibcxx_function_requires(_EqualOpConcept< - typename iterator_traits<_ForwardIterator1>::value_type, - typename iterator_traits<_ForwardIterator2>::value_type>) - __glibcxx_requires_valid_range(__first1, __last1); - __glibcxx_requires_valid_range(__first2, __last2); - - // Test for empty ranges - if (__first1 == __last1 || __first2 == __last2) - return __first1; - - // Test for a pattern of length 1. - _ForwardIterator2 __p1(__first2); - if (++__p1 == __last2) - return _GLIBCXX_STD_A::find(__first1, __last1, *__first2); - - // General case. - _ForwardIterator2 __p; - _ForwardIterator1 __current = __first1; - - for (;;) - { - __first1 = _GLIBCXX_STD_A::find(__first1, __last1, *__first2); - if (__first1 == __last1) - return __last1; - - __p = __p1; - __current = __first1; - if (++__current == __last1) - return __last1; - - while (*__current == *__p) - { - if (++__p == __last2) - return __first1; - if (++__current == __last1) - return __last1; - } - ++__first1; - } - return __first1; - } - - /** - * @brief Search a sequence for a matching sub-sequence using a predicate. - * @ingroup non_mutating_algorithms - * @param __first1 A forward iterator. - * @param __last1 A forward iterator. - * @param __first2 A forward iterator. - * @param __last2 A forward iterator. - * @param __predicate A binary predicate. - * @return The first iterator @c i in the range - * @p [__first1,__last1-(__last2-__first2)) such that - * @p __predicate(*(i+N),*(__first2+N)) is true for each @c N in the range - * @p [0,__last2-__first2), or @p __last1 if no such iterator exists. - * - * Searches the range @p [__first1,__last1) for a sub-sequence that - * compares equal value-by-value with the sequence given by @p - * [__first2,__last2), using @p __predicate to determine equality, - * and returns an iterator to the first element of the - * sub-sequence, or @p __last1 if no such iterator exists. - * - * @see search(_ForwardIter1, _ForwardIter1, _ForwardIter2, _ForwardIter2) - */ - template - _ForwardIterator1 - search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, - _ForwardIterator2 __first2, _ForwardIterator2 __last2, - _BinaryPredicate __predicate) - { - // concept requirements - __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>) - __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>) - __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate, - typename iterator_traits<_ForwardIterator1>::value_type, - typename iterator_traits<_ForwardIterator2>::value_type>) - __glibcxx_requires_valid_range(__first1, __last1); - __glibcxx_requires_valid_range(__first2, __last2); - - // Test for empty ranges - if (__first1 == __last1 || __first2 == __last2) - return __first1; - - // Test for a pattern of length 1. - _ForwardIterator2 __p1(__first2); - if (++__p1 == __last2) - { - while (__first1 != __last1 - && !bool(__predicate(*__first1, *__first2))) - ++__first1; - return __first1; - } - - // General case. - _ForwardIterator2 __p; - _ForwardIterator1 __current = __first1; - - for (;;) - { - while (__first1 != __last1 - && !bool(__predicate(*__first1, *__first2))) - ++__first1; - if (__first1 == __last1) - return __last1; - - __p = __p1; - __current = __first1; - if (++__current == __last1) - return __last1; - - while (__predicate(*__current, *__p)) - { - if (++__p == __last2) - return __first1; - if (++__current == __last1) - return __last1; - } - ++__first1; - } - return __first1; - } - - - /** - * @brief Search a sequence for a number of consecutive values. - * @ingroup non_mutating_algorithms - * @param __first A forward iterator. - * @param __last A forward iterator. - * @param __count The number of consecutive values. - * @param __val The value to find. - * @return The first iterator @c i in the range @p - * [__first,__last-__count) such that @c *(i+N) == @p __val for - * each @c N in the range @p [0,__count), or @p __last if no such - * iterator exists. - * - * Searches the range @p [__first,__last) for @p count consecutive elements - * equal to @p __val. - */ - template - _ForwardIterator - search_n(_ForwardIterator __first, _ForwardIterator __last, - _Integer __count, const _Tp& __val) - { - // concept requirements - __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>) - __glibcxx_function_requires(_EqualOpConcept< - typename iterator_traits<_ForwardIterator>::value_type, _Tp>) - __glibcxx_requires_valid_range(__first, __last); - - if (__count <= 0) - return __first; - if (__count == 1) - return _GLIBCXX_STD_A::find(__first, __last, __val); - return std::__search_n(__first, __last, __count, __val, - std::__iterator_category(__first)); - } - - - /** - * @brief Search a sequence for a number of consecutive values using a - * predicate. - * @ingroup non_mutating_algorithms - * @param __first A forward iterator. - * @param __last A forward iterator. - * @param __count The number of consecutive values. - * @param __val The value to find. - * @param __binary_pred A binary predicate. - * @return The first iterator @c i in the range @p - * [__first,__last-__count) such that @p - * __binary_pred(*(i+N),__val) is true for each @c N in the range - * @p [0,__count), or @p __last if no such iterator exists. - * - * Searches the range @p [__first,__last) for @p __count - * consecutive elements for which the predicate returns true. - */ - template - _ForwardIterator - search_n(_ForwardIterator __first, _ForwardIterator __last, - _Integer __count, const _Tp& __val, - _BinaryPredicate __binary_pred) - { - // concept requirements - __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>) - __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate, - typename iterator_traits<_ForwardIterator>::value_type, _Tp>) - __glibcxx_requires_valid_range(__first, __last); - - if (__count <= 0) - return __first; - if (__count == 1) - { - while (__first != __last && !bool(__binary_pred(*__first, __val))) - ++__first; - return __first; - } - return std::__search_n(__first, __last, __count, __val, __binary_pred, - std::__iterator_category(__first)); - } - - - /** - * @brief Perform an operation on a sequence. - * @ingroup mutating_algorithms - * @param __first An input iterator. - * @param __last An input iterator. - * @param __result An output iterator. - * @param __unary_op A unary operator. - * @return An output iterator equal to @p __result+(__last-__first). - * - * Applies the operator to each element in the input range and assigns - * the results to successive elements of the output sequence. - * Evaluates @p *(__result+N)=unary_op(*(__first+N)) for each @c N in the - * range @p [0,__last-__first). - * - * @p unary_op must not alter its argument. - */ - template - _OutputIterator - transform(_InputIterator __first, _InputIterator __last, - _OutputIterator __result, _UnaryOperation __unary_op) - { - // concept requirements - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>) - __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, - // "the type returned by a _UnaryOperation" - __typeof__(__unary_op(*__first))>) - __glibcxx_requires_valid_range(__first, __last); - - for (; __first != __last; ++__first, ++__result) - *__result = __unary_op(*__first); - return __result; - } - - /** - * @brief Perform an operation on corresponding elements of two sequences. - * @ingroup mutating_algorithms - * @param __first1 An input iterator. - * @param __last1 An input iterator. - * @param __first2 An input iterator. - * @param __result An output iterator. - * @param __binary_op A binary operator. - * @return An output iterator equal to @p result+(last-first). - * - * Applies the operator to the corresponding elements in the two - * input ranges and assigns the results to successive elements of the - * output sequence. - * Evaluates @p - * *(__result+N)=__binary_op(*(__first1+N),*(__first2+N)) for each - * @c N in the range @p [0,__last1-__first1). - * - * @p binary_op must not alter either of its arguments. - */ - template - _OutputIterator - transform(_InputIterator1 __first1, _InputIterator1 __last1, - _InputIterator2 __first2, _OutputIterator __result, - _BinaryOperation __binary_op) - { - // concept requirements - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>) - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>) - __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, - // "the type returned by a _BinaryOperation" - __typeof__(__binary_op(*__first1,*__first2))>) - __glibcxx_requires_valid_range(__first1, __last1); - - for (; __first1 != __last1; ++__first1, ++__first2, ++__result) - *__result = __binary_op(*__first1, *__first2); - return __result; - } - - /** - * @brief Replace each occurrence of one value in a sequence with another - * value. - * @ingroup mutating_algorithms - * @param __first A forward iterator. - * @param __last A forward iterator. - * @param __old_value The value to be replaced. - * @param __new_value The replacement value. - * @return replace() returns no value. - * - * For each iterator @c i in the range @p [__first,__last) if @c *i == - * @p __old_value then the assignment @c *i = @p __new_value is performed. - */ - template - void - replace(_ForwardIterator __first, _ForwardIterator __last, - const _Tp& __old_value, const _Tp& __new_value) - { - // concept requirements - __glibcxx_function_requires(_Mutable_ForwardIteratorConcept< - _ForwardIterator>) - __glibcxx_function_requires(_EqualOpConcept< - typename iterator_traits<_ForwardIterator>::value_type, _Tp>) - __glibcxx_function_requires(_ConvertibleConcept<_Tp, - typename iterator_traits<_ForwardIterator>::value_type>) - __glibcxx_requires_valid_range(__first, __last); - - for (; __first != __last; ++__first) - if (*__first == __old_value) - *__first = __new_value; - } - - /** - * @brief Replace each value in a sequence for which a predicate returns - * true with another value. - * @ingroup mutating_algorithms - * @param __first A forward iterator. - * @param __last A forward iterator. - * @param __pred A predicate. - * @param __new_value The replacement value. - * @return replace_if() returns no value. - * - * For each iterator @c i in the range @p [__first,__last) if @p __pred(*i) - * is true then the assignment @c *i = @p __new_value is performed. - */ - template - void - replace_if(_ForwardIterator __first, _ForwardIterator __last, - _Predicate __pred, const _Tp& __new_value) - { - // concept requirements - __glibcxx_function_requires(_Mutable_ForwardIteratorConcept< - _ForwardIterator>) - __glibcxx_function_requires(_ConvertibleConcept<_Tp, - typename iterator_traits<_ForwardIterator>::value_type>) - __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate, - typename iterator_traits<_ForwardIterator>::value_type>) - __glibcxx_requires_valid_range(__first, __last); - - for (; __first != __last; ++__first) - if (__pred(*__first)) - *__first = __new_value; - } - - /** - * @brief Assign the result of a function object to each value in a - * sequence. - * @ingroup mutating_algorithms - * @param __first A forward iterator. - * @param __last A forward iterator. - * @param __gen A function object taking no arguments and returning - * std::iterator_traits<_ForwardIterator>::value_type - * @return generate() returns no value. - * - * Performs the assignment @c *i = @p __gen() for each @c i in the range - * @p [__first,__last). - */ - template - void - generate(_ForwardIterator __first, _ForwardIterator __last, - _Generator __gen) - { - // concept requirements - __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>) - __glibcxx_function_requires(_GeneratorConcept<_Generator, - typename iterator_traits<_ForwardIterator>::value_type>) - __glibcxx_requires_valid_range(__first, __last); - - for (; __first != __last; ++__first) - *__first = __gen(); - } - - /** - * @brief Assign the result of a function object to each value in a - * sequence. - * @ingroup mutating_algorithms - * @param __first A forward iterator. - * @param __n The length of the sequence. - * @param __gen A function object taking no arguments and returning - * std::iterator_traits<_ForwardIterator>::value_type - * @return The end of the sequence, @p __first+__n - * - * Performs the assignment @c *i = @p __gen() for each @c i in the range - * @p [__first,__first+__n). - * - * _GLIBCXX_RESOLVE_LIB_DEFECTS - * DR 865. More algorithms that throw away information - */ - template - _OutputIterator - generate_n(_OutputIterator __first, _Size __n, _Generator __gen) - { - // concept requirements - __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, - // "the type returned by a _Generator" - __typeof__(__gen())>) - - for (__decltype(__n + 0) __niter = __n; - __niter > 0; --__niter, ++__first) - *__first = __gen(); - return __first; - } - - - /** - * @brief Copy a sequence, removing consecutive duplicate values. - * @ingroup mutating_algorithms - * @param __first An input iterator. - * @param __last An input iterator. - * @param __result An output iterator. - * @return An iterator designating the end of the resulting sequence. - * - * Copies each element in the range @p [__first,__last) to the range - * beginning at @p __result, except that only the first element is copied - * from groups of consecutive elements that compare equal. - * unique_copy() is stable, so the relative order of elements that are - * copied is unchanged. - * - * _GLIBCXX_RESOLVE_LIB_DEFECTS - * DR 241. Does unique_copy() require CopyConstructible and Assignable? - * - * _GLIBCXX_RESOLVE_LIB_DEFECTS - * DR 538. 241 again: Does unique_copy() require CopyConstructible and - * Assignable? - */ - template - inline _OutputIterator - unique_copy(_InputIterator __first, _InputIterator __last, - _OutputIterator __result) - { - // concept requirements - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>) - __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, - typename iterator_traits<_InputIterator>::value_type>) - __glibcxx_function_requires(_EqualityComparableConcept< - typename iterator_traits<_InputIterator>::value_type>) - __glibcxx_requires_valid_range(__first, __last); - - if (__first == __last) - return __result; - return std::__unique_copy(__first, __last, __result, - std::__iterator_category(__first), - std::__iterator_category(__result)); - } - - /** - * @brief Copy a sequence, removing consecutive values using a predicate. - * @ingroup mutating_algorithms - * @param __first An input iterator. - * @param __last An input iterator. - * @param __result An output iterator. - * @param __binary_pred A binary predicate. - * @return An iterator designating the end of the resulting sequence. - * - * Copies each element in the range @p [__first,__last) to the range - * beginning at @p __result, except that only the first element is copied - * from groups of consecutive elements for which @p __binary_pred returns - * true. - * unique_copy() is stable, so the relative order of elements that are - * copied is unchanged. - * - * _GLIBCXX_RESOLVE_LIB_DEFECTS - * DR 241. Does unique_copy() require CopyConstructible and Assignable? - */ - template - inline _OutputIterator - unique_copy(_InputIterator __first, _InputIterator __last, - _OutputIterator __result, - _BinaryPredicate __binary_pred) - { - // concept requirements -- predicates checked later - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>) - __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, - typename iterator_traits<_InputIterator>::value_type>) - __glibcxx_requires_valid_range(__first, __last); - - if (__first == __last) - return __result; - return std::__unique_copy(__first, __last, __result, __binary_pred, - std::__iterator_category(__first), - std::__iterator_category(__result)); - } - - - /** - * @brief Randomly shuffle the elements of a sequence. - * @ingroup mutating_algorithms - * @param __first A forward iterator. - * @param __last A forward iterator. - * @return Nothing. - * - * Reorder the elements in the range @p [__first,__last) using a random - * distribution, so that every possible ordering of the sequence is - * equally likely. - */ - template - inline void - random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last) - { - // concept requirements - __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept< - _RandomAccessIterator>) - __glibcxx_requires_valid_range(__first, __last); - - if (__first != __last) - for (_RandomAccessIterator __i = __first + 1; __i != __last; ++__i) - std::iter_swap(__i, __first + (std::rand() % ((__i - __first) + 1))); - } - - /** - * @brief Shuffle the elements of a sequence using a random number - * generator. - * @ingroup mutating_algorithms - * @param __first A forward iterator. - * @param __last A forward iterator. - * @param __rand The RNG functor or function. - * @return Nothing. - * - * Reorders the elements in the range @p [__first,__last) using @p __rand to - * provide a random distribution. Calling @p __rand(N) for a positive - * integer @p N should return a randomly chosen integer from the - * range [0,N). - */ - template - void - random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last, -#if __cplusplus >= 201103L - _RandomNumberGenerator&& __rand) -#else - _RandomNumberGenerator& __rand) -#endif - { - // concept requirements - __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept< - _RandomAccessIterator>) - __glibcxx_requires_valid_range(__first, __last); - - if (__first == __last) - return; - for (_RandomAccessIterator __i = __first + 1; __i != __last; ++__i) - std::iter_swap(__i, __first + __rand((__i - __first) + 1)); - } - - - /** - * @brief Move elements for which a predicate is true to the beginning - * of a sequence. - * @ingroup mutating_algorithms - * @param __first A forward iterator. - * @param __last A forward iterator. - * @param __pred A predicate functor. - * @return An iterator @p middle such that @p __pred(i) is true for each - * iterator @p i in the range @p [__first,middle) and false for each @p i - * in the range @p [middle,__last). - * - * @p __pred must not modify its operand. @p partition() does not preserve - * the relative ordering of elements in each group, use - * @p stable_partition() if this is needed. - */ - template - inline _ForwardIterator - partition(_ForwardIterator __first, _ForwardIterator __last, - _Predicate __pred) - { - // concept requirements - __glibcxx_function_requires(_Mutable_ForwardIteratorConcept< - _ForwardIterator>) - __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate, - typename iterator_traits<_ForwardIterator>::value_type>) - __glibcxx_requires_valid_range(__first, __last); - - return std::__partition(__first, __last, __pred, - std::__iterator_category(__first)); - } - - /** - * @brief Sort the smallest elements of a sequence. - * @ingroup sorting_algorithms - * @param __first An iterator. - * @param __middle Another iterator. - * @param __last Another iterator. - * @return Nothing. - * - * Sorts the smallest @p (__middle-__first) elements in the range - * @p [first,last) and moves them to the range @p [__first,__middle). The - * order of the remaining elements in the range @p [__middle,__last) is - * undefined. - * After the sort if @e i and @e j are iterators in the range - * @p [__first,__middle) such that i precedes j and @e k is an iterator in - * the range @p [__middle,__last) then *j<*i and *k<*i are both false. - */ - template - inline void - partial_sort(_RandomAccessIterator __first, - _RandomAccessIterator __middle, - _RandomAccessIterator __last) - { - typedef typename iterator_traits<_RandomAccessIterator>::value_type - _ValueType; - - // concept requirements - __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept< - _RandomAccessIterator>) - __glibcxx_function_requires(_LessThanComparableConcept<_ValueType>) - __glibcxx_requires_valid_range(__first, __middle); - __glibcxx_requires_valid_range(__middle, __last); - - std::__heap_select(__first, __middle, __last); - std::sort_heap(__first, __middle); - } - - /** - * @brief Sort the smallest elements of a sequence using a predicate - * for comparison. - * @ingroup sorting_algorithms - * @param __first An iterator. - * @param __middle Another iterator. - * @param __last Another iterator. - * @param __comp A comparison functor. - * @return Nothing. - * - * Sorts the smallest @p (__middle-__first) elements in the range - * @p [__first,__last) and moves them to the range @p [__first,__middle). The - * order of the remaining elements in the range @p [__middle,__last) is - * undefined. - * After the sort if @e i and @e j are iterators in the range - * @p [__first,__middle) such that i precedes j and @e k is an iterator in - * the range @p [__middle,__last) then @p *__comp(j,*i) and @p __comp(*k,*i) - * are both false. - */ - template - inline void - partial_sort(_RandomAccessIterator __first, - _RandomAccessIterator __middle, - _RandomAccessIterator __last, - _Compare __comp) - { - typedef typename iterator_traits<_RandomAccessIterator>::value_type - _ValueType; - - // concept requirements - __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept< - _RandomAccessIterator>) - __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, - _ValueType, _ValueType>) - __glibcxx_requires_valid_range(__first, __middle); - __glibcxx_requires_valid_range(__middle, __last); - - std::__heap_select(__first, __middle, __last, __comp); - std::sort_heap(__first, __middle, __comp); - } - - /** - * @brief Sort a sequence just enough to find a particular position. - * @ingroup sorting_algorithms - * @param __first An iterator. - * @param __nth Another iterator. - * @param __last Another iterator. - * @return Nothing. - * - * Rearranges the elements in the range @p [__first,__last) so that @p *__nth - * is the same element that would have been in that position had the - * whole sequence been sorted. The elements either side of @p *__nth are - * not completely sorted, but for any iterator @e i in the range - * @p [__first,__nth) and any iterator @e j in the range @p [__nth,__last) it - * holds that *j < *i is false. - */ - template - inline void - nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, - _RandomAccessIterator __last) - { - typedef typename iterator_traits<_RandomAccessIterator>::value_type - _ValueType; - - // concept requirements - __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept< - _RandomAccessIterator>) - __glibcxx_function_requires(_LessThanComparableConcept<_ValueType>) - __glibcxx_requires_valid_range(__first, __nth); - __glibcxx_requires_valid_range(__nth, __last); - - if (__first == __last || __nth == __last) - return; - - std::__introselect(__first, __nth, __last, - std::__lg(__last - __first) * 2); - } - - /** - * @brief Sort a sequence just enough to find a particular position - * using a predicate for comparison. - * @ingroup sorting_algorithms - * @param __first An iterator. - * @param __nth Another iterator. - * @param __last Another iterator. - * @param __comp A comparison functor. - * @return Nothing. - * - * Rearranges the elements in the range @p [__first,__last) so that @p *__nth - * is the same element that would have been in that position had the - * whole sequence been sorted. The elements either side of @p *__nth are - * not completely sorted, but for any iterator @e i in the range - * @p [__first,__nth) and any iterator @e j in the range @p [__nth,__last) it - * holds that @p __comp(*j,*i) is false. - */ - template - inline void - nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, - _RandomAccessIterator __last, _Compare __comp) - { - typedef typename iterator_traits<_RandomAccessIterator>::value_type - _ValueType; - - // concept requirements - __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept< - _RandomAccessIterator>) - __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, - _ValueType, _ValueType>) - __glibcxx_requires_valid_range(__first, __nth); - __glibcxx_requires_valid_range(__nth, __last); - - if (__first == __last || __nth == __last) - return; - - std::__introselect(__first, __nth, __last, - std::__lg(__last - __first) * 2, __comp); - } - - - /** - * @brief Sort the elements of a sequence. - * @ingroup sorting_algorithms - * @param __first An iterator. - * @param __last Another iterator. - * @return Nothing. - * - * Sorts the elements in the range @p [__first,__last) in ascending order, - * such that for each iterator @e i in the range @p [__first,__last-1), - * *(i+1)<*i is false. - * - * The relative ordering of equivalent elements is not preserved, use - * @p stable_sort() if this is needed. - */ - template - inline void - sort(_RandomAccessIterator __first, _RandomAccessIterator __last) - { - typedef typename iterator_traits<_RandomAccessIterator>::value_type - _ValueType; - - // concept requirements - __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept< - _RandomAccessIterator>) - __glibcxx_function_requires(_LessThanComparableConcept<_ValueType>) - __glibcxx_requires_valid_range(__first, __last); - - if (__first != __last) - { - std::__introsort_loop(__first, __last, - std::__lg(__last - __first) * 2); - std::__final_insertion_sort(__first, __last); - } - } - - /** - * @brief Sort the elements of a sequence using a predicate for comparison. - * @ingroup sorting_algorithms - * @param __first An iterator. - * @param __last Another iterator. - * @param __comp A comparison functor. - * @return Nothing. - * - * Sorts the elements in the range @p [__first,__last) in ascending order, - * such that @p __comp(*(i+1),*i) is false for every iterator @e i in the - * range @p [__first,__last-1). - * - * The relative ordering of equivalent elements is not preserved, use - * @p stable_sort() if this is needed. - */ - template - inline void - sort(_RandomAccessIterator __first, _RandomAccessIterator __last, - _Compare __comp) - { - typedef typename iterator_traits<_RandomAccessIterator>::value_type - _ValueType; - - // concept requirements - __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept< - _RandomAccessIterator>) - __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, _ValueType, - _ValueType>) - __glibcxx_requires_valid_range(__first, __last); - - if (__first != __last) - { - std::__introsort_loop(__first, __last, - std::__lg(__last - __first) * 2, __comp); - std::__final_insertion_sort(__first, __last, __comp); - } - } - - /** - * @brief Merges two sorted ranges. - * @ingroup sorting_algorithms - * @param __first1 An iterator. - * @param __first2 Another iterator. - * @param __last1 Another iterator. - * @param __last2 Another iterator. - * @param __result An iterator pointing to the end of the merged range. - * @return An iterator pointing to the first element not less - * than @e val. - * - * Merges the ranges @p [__first1,__last1) and @p [__first2,__last2) into - * the sorted range @p [__result, __result + (__last1-__first1) + - * (__last2-__first2)). Both input ranges must be sorted, and the - * output range must not overlap with either of the input ranges. - * The sort is @e stable, that is, for equivalent elements in the - * two ranges, elements from the first range will always come - * before elements from the second. - */ - template - _OutputIterator - merge(_InputIterator1 __first1, _InputIterator1 __last1, - _InputIterator2 __first2, _InputIterator2 __last2, - _OutputIterator __result) - { - typedef typename iterator_traits<_InputIterator1>::value_type - _ValueType1; - typedef typename iterator_traits<_InputIterator2>::value_type - _ValueType2; - - // concept requirements - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>) - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>) - __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, - _ValueType1>) - __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, - _ValueType2>) - __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>) - __glibcxx_requires_sorted_set(__first1, __last1, __first2); - __glibcxx_requires_sorted_set(__first2, __last2, __first1); - - while (__first1 != __last1 && __first2 != __last2) - { - if (*__first2 < *__first1) - { - *__result = *__first2; - ++__first2; - } - else - { - *__result = *__first1; - ++__first1; - } - ++__result; - } - return std::copy(__first2, __last2, std::copy(__first1, __last1, - __result)); - } - - /** - * @brief Merges two sorted ranges. - * @ingroup sorting_algorithms - * @param __first1 An iterator. - * @param __first2 Another iterator. - * @param __last1 Another iterator. - * @param __last2 Another iterator. - * @param __result An iterator pointing to the end of the merged range. - * @param __comp A functor to use for comparisons. - * @return An iterator pointing to the first element "not less - * than" @e val. - * - * Merges the ranges @p [__first1,__last1) and @p [__first2,__last2) into - * the sorted range @p [__result, __result + (__last1-__first1) + - * (__last2-__first2)). Both input ranges must be sorted, and the - * output range must not overlap with either of the input ranges. - * The sort is @e stable, that is, for equivalent elements in the - * two ranges, elements from the first range will always come - * before elements from the second. - * - * The comparison function should have the same effects on ordering as - * the function used for the initial sort. - */ - template - _OutputIterator - merge(_InputIterator1 __first1, _InputIterator1 __last1, - _InputIterator2 __first2, _InputIterator2 __last2, - _OutputIterator __result, _Compare __comp) - { - typedef typename iterator_traits<_InputIterator1>::value_type - _ValueType1; - typedef typename iterator_traits<_InputIterator2>::value_type - _ValueType2; - - // concept requirements - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>) - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>) - __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, - _ValueType1>) - __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, - _ValueType2>) - __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, - _ValueType2, _ValueType1>) - __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp); - __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp); - - while (__first1 != __last1 && __first2 != __last2) - { - if (__comp(*__first2, *__first1)) - { - *__result = *__first2; - ++__first2; - } - else - { - *__result = *__first1; - ++__first1; - } - ++__result; - } - return std::copy(__first2, __last2, std::copy(__first1, __last1, - __result)); - } - - - /** - * @brief Sort the elements of a sequence, preserving the relative order - * of equivalent elements. - * @ingroup sorting_algorithms - * @param __first An iterator. - * @param __last Another iterator. - * @return Nothing. - * - * Sorts the elements in the range @p [__first,__last) in ascending order, - * such that for each iterator @p i in the range @p [__first,__last-1), - * @p *(i+1)<*i is false. - * - * The relative ordering of equivalent elements is preserved, so any two - * elements @p x and @p y in the range @p [__first,__last) such that - * @p x - inline void - stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last) - { - typedef typename iterator_traits<_RandomAccessIterator>::value_type - _ValueType; - typedef typename iterator_traits<_RandomAccessIterator>::difference_type - _DistanceType; - - // concept requirements - __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept< - _RandomAccessIterator>) - __glibcxx_function_requires(_LessThanComparableConcept<_ValueType>) - __glibcxx_requires_valid_range(__first, __last); - - _Temporary_buffer<_RandomAccessIterator, _ValueType> __buf(__first, - __last); - if (__buf.begin() == 0) - std::__inplace_stable_sort(__first, __last); - else - std::__stable_sort_adaptive(__first, __last, __buf.begin(), - _DistanceType(__buf.size())); - } - - /** - * @brief Sort the elements of a sequence using a predicate for comparison, - * preserving the relative order of equivalent elements. - * @ingroup sorting_algorithms - * @param __first An iterator. - * @param __last Another iterator. - * @param __comp A comparison functor. - * @return Nothing. - * - * Sorts the elements in the range @p [__first,__last) in ascending order, - * such that for each iterator @p i in the range @p [__first,__last-1), - * @p __comp(*(i+1),*i) is false. - * - * The relative ordering of equivalent elements is preserved, so any two - * elements @p x and @p y in the range @p [__first,__last) such that - * @p __comp(x,y) is false and @p __comp(y,x) is false will have the same - * relative ordering after calling @p stable_sort(). - */ - template - inline void - stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, - _Compare __comp) - { - typedef typename iterator_traits<_RandomAccessIterator>::value_type - _ValueType; - typedef typename iterator_traits<_RandomAccessIterator>::difference_type - _DistanceType; - - // concept requirements - __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept< - _RandomAccessIterator>) - __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, - _ValueType, - _ValueType>) - __glibcxx_requires_valid_range(__first, __last); - - _Temporary_buffer<_RandomAccessIterator, _ValueType> __buf(__first, - __last); - if (__buf.begin() == 0) - std::__inplace_stable_sort(__first, __last, __comp); - else - std::__stable_sort_adaptive(__first, __last, __buf.begin(), - _DistanceType(__buf.size()), __comp); - } - - - /** - * @brief Return the union of two sorted ranges. - * @ingroup set_algorithms - * @param __first1 Start of first range. - * @param __last1 End of first range. - * @param __first2 Start of second range. - * @param __last2 End of second range. - * @return End of the output range. - * @ingroup set_algorithms - * - * This operation iterates over both ranges, copying elements present in - * each range in order to the output range. Iterators increment for each - * range. When the current element of one range is less than the other, - * that element is copied and the iterator advanced. If an element is - * contained in both ranges, the element from the first range is copied and - * both ranges advance. The output range may not overlap either input - * range. - */ - template - _OutputIterator - set_union(_InputIterator1 __first1, _InputIterator1 __last1, - _InputIterator2 __first2, _InputIterator2 __last2, - _OutputIterator __result) - { - typedef typename iterator_traits<_InputIterator1>::value_type - _ValueType1; - typedef typename iterator_traits<_InputIterator2>::value_type - _ValueType2; - - // concept requirements - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>) - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>) - __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, - _ValueType1>) - __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, - _ValueType2>) - __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>) - __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>) - __glibcxx_requires_sorted_set(__first1, __last1, __first2); - __glibcxx_requires_sorted_set(__first2, __last2, __first1); - - while (__first1 != __last1 && __first2 != __last2) - { - if (*__first1 < *__first2) - { - *__result = *__first1; - ++__first1; - } - else if (*__first2 < *__first1) - { - *__result = *__first2; - ++__first2; - } - else - { - *__result = *__first1; - ++__first1; - ++__first2; - } - ++__result; - } - return std::copy(__first2, __last2, std::copy(__first1, __last1, - __result)); - } - - /** - * @brief Return the union of two sorted ranges using a comparison functor. - * @ingroup set_algorithms - * @param __first1 Start of first range. - * @param __last1 End of first range. - * @param __first2 Start of second range. - * @param __last2 End of second range. - * @param __comp The comparison functor. - * @return End of the output range. - * @ingroup set_algorithms - * - * This operation iterates over both ranges, copying elements present in - * each range in order to the output range. Iterators increment for each - * range. When the current element of one range is less than the other - * according to @p __comp, that element is copied and the iterator advanced. - * If an equivalent element according to @p __comp is contained in both - * ranges, the element from the first range is copied and both ranges - * advance. The output range may not overlap either input range. - */ - template - _OutputIterator - set_union(_InputIterator1 __first1, _InputIterator1 __last1, - _InputIterator2 __first2, _InputIterator2 __last2, - _OutputIterator __result, _Compare __comp) - { - typedef typename iterator_traits<_InputIterator1>::value_type - _ValueType1; - typedef typename iterator_traits<_InputIterator2>::value_type - _ValueType2; - - // concept requirements - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>) - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>) - __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, - _ValueType1>) - __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, - _ValueType2>) - __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, - _ValueType1, _ValueType2>) - __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, - _ValueType2, _ValueType1>) - __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp); - __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp); - - while (__first1 != __last1 && __first2 != __last2) - { - if (__comp(*__first1, *__first2)) - { - *__result = *__first1; - ++__first1; - } - else if (__comp(*__first2, *__first1)) - { - *__result = *__first2; - ++__first2; - } - else - { - *__result = *__first1; - ++__first1; - ++__first2; - } - ++__result; - } - return std::copy(__first2, __last2, std::copy(__first1, __last1, - __result)); - } - - /** - * @brief Return the intersection of two sorted ranges. - * @ingroup set_algorithms - * @param __first1 Start of first range. - * @param __last1 End of first range. - * @param __first2 Start of second range. - * @param __last2 End of second range. - * @return End of the output range. - * @ingroup set_algorithms - * - * This operation iterates over both ranges, copying elements present in - * both ranges in order to the output range. Iterators increment for each - * range. When the current element of one range is less than the other, - * that iterator advances. If an element is contained in both ranges, the - * element from the first range is copied and both ranges advance. The - * output range may not overlap either input range. - */ - template - _OutputIterator - set_intersection(_InputIterator1 __first1, _InputIterator1 __last1, - _InputIterator2 __first2, _InputIterator2 __last2, - _OutputIterator __result) - { - typedef typename iterator_traits<_InputIterator1>::value_type - _ValueType1; - typedef typename iterator_traits<_InputIterator2>::value_type - _ValueType2; - - // concept requirements - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>) - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>) - __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, - _ValueType1>) - __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>) - __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>) - __glibcxx_requires_sorted_set(__first1, __last1, __first2); - __glibcxx_requires_sorted_set(__first2, __last2, __first1); - - while (__first1 != __last1 && __first2 != __last2) - if (*__first1 < *__first2) - ++__first1; - else if (*__first2 < *__first1) - ++__first2; - else - { - *__result = *__first1; - ++__first1; - ++__first2; - ++__result; - } - return __result; - } - - /** - * @brief Return the intersection of two sorted ranges using comparison - * functor. - * @ingroup set_algorithms - * @param __first1 Start of first range. - * @param __last1 End of first range. - * @param __first2 Start of second range. - * @param __last2 End of second range. - * @param __comp The comparison functor. - * @return End of the output range. - * @ingroup set_algorithms - * - * This operation iterates over both ranges, copying elements present in - * both ranges in order to the output range. Iterators increment for each - * range. When the current element of one range is less than the other - * according to @p __comp, that iterator advances. If an element is - * contained in both ranges according to @p __comp, the element from the - * first range is copied and both ranges advance. The output range may not - * overlap either input range. - */ - template - _OutputIterator - set_intersection(_InputIterator1 __first1, _InputIterator1 __last1, - _InputIterator2 __first2, _InputIterator2 __last2, - _OutputIterator __result, _Compare __comp) - { - typedef typename iterator_traits<_InputIterator1>::value_type - _ValueType1; - typedef typename iterator_traits<_InputIterator2>::value_type - _ValueType2; - - // concept requirements - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>) - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>) - __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, - _ValueType1>) - __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, - _ValueType1, _ValueType2>) - __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, - _ValueType2, _ValueType1>) - __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp); - __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp); - - while (__first1 != __last1 && __first2 != __last2) - if (__comp(*__first1, *__first2)) - ++__first1; - else if (__comp(*__first2, *__first1)) - ++__first2; - else - { - *__result = *__first1; - ++__first1; - ++__first2; - ++__result; - } - return __result; - } - - /** - * @brief Return the difference of two sorted ranges. - * @ingroup set_algorithms - * @param __first1 Start of first range. - * @param __last1 End of first range. - * @param __first2 Start of second range. - * @param __last2 End of second range. - * @return End of the output range. - * @ingroup set_algorithms - * - * This operation iterates over both ranges, copying elements present in - * the first range but not the second in order to the output range. - * Iterators increment for each range. When the current element of the - * first range is less than the second, that element is copied and the - * iterator advances. If the current element of the second range is less, - * the iterator advances, but no element is copied. If an element is - * contained in both ranges, no elements are copied and both ranges - * advance. The output range may not overlap either input range. - */ - template - _OutputIterator - set_difference(_InputIterator1 __first1, _InputIterator1 __last1, - _InputIterator2 __first2, _InputIterator2 __last2, - _OutputIterator __result) - { - typedef typename iterator_traits<_InputIterator1>::value_type - _ValueType1; - typedef typename iterator_traits<_InputIterator2>::value_type - _ValueType2; - - // concept requirements - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>) - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>) - __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, - _ValueType1>) - __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>) - __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>) - __glibcxx_requires_sorted_set(__first1, __last1, __first2); - __glibcxx_requires_sorted_set(__first2, __last2, __first1); - - while (__first1 != __last1 && __first2 != __last2) - if (*__first1 < *__first2) - { - *__result = *__first1; - ++__first1; - ++__result; - } - else if (*__first2 < *__first1) - ++__first2; - else - { - ++__first1; - ++__first2; - } - return std::copy(__first1, __last1, __result); - } - - /** - * @brief Return the difference of two sorted ranges using comparison - * functor. - * @ingroup set_algorithms - * @param __first1 Start of first range. - * @param __last1 End of first range. - * @param __first2 Start of second range. - * @param __last2 End of second range. - * @param __comp The comparison functor. - * @return End of the output range. - * @ingroup set_algorithms - * - * This operation iterates over both ranges, copying elements present in - * the first range but not the second in order to the output range. - * Iterators increment for each range. When the current element of the - * first range is less than the second according to @p __comp, that element - * is copied and the iterator advances. If the current element of the - * second range is less, no element is copied and the iterator advances. - * If an element is contained in both ranges according to @p __comp, no - * elements are copied and both ranges advance. The output range may not - * overlap either input range. - */ - template - _OutputIterator - set_difference(_InputIterator1 __first1, _InputIterator1 __last1, - _InputIterator2 __first2, _InputIterator2 __last2, - _OutputIterator __result, _Compare __comp) - { - typedef typename iterator_traits<_InputIterator1>::value_type - _ValueType1; - typedef typename iterator_traits<_InputIterator2>::value_type - _ValueType2; - - // concept requirements - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>) - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>) - __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, - _ValueType1>) - __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, - _ValueType1, _ValueType2>) - __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, - _ValueType2, _ValueType1>) - __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp); - __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp); - - while (__first1 != __last1 && __first2 != __last2) - if (__comp(*__first1, *__first2)) - { - *__result = *__first1; - ++__first1; - ++__result; - } - else if (__comp(*__first2, *__first1)) - ++__first2; - else - { - ++__first1; - ++__first2; - } - return std::copy(__first1, __last1, __result); - } - - /** - * @brief Return the symmetric difference of two sorted ranges. - * @ingroup set_algorithms - * @param __first1 Start of first range. - * @param __last1 End of first range. - * @param __first2 Start of second range. - * @param __last2 End of second range. - * @return End of the output range. - * @ingroup set_algorithms - * - * This operation iterates over both ranges, copying elements present in - * one range but not the other in order to the output range. Iterators - * increment for each range. When the current element of one range is less - * than the other, that element is copied and the iterator advances. If an - * element is contained in both ranges, no elements are copied and both - * ranges advance. The output range may not overlap either input range. - */ - template - _OutputIterator - set_symmetric_difference(_InputIterator1 __first1, _InputIterator1 __last1, - _InputIterator2 __first2, _InputIterator2 __last2, - _OutputIterator __result) - { - typedef typename iterator_traits<_InputIterator1>::value_type - _ValueType1; - typedef typename iterator_traits<_InputIterator2>::value_type - _ValueType2; - - // concept requirements - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>) - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>) - __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, - _ValueType1>) - __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, - _ValueType2>) - __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>) - __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>) - __glibcxx_requires_sorted_set(__first1, __last1, __first2); - __glibcxx_requires_sorted_set(__first2, __last2, __first1); - - while (__first1 != __last1 && __first2 != __last2) - if (*__first1 < *__first2) - { - *__result = *__first1; - ++__first1; - ++__result; - } - else if (*__first2 < *__first1) - { - *__result = *__first2; - ++__first2; - ++__result; - } - else - { - ++__first1; - ++__first2; - } - return std::copy(__first2, __last2, std::copy(__first1, - __last1, __result)); - } - - /** - * @brief Return the symmetric difference of two sorted ranges using - * comparison functor. - * @ingroup set_algorithms - * @param __first1 Start of first range. - * @param __last1 End of first range. - * @param __first2 Start of second range. - * @param __last2 End of second range. - * @param __comp The comparison functor. - * @return End of the output range. - * @ingroup set_algorithms - * - * This operation iterates over both ranges, copying elements present in - * one range but not the other in order to the output range. Iterators - * increment for each range. When the current element of one range is less - * than the other according to @p comp, that element is copied and the - * iterator advances. If an element is contained in both ranges according - * to @p __comp, no elements are copied and both ranges advance. The output - * range may not overlap either input range. - */ - template - _OutputIterator - set_symmetric_difference(_InputIterator1 __first1, _InputIterator1 __last1, - _InputIterator2 __first2, _InputIterator2 __last2, - _OutputIterator __result, - _Compare __comp) - { - typedef typename iterator_traits<_InputIterator1>::value_type - _ValueType1; - typedef typename iterator_traits<_InputIterator2>::value_type - _ValueType2; - - // concept requirements - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>) - __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>) - __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, - _ValueType1>) - __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, - _ValueType2>) - __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, - _ValueType1, _ValueType2>) - __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, - _ValueType2, _ValueType1>) - __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp); - __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp); - - while (__first1 != __last1 && __first2 != __last2) - if (__comp(*__first1, *__first2)) - { - *__result = *__first1; - ++__first1; - ++__result; - } - else if (__comp(*__first2, *__first1)) - { - *__result = *__first2; - ++__first2; - ++__result; - } - else - { - ++__first1; - ++__first2; - } - return std::copy(__first2, __last2, - std::copy(__first1, __last1, __result)); - } - - - /** - * @brief Return the minimum element in a range. - * @ingroup sorting_algorithms - * @param __first Start of range. - * @param __last End of range. - * @return Iterator referencing the first instance of the smallest value. - */ - template - _ForwardIterator - min_element(_ForwardIterator __first, _ForwardIterator __last) - { - // concept requirements - __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>) - __glibcxx_function_requires(_LessThanComparableConcept< - typename iterator_traits<_ForwardIterator>::value_type>) - __glibcxx_requires_valid_range(__first, __last); - - if (__first == __last) - return __first; - _ForwardIterator __result = __first; - while (++__first != __last) - if (*__first < *__result) - __result = __first; - return __result; - } - - /** - * @brief Return the minimum element in a range using comparison functor. - * @ingroup sorting_algorithms - * @param __first Start of range. - * @param __last End of range. - * @param __comp Comparison functor. - * @return Iterator referencing the first instance of the smallest value - * according to __comp. - */ - template - _ForwardIterator - min_element(_ForwardIterator __first, _ForwardIterator __last, - _Compare __comp) - { - // concept requirements - __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>) - __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, - typename iterator_traits<_ForwardIterator>::value_type, - typename iterator_traits<_ForwardIterator>::value_type>) - __glibcxx_requires_valid_range(__first, __last); - - if (__first == __last) - return __first; - _ForwardIterator __result = __first; - while (++__first != __last) - if (__comp(*__first, *__result)) - __result = __first; - return __result; - } - - /** - * @brief Return the maximum element in a range. - * @ingroup sorting_algorithms - * @param __first Start of range. - * @param __last End of range. - * @return Iterator referencing the first instance of the largest value. - */ - template - _ForwardIterator - max_element(_ForwardIterator __first, _ForwardIterator __last) - { - // concept requirements - __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>) - __glibcxx_function_requires(_LessThanComparableConcept< - typename iterator_traits<_ForwardIterator>::value_type>) - __glibcxx_requires_valid_range(__first, __last); - - if (__first == __last) - return __first; - _ForwardIterator __result = __first; - while (++__first != __last) - if (*__result < *__first) - __result = __first; - return __result; - } - - /** - * @brief Return the maximum element in a range using comparison functor. - * @ingroup sorting_algorithms - * @param __first Start of range. - * @param __last End of range. - * @param __comp Comparison functor. - * @return Iterator referencing the first instance of the largest value - * according to __comp. - */ - template - _ForwardIterator - max_element(_ForwardIterator __first, _ForwardIterator __last, - _Compare __comp) - { - // concept requirements - __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>) - __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, - typename iterator_traits<_ForwardIterator>::value_type, - typename iterator_traits<_ForwardIterator>::value_type>) - __glibcxx_requires_valid_range(__first, __last); - - if (__first == __last) return __first; - _ForwardIterator __result = __first; - while (++__first != __last) - if (__comp(*__result, *__first)) - __result = __first; - return __result; - } - -_GLIBCXX_END_NAMESPACE_ALGO -} // namespace std - -#endif /* _STL_ALGO_H */ diff -r e2911d0176dc -r 212145b8e5f0 build-aux/subst-config-vals.in.sh --- a/build-aux/subst-config-vals.in.sh Fri May 12 08:00:41 2023 +0200 +++ b/build-aux/subst-config-vals.in.sh Fri May 12 08:03:14 2023 +0200 @@ -210,7 +210,6 @@ QT_CPPFLAGS="@QT_CPPFLAGS@" QT_LDFLAGS="@QT_LDFLAGS@" QT_LIBS="@QT_LIBS@" -QT_OPENGL_LIBS="@QT_OPENGL_LIBS@" RANLIB="@RANLIB@" RDYNAMIC_FLAG="@RDYNAMIC_FLAG@" READLINE_LIBS="@LIBREADLINE@" @@ -372,7 +371,6 @@ -e "s|%OCTAVE_CONF_QT_CPPFLAGS%|\"${QT_CPPFLAGS}\"|" \ -e "s|%OCTAVE_CONF_QT_LDFLAGS%|\"${QT_LDFLAGS}\"|" \ -e "s|%OCTAVE_CONF_QT_LIBS%|\"${QT_LIBS}\"|" \ - -e "s|%OCTAVE_CONF_QT_OPENGL_LIBS%|\"${QT_OPENGL_LIBS}\"|" \ -e "s|%OCTAVE_CONF_RANLIB%|\"${RANLIB}\"|" \ -e "s|%OCTAVE_CONF_RDYNAMIC_FLAG%|\"${RDYNAMIC_FLAG}\"|" \ -e "s|%OCTAVE_CONF_READLINE_LIBS%|\"${READLINE_LIBS}\"|" | \ diff -r e2911d0176dc -r 212145b8e5f0 build-aux/subst-cross-config-vals.in.sh --- a/build-aux/subst-cross-config-vals.in.sh Fri May 12 08:00:41 2023 +0200 +++ b/build-aux/subst-cross-config-vals.in.sh Fri May 12 08:03:14 2023 +0200 @@ -214,7 +214,6 @@ QT_CPPFLAGS="@QT_CPPFLAGS@" QT_LDFLAGS="@QT_LDFLAGS@" QT_LIBS="@QT_LIBS@" -QT_OPENGL_LIBS="@QT_OPENGL_LIBS@" RANLIB="@RANLIB@" RDYNAMIC_FLAG="@RDYNAMIC_FLAG@" READLINE_LIBS="@LIBREADLINE@" @@ -376,7 +375,6 @@ -e "s|%OCTAVE_CONF_QT_CPPFLAGS%|\"${QT_CPPFLAGS}\"|" \ -e "s|%OCTAVE_CONF_QT_LDFLAGS%|\"${QT_LDFLAGS}\"|" \ -e "s|%OCTAVE_CONF_QT_LIBS%|\"${QT_LIBS}\"|" \ - -e "s|%OCTAVE_CONF_QT_OPENGL_LIBS%|\"${QT_OPENGL_LIBS}\"|" \ -e "s|%OCTAVE_CONF_RANLIB%|\"${RANLIB}\"|" \ -e "s|%OCTAVE_CONF_RDYNAMIC_FLAG%|\"${RDYNAMIC_FLAG}\"|" \ -e "s|%OCTAVE_CONF_READLINE_LIBS%|\"${READLINE_LIBS}\"|" | \ diff -r e2911d0176dc -r 212145b8e5f0 configure.ac --- a/configure.ac Fri May 12 08:00:41 2023 +0200 +++ b/configure.ac Fri May 12 08:03:14 2023 +0200 @@ -27,7 +27,7 @@ ### Initialize Autoconf AC_PREREQ([2.65]) -AC_INIT([GNU Octave], [8.2.1], [https://octave.org/bugs.html], [octave], +AC_INIT([GNU Octave], [9.0.0], [https://octave.org/bugs.html], [octave], [https://www.gnu.org/software/octave/]) ### Declare version numbers @@ -39,9 +39,9 @@ ## explains how to update these numbers for release and development ## versions. -OCTAVE_MAJOR_VERSION=8 -OCTAVE_MINOR_VERSION=2 -OCTAVE_PATCH_VERSION=1 +OCTAVE_MAJOR_VERSION=9 +OCTAVE_MINOR_VERSION=0 +OCTAVE_PATCH_VERSION=0 dnl PACKAGE_VERSION is set by the AC_INIT VERSION argument. OCTAVE_VERSION="$PACKAGE_VERSION" @@ -389,16 +389,6 @@ fi AC_SUBST(GXX_VERSION) -## Workaround for broken STL algorithm library. -OCTAVE_CHECK_BROKEN_STL_ALGO_H -AM_CONDITIONAL([AMCOND_HAVE_BROKEN_STL_ALGO_H], - [test $octave_cv_broken_stl_algo_h = yes]) - -if test $octave_cv_broken_stl_algo_h = yes; then - warn_stl_algo_h="Found nth_element broken in g++ $GXX_VERSION. Attempting to repair by using local patched version of bits/stl_algo.h." - OCTAVE_CONFIGURE_WARNING([warn_stl_algo_h]) -fi - ### Check version number when using gcc. dnl It might be different from the g++ version number. @@ -940,6 +930,20 @@ [Define to 1 to truncate intermediate FP results.]) fi +### Enable internal checks + +## The checks slow down the execution and are redundant, +## but useful for debugging or verifying GNU Octave. +ENABLE_INTERNAL_CHECKS=no +AC_ARG_ENABLE([internal-checks], + [AS_HELP_STRING([--enable-internal-checks], + [Enable internal checks that are redundant but useful to debug or verify GNU Octave])], + [if test "$enableval" = yes; then ENABLE_INTERNAL_CHECKS=yes; fi], []) +if test $ENABLE_INTERNAL_CHECKS = yes; then + AC_DEFINE(OCTAVE_ENABLE_INTERNAL_CHECKS, 1, + [Define to 1 to enable internal checks.]) +fi + ### Determine extra CFLAGS, CXXFLAGS that may be necessary for Octave. ## On Intel systems with gcc, we need to compile with -mieee-fp to get full @@ -998,6 +1002,7 @@ AC_SUBST(XTRA_CFLAGS) AC_SUBST(XTRA_CXXFLAGS) +AC_SUBST(XTRA_LDFLAGS) ### Defaults for cross compiling. dnl BUILD_CC and BUILD_CXX are the compilers that we use for building tools @@ -1492,6 +1497,12 @@ OCTAVE_ENABLE_READLINE +### Check whether functions from libiconv are available. + +OCTAVE_CHECK_ICONVLIST + +OCTAVE_CHECK_ICONV_CANONICALIZE + ### Check for ZLIB library. OCTAVE_CHECK_LIB(z, ZLIB, @@ -1853,7 +1864,7 @@ ### GUI/Qt related tests. -QT_VERSIONS="5" +QT_VERSIONS="5 6" AC_ARG_WITH([qt], [AS_HELP_STRING([--with-qt=VER], [use the Qt major version VER]) @@ -2008,8 +2019,11 @@ AC_SUBST(FLTK_LDFLAGS) AC_SUBST(FLTK_LIBS) -### Final determination of whether OpenGL graphics can be built. -if test $build_qt_graphics = no && test $build_fltk_graphics = no; then +### Final determination of whether OpenGL graphics features should +### be built. Note that there is no longer a way to build the Qt GUI +### without also building a Qt widget that uses OpenGL graphics so we +### check $build_qt_gui instead of $build_qt_graphics here. +if test $build_qt_gui = no && test $build_fltk_graphics = no; then opengl_graphics=no else opengl_graphics=yes @@ -2676,7 +2690,7 @@ fi], []) if test $ENABLE_DOCS = yes; then - if test $opengl_graphics = no || test "$have_qt_opengl_offscreen" = no; then + if test $opengl_graphics = no; then if test -n "$warn_gnuplot"; then ENABLE_DOCS=no warn_docs_graphics="building documentation disabled because no suitable graphics toolkit is available; make dist will fail." @@ -2730,10 +2744,10 @@ ### Determine whether libraries should be linked with visibility attributes. -ENABLE_LIB_VISIBILITY_FLAGS=no +ENABLE_LIB_VISIBILITY_FLAGS=yes AC_ARG_ENABLE(lib-visibility-flags, - [AS_HELP_STRING([--enable-lib-visibility-flags], - [build libraries with visibility flags (export only symbols from API)])], + [AS_HELP_STRING([--disable-lib-visibility-flags], + [don't build libraries with visibility flags (export all symbols)])], [case $enableval in yes) ENABLE_LIB_VISIBILITY_FLAGS=yes ;; no) ENABLE_LIB_VISIBILITY_FLAGS=no ;; @@ -2881,19 +2895,19 @@ ADDRESS_SANITIZER_ENABLED=yes for flag in $GCC_ADDRESS_SANITIZER_FLAGS; do OCTAVE_CC_FLAG([$flag], [ - WARN_CFLAGS="$WARN_CFLAGS $flag"; - AC_MSG_RESULT([adding $flag to WARN_CFLAGS])]) + XTRA_CFLAGS="$XTRA_CFLAGS $flag"; + AC_MSG_RESULT([adding $flag to XTRA_CFLAGS])]) done for flag in $GXX_ADDRESS_SANITIZER_FLAGS; do OCTAVE_CXX_FLAG([$flag], [ - WARN_CXXFLAGS="$WARN_CXXFLAGS $flag"; - AC_MSG_RESULT([adding $flag to WARN_CXXFLAGS])]) + XTRA_CXXFLAGS="$XTRA_CXXFLAGS $flag"; + AC_MSG_RESULT([adding $flag to XTRA_CXXFLAGS])]) done dnl FIXME: do we really need an LD-specific test, or is this good enough? for flag in $LD_ADDRESS_SANITIZER_FLAGS; do OCTAVE_CC_FLAG([$flag], [ - WARN_LDFLAGS="$WARN_LDFLAGS $flag"; - AC_MSG_RESULT([adding $flag to WARN_LDFLAGS])]) + XTRA_LDFLAGS="$XTRA_LDFLAGS $flag"; + AC_MSG_RESULT([adding $flag to XTRA_LDFLAGS])]) done fi AC_SUBST(ADDRESS_SANITIZER_ENABLED) @@ -3041,8 +3055,8 @@ OCTAVE_GUI_LINK_OPTS="" if test $build_qt_gui = yes; then - LIBOCTGUI_LINK_DEPS="$QT_LIBS $QT_OPENGL_LIBS" - LIBOCTGUI_LINK_OPTS="$QT_LDFLAGS $QT_OPENGL_LDFLAGS" + LIBOCTGUI_LINK_DEPS="$QT_LIBS" + LIBOCTGUI_LINK_OPTS="$QT_LDFLAGS" if test $link_all_deps = yes || test -n "$QT_LDFLAGS"; then LIBOCTGUI_LINK_DEPS="$LIBOCTGUI_LINK_DEPS $LIBOCTINTERP_LINK_DEPS" @@ -3161,6 +3175,8 @@ AC_CONFIG_FILES([ Makefile build-aux/check-subst-vars.sh:build-aux/check-subst-vars.in.sh + build-aux/find-defun-files.sh:build-aux/find-defun-files.in.sh + build-aux/find-files-with-tests.sh:build-aux/find-files-with-tests.in.sh doc/doxyhtml/Doxyfile libgnu/Makefile test/Makefile @@ -3207,7 +3223,7 @@ Lex libraries: $LEXLIB LIBS: $LIBS LDFLAGS: $LDFLAGS - Extra LDFLAGS: $WARN_LDFLAGS + Extra LDFLAGS: $XTRA_LDFLAGS $WARN_LDFLAGS AMD CPPFLAGS: $AMD_CPPFLAGS AMD LDFLAGS: $AMD_LDFLAGS @@ -3287,7 +3303,6 @@ Qt CPPFLAGS: $QT_CPPFLAGS Qt LDFLAGS: $QT_LDFLAGS Qt GUI libraries: $QT_LIBS - Qt OpenGL libraries: $QT_OPENGL_LIBS Qt moc: $MOC $MOCFLAGS Qt uic: $UIC $UICFLAGS Qt rcc: $RCC $RCCFLAGS diff -r e2911d0176dc -r 212145b8e5f0 doc/interpreter/basics.txi --- a/doc/interpreter/basics.txi Fri May 12 08:00:41 2023 +0200 +++ b/doc/interpreter/basics.txi Fri May 12 08:03:14 2023 +0200 @@ -391,11 +391,11 @@ properties). In other words, the system's locale charset is in effect until a user manually sets the m-file encoding (e.g., in one of the startup files) and triggers re-parsing of any relevant m-files. Octave can be forced to use a -new encoding with the undocumented function @code{__mfile_encoding__}: +new encoding with the function @code{mfile_encoding}: @example @group -__mfile_encoding__ ("utf-8"); # set new encoding +mfile_encoding ("utf-8"); # set new encoding clear ("functions"); # re-parse all .m files in the new encoding @end group @end example diff -r e2911d0176dc -r 212145b8e5f0 doc/interpreter/contributors.in --- a/doc/interpreter/contributors.in Fri May 12 08:00:41 2023 +0200 +++ b/doc/interpreter/contributors.in Fri May 12 08:03:14 2023 +0200 @@ -101,6 +101,7 @@ Massimiliano Fasi Stephen Fegan Ramon Garcia Fernandez +Kasper H. Filtenborg Torsten Finke David Finkel Guillaume Flandin diff -r e2911d0176dc -r 212145b8e5f0 doc/interpreter/external.txi --- a/doc/interpreter/external.txi Fri May 12 08:00:41 2023 +0200 +++ b/doc/interpreter/external.txi Fri May 12 08:03:14 2023 +0200 @@ -312,19 +312,19 @@ circumstances the user might prefer to access the data of the array or matrix directly through the @code{fortran_vec} method discussed below. -@deftypefn {Method} {octave_idx_type} numel (void) const +@deftypefn {Method} {octave_idx_type} numel () const The total number of elements in the matrix or array. @end deftypefn -@deftypefn {Method} {size_t} byte_size (void) const +@deftypefn {Method} {size_t} byte_size () const The number of bytes used to store the matrix or array. @end deftypefn -@deftypefn {Method} {dim_vector} dims (void) const +@deftypefn {Method} {dim_vector} dims () const The dimensions of the matrix or array in value of type @code{dim_vector}. @end deftypefn -@deftypefn {Method} {int} ndims (void) const +@deftypefn {Method} {int} ndims () const The number of dimensions of the matrix or array. Matrices are always 2-D, but arrays can be N-dimensional. @end deftypefn @@ -336,7 +336,7 @@ of rows and columns in the matrix. @end deftypefn -@deftypefn {Method} {T*} fortran_vec (void) +@deftypefn {Method} {T*} fortran_vec () This method returns a pointer to the underlying data of the matrix or array so that it can be manipulated directly, either within Octave or by an external library. diff -r e2911d0176dc -r 212145b8e5f0 doc/interpreter/func.txi --- a/doc/interpreter/func.txi Fri May 12 08:00:41 2023 +0200 +++ b/doc/interpreter/func.txi Fri May 12 08:03:14 2023 +0200 @@ -926,6 +926,8 @@ @DOCSTRING(dir_in_loadpath) +@DOCSTRING(mfile_encoding) + @DOCSTRING(dir_encoding) @node Subfunctions @@ -1955,7 +1957,7 @@ @example @group -toupper lower_case_arg +upper lower_case_arg @result{} ans = LOWER_CASE_ARG @end group @end example @@ -1967,9 +1969,9 @@ @example @group strvar = "hello world"; -toupper strvar +upper strvar @result{} ans = STRVAR -toupper (strvar) +upper (strvar) @result{} ans = HELLO WORLD @end group @end example diff -r e2911d0176dc -r 212145b8e5f0 doc/interpreter/geometryimages.m --- a/doc/interpreter/geometryimages.m Fri May 12 08:00:41 2023 +0200 +++ b/doc/interpreter/geometryimages.m Fri May 12 08:03:14 2023 +0200 @@ -154,8 +154,7 @@ function set_graphics_toolkit () if (isempty (available_graphics_toolkits ())) error ("no graphics toolkit available for plotting"); - elseif (strcmp ("qt", graphics_toolkit ()) - && __have_feature__ ("QT_OFFSCREEN")) + elseif (strcmp ("qt", graphics_toolkit ())) ## Use qt with QOffscreenSurface for plot elseif (! strcmp ("gnuplot", graphics_toolkit ())) if (! any (strcmp ("gnuplot", available_graphics_toolkits ()))) diff -r e2911d0176dc -r 212145b8e5f0 doc/interpreter/interpimages.m --- a/doc/interpreter/interpimages.m Fri May 12 08:00:41 2023 +0200 +++ b/doc/interpreter/interpimages.m Fri May 12 08:03:14 2023 +0200 @@ -96,8 +96,7 @@ function set_graphics_toolkit () if (isempty (available_graphics_toolkits ())) error ("no graphics toolkit available for plotting"); - elseif (strcmp ("qt", graphics_toolkit ()) - && __have_feature__ ("QT_OFFSCREEN")) + elseif (strcmp ("qt", graphics_toolkit ())) ## Use qt with QOffscreenSurface for plot elseif (! strcmp ("gnuplot", graphics_toolkit ())) if (! any (strcmp ("gnuplot", available_graphics_toolkits ()))) diff -r e2911d0176dc -r 212145b8e5f0 doc/interpreter/linalg.txi --- a/doc/interpreter/linalg.txi Fri May 12 08:00:41 2023 +0200 +++ b/doc/interpreter/linalg.txi Fri May 12 08:03:14 2023 +0200 @@ -211,6 +211,8 @@ @DOCSTRING(kron) +@DOCSTRING(tensorprod) + @DOCSTRING(blkmm) @DOCSTRING(sylvester) diff -r e2911d0176dc -r 212145b8e5f0 doc/interpreter/module.mk --- a/doc/interpreter/module.mk Fri May 12 08:00:41 2023 +0200 +++ b/doc/interpreter/module.mk Fri May 12 08:03:14 2023 +0200 @@ -369,7 +369,6 @@ @$(GREP) '#define HAVE_CHOLMOD 1' $(top_builddir)/config.h > /dev/null || { echo "Documentation creation requires missing CHOLMOD library. Cannot package distribution!" ; exit 1; } @$(GREP) '#define HAVE_UMFPACK 1' $(top_builddir)/config.h > /dev/null || { echo "Documentation creation requires missing UMFPACK library. Cannot package distribution!" ; exit 1; } @$(GREP) '#define HAVE_QHULL 1' $(top_builddir)/config.h > /dev/null || { echo "Documentation creation requires missing QHULL library. Cannot package distribution!" ; exit 1; } - @$(GREP) '#define HAVE_QT_OFFSCREEN 1' $(top_builddir)/config.h > /dev/null || { echo "Documentation creation requires Qt offscreen OpenGL rendering. Cannot package distribution!" ; exit 1; } $(MUNGED_TEXI_SRC): $(DOCSTRING_FILES) diff -r e2911d0176dc -r 212145b8e5f0 doc/interpreter/numbers.txi --- a/doc/interpreter/numbers.txi Fri May 12 08:00:41 2023 +0200 +++ b/doc/interpreter/numbers.txi Fri May 12 08:03:14 2023 +0200 @@ -871,6 +871,8 @@ @DOCSTRING(isprime) +@DOCSTRING(isuniform) + If instead of knowing properties of variables, you wish to know which variables are defined and to gather other information about the workspace itself, @pxref{Status of Variables}. diff -r e2911d0176dc -r 212145b8e5f0 doc/interpreter/plotimages.m --- a/doc/interpreter/plotimages.m Fri May 12 08:00:41 2023 +0200 +++ b/doc/interpreter/plotimages.m Fri May 12 08:03:14 2023 +0200 @@ -154,8 +154,7 @@ function set_graphics_toolkit () if (isempty (available_graphics_toolkits ())) error ("no graphics toolkit available for plotting"); - elseif (strcmp ("qt", graphics_toolkit ()) - && __have_feature__ ("QT_OFFSCREEN")) + elseif (strcmp ("qt", graphics_toolkit ())) ## Use qt with QOffscreenSurface for plot elseif (! strcmp ("gnuplot", graphics_toolkit ())) if (! any (strcmp ("gnuplot", available_graphics_toolkits ()))) diff -r e2911d0176dc -r 212145b8e5f0 doc/interpreter/sparseimages.m --- a/doc/interpreter/sparseimages.m Fri May 12 08:00:41 2023 +0200 +++ b/doc/interpreter/sparseimages.m Fri May 12 08:03:14 2023 +0200 @@ -255,8 +255,7 @@ function set_graphics_toolkit () if (isempty (available_graphics_toolkits ())) error ("no graphics toolkit available for plotting"); - elseif (strcmp ("qt", graphics_toolkit ()) - && __have_feature__ ("QT_OFFSCREEN")) + elseif (strcmp ("qt", graphics_toolkit ())) ## Use qt with QOffscreenSurface for plot elseif (! strcmp ("gnuplot", graphics_toolkit ())) if (! any (strcmp ("gnuplot", available_graphics_toolkits ()))) diff -r e2911d0176dc -r 212145b8e5f0 doc/interpreter/splineimages.m --- a/doc/interpreter/splineimages.m Fri May 12 08:00:41 2023 +0200 +++ b/doc/interpreter/splineimages.m Fri May 12 08:03:14 2023 +0200 @@ -186,8 +186,7 @@ function set_graphics_toolkit () if (isempty (available_graphics_toolkits ())) error ("no graphics toolkit available for plotting"); - elseif (strcmp ("qt", graphics_toolkit ()) - && __have_feature__ ("QT_OFFSCREEN")) + elseif (strcmp ("qt", graphics_toolkit ())) ## Use qt with QOffscreenSurface for plot elseif (! strcmp ("gnuplot", graphics_toolkit ())) if (! any (strcmp ("gnuplot", available_graphics_toolkits ()))) diff -r e2911d0176dc -r 212145b8e5f0 doc/interpreter/strings.txi --- a/doc/interpreter/strings.txi Fri May 12 08:00:41 2023 +0200 +++ b/doc/interpreter/strings.txi Fri May 12 08:03:14 2023 +0200 @@ -254,9 +254,9 @@ The following functions are useful to perform common String operations. -@DOCSTRING(tolower) +@DOCSTRING(lower) -@DOCSTRING(toupper) +@DOCSTRING(upper) @DOCSTRING(deblank) diff -r e2911d0176dc -r 212145b8e5f0 doc/liboctave/range.texi --- a/doc/liboctave/range.texi Fri May 12 08:00:41 2023 +0200 +++ b/doc/liboctave/range.texi Fri May 12 08:03:14 2023 +0200 @@ -20,35 +20,4 @@ @chapter Ranges @cindex ranges -@deftypefn {} {} Range (void) -@deftypefnx {} {} Range (const Range &@var{r}) -@deftypefnx {} {} Range (double @var{b}, double @var{l}) -@deftypefnx {} {} Range (double @var{b}, double @var{l}, double @var{i}) -@end deftypefn - -@deftypefn {} double base (void) const -@deftypefnx {} double limit (void) const -@deftypefnx {} double inc (void) const -@end deftypefn - -@deftypefn {} void set_base (double @var{b}) -@deftypefnx {} void set_limit (double @var{l}) -@deftypefnx {} void set_inc (double @var{i}) -@end deftypefn - -@deftypefn {} int nelem (void) const -@end deftypefn - -@deftypefn {} double min (void) const -@deftypefnx {} double max (void) const -@end deftypefn - -@deftypefn {} void sort (void) -@end deftypefn - -@deftypefn {} {ostream&} {operator <<} (ostream &@var{os}, const Range &@var{r}) -@deftypefnx {} {istream&} {operator >>} (istream &@var{is}, Range &@var{r}) -@end deftypefn - -@deftypefn {} void print_range (void) -@end deftypefn +FIXME: The @code{Range} class is obsolete. diff -r e2911d0176dc -r 212145b8e5f0 etc/NEWS.8.md diff -r e2911d0176dc -r 212145b8e5f0 etc/NEWS.9.md --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/etc/NEWS.9.md Fri May 12 08:03:14 2023 +0200 @@ -0,0 +1,197 @@ +Summary of important user-visible changes for version 9 (yyyy-mm-dd): +--------------------------------------------------------------------- + +### General improvements + +- `oruntests`: The current directory now changes to the directory +containing the files with the tests for the duration of the test. This +aligns the behavior of this function with Octave's test suite. This also +means that the file encoding specified in the `.oct-config` file for the +respective directory is taken into account for the tests. + +- `dec2base`, `dec2bin`, and `dec2hex` have all been overhauled. All three +functions now accommodate negative inputs and fractional inputs, and repeated +code between the functions has been reduced or eliminated. Previously only +`dec2bin` and `dec2hex` accepted negative inputs but `dec2base` did not, and +none of the three accepted fractional inputs. But now, +`dec2base (100*pi, 16, 4, 6)` for exampele returns a base-16 string with four +places for the integer part and six places for the fractional part. Omitting +the number of decimal places (the fourth input) retains old behavior for +backward compatibility, except that non-integer inputs will no longer error. + +- `quiver` and `quiver3` now properly plot non-float numeric inputs by +internally recasting them to 'double' (bug #59695). Both functions now +honor a previously ignored scaling factor input when there is only a +single arrow (bug #39552), and `quiver3` no longer produces an error when a +scaling factor is input without x and y inputs. Both functions now also +accept a scale factor of "off" which is equivalent to setting it to 0. +When a linestyle with a base marker is set suppressing arrowhead display, +subsequent name-value property pairs in the quiver/quiver3 function call +will no longer turn arrowhead display back on (bug #64143). The linewdith +property now also affect the line width of the base marker. + +- The `inputParser` function has been re-architected for a 60% performance +improvement. + +### Graphical User Interface + +### Graphics backend + +* The `set` function now accepts any combination of name/value pairs, +cell array of names / cell array of values, or property structures. +This change is Matlab-compatible. + +* When the `hold` function is used without arguments to toggle the current +state the resulting value is now displayed in the Command Window for +informational purposes. + +### Matlab compatibility + +- The `inputParser` function now implements the `PartialMatching` property +for `Parameter` and `Switch` names. For Matlab compatibility, +`PartialMatching` is now set to true by default which may change the behavior +of existing code. + +- Overhauled `mean`, `median`, `var`, and `std` functions have been imported +from statistics package v1.5.4 to compatibly implement 'nanflag' (bug #50571), +'all' (bug #58116), and 'vecdim' (bug #58089) options, preserve output class, +and match expected output behavior for empty (bug #50583) and sparse inputs +(bug #63291). Both `median` and `mean` can handle large int values without +overflow or precision concerns (bug #54567), and `mean` avoids errors due to +limits of single precision by processing as doubles (bug #63848). `median` +has also adopted the 'outtype' option from `mean`. + +- `mad` function now produces Matlab compatible output using improved `mean` +and `median` functions. 'vecdim' and 'all' options are now supported. `mad` +ignores all NaN values (using 'omitnan' mean/median option) and produces +expected output behavior for empty inputs. + +- `mode` now produces Matlab compatible output for empty inputs (bug #50583). + +- `normalize` now produces Matlab compatible output for inputs containing NaN +values (bug #50571). + +- `cov` now processes the input form cov(x,y) with two separate data arrays +x and y, as cov(x(:),y(:)) to maintain Matlab compatibility. It also accepts +a NANFLAG option to allow ignoring NaN entries in input data (bug #50571) +and produces Matlab compatible outputs for empty inputs (bug #50583). `corr` +and `corrcoef` internal code has been adapted to the new `cov` behavior with +no change to user interface. Packages using the octave core's `cov` that rely +on the previous calling form may need to make similar adaptations. Calls for +cov(x) with a vector x expecting a scalar return can get the previous results +from `cov(x)(2)`, and calls to cov(x,y) with x and y matrices expecting +columnwise covariance calculation can obtain the previous results using +`cov([x,y])(1:nx, nx+1:end)`, where nx = columns(x). + +- `qz` now handles input and output arguments in a Matlab compatible +way. It always computes the complex QZ decomposition if there are only +two input arguments, and it accepts an optional third input argument +'real' or 'complex' to select the type of decomposition. The output +arguments are always in the same order independently of the input +arguments, and the generalized eigenvalues are no longer returned (one +can use the `ordeig` function for that purpose). The optional reordering +of the generalized eigenvalues has been removed (one can use the `ordqz` +function for that purpose). + +### Alphabetical list of new functions added in Octave 9 + +* `isuniform` +* `tensorprod` + +### Deprecated functions, properties, and operators + +The following functions and properties have been deprecated in Octave 9 +and will be removed from Octave 11 (or whatever version is the second +major release after 9): + +- Functions + + Function | Replacement + -----------------------|------------------ + +- Properties + + The following property names are discouraged, but there is no fixed + date for their removal. + + Object | Property | Replacement + -----------------|-------------|------------ + +- Core + + * The `idx_vector::bool()` function is obsolete and always returns true. +Any uses can simply be removed from existing code with no loss of function. + + * The `all_ok(const Array&)` function in `Array-util.h` +is obsolete and always returns true. Any uses can simply be removed from +existing code with no loss of function. + + * The member variable `octave_base_value::count` is deprecated and will be removed from Octave 11. Replace all instances with the new name `m_count`. + +The following features were deprecated in Octave 7 and have been removed +from Octave 9. + +- Functions + + Function | Replacement + ---------------------------|------------------ + disable_diagonal_matrix | optimize_diagonal_matrix + disable_permutation_matrix | optimize_permutation_matrix + disable_range | optimize_range + +- Operators + + Operator | Replacement + ---------|------------ + .+ | + + .+= | += + .- | - + .-= | -= + ** | ^ + **= | ^= + .** | .^ + .**= | .^= + +- Interpreter + + * The use of `'...'` for line continuations *inside* double-quoted + strings has been removed. Use `'\'` for line continuations inside strings + instead. + + * The use of `'\'` as a line continuation *outside* of double-quoted + strings has been removed. Use `'...'` for line continuations instead. + + * Support for trailing whitespace after a `'\'` line continuation has been + removed. Delete unnecessary trailing whitespace. + +- For plot functions, the use of numbers to select line colors in + shorthand formats was an undocumented feature that was removed in Octave 9. + +- The environment variable used by `mkoctfile` for linker flags is now + `LDFLAGS` rather than `LFLAGS`. `LFLAGS` was deprecated in Octave 6 + and has been removed. + +Summary of bugs fixed for version 9.1.0 (yyyy-mm-dd): +---------------------------------------------------- + +- Bugfixes to `whos -file`, `urlread`, `mat2cell`, `set`. + +- Memory usage reduced for `movfun` by eliminating temporary copies. + +- Memory usage reduced when saving to file, preventing OOM and data loss. + +- Several race conditions removed in signal handler. + +- Performance improvements: avoid unnecessary string construction, use + static casts instead of dynamic casts where possible. + +### Old release news + +- [Octave 8.x](etc/NEWS.8) +- [Octave 7.x](etc/NEWS.7) +- [Octave 6.x](etc/NEWS.6) +- [Octave 5.x](etc/NEWS.5) +- [Octave 4.x](etc/NEWS.4) +- [Octave 3.x](etc/NEWS.3) +- [Octave 2.x](etc/NEWS.2) +- [Octave 1.x](etc/NEWS.1) diff -r e2911d0176dc -r 212145b8e5f0 etc/module.mk --- a/etc/module.mk Fri May 12 08:00:41 2023 +0200 +++ b/etc/module.mk Fri May 12 08:03:14 2023 +0200 @@ -13,6 +13,7 @@ %reldir%/NEWS.6.md \ %reldir%/NEWS.7.md \ %reldir%/NEWS.8.md \ + %reldir%/NEWS.9.md \ %reldir%/gdbinit %canon_reldir%_EXTRA_DIST += \ diff -r e2911d0176dc -r 212145b8e5f0 examples/code/embedded.cc --- a/examples/code/embedded.cc Fri May 12 08:00:41 2023 +0200 +++ b/examples/code/embedded.cc Fri May 12 08:03:14 2023 +0200 @@ -5,7 +5,7 @@ #include int -main (void) +main () { // Create interpreter. diff -r e2911d0176dc -r 212145b8e5f0 examples/code/make_int.cc --- a/examples/code/make_int.cc Fri May 12 08:00:41 2023 +0200 +++ b/examples/code/make_int.cc Fri May 12 08:03:14 2023 +0200 @@ -37,7 +37,7 @@ { public: - octave_integer (void) + octave_integer () : octave_base_dld_value (), scalar (0) { } octave_integer (int i) @@ -46,40 +46,35 @@ octave_integer (const octave_integer& s) : octave_base_dld_value (), scalar (s.scalar) { } - ~octave_integer (void) = default; - - octave_base_value * clone (void) { return new octave_integer (*this); } + ~octave_integer () = default; -#if 0 - void *operator new (std::size_t size); - void operator delete (void *p, std::size_t size); -#endif + octave_base_value * clone () { return new octave_integer (*this); } octave::idx_vector index_vector (bool) const { return octave::idx_vector ((double) scalar); } - int rows (void) const { return 1; } - int columns (void) const { return 1; } + int rows () const { return 1; } + int columns () const { return 1; } - bool is_constant (void) const { return true; } + bool is_constant () const { return true; } - bool is_defined (void) const { return true; } - bool is_real_scalar (void) const { return true; } + bool is_defined () const { return true; } + bool is_real_scalar () const { return true; } - octave_value all (void) const { return (double) (scalar != 0); } - octave_value any (void) const { return (double) (scalar != 0); } + octave_value all () const { return (double) (scalar != 0); } + octave_value any () const { return (double) (scalar != 0); } - bool is_real_type (void) const { return true; } - bool is_scalar_type (void) const { return true; } - bool isnumeric (void) const { return true; } + bool is_real_type () const { return true; } + bool is_scalar_type () const { return true; } + bool isnumeric () const { return true; } - bool valid_as_scalar_index (void) const + bool valid_as_scalar_index () const { return scalar == 1; } - bool valid_as_zero_index (void) const + bool valid_as_zero_index () const { return scalar == 0; } - bool is_true (void) const { return (scalar != 0); } + bool is_true () const { return (scalar != 0); } double double_value (bool = false) const { return (double) scalar; } @@ -92,17 +87,17 @@ ComplexMatrix complex_matrix_value (bool = false) const { return ComplexMatrix (1, 1, Complex (scalar)); } - octave_value gnot (void) const { return octave_value ((double) ! scalar); } + octave_value gnot () const { return octave_value ((double) ! scalar); } - octave_value uminus (void) const { return new octave_integer (- scalar); } + octave_value uminus () const { return new octave_integer (- scalar); } - octave_value transpose (void) const { return new octave_integer (scalar); } + octave_value transpose () const { return new octave_integer (scalar); } - octave_value hermitian (void) const { return new octave_integer (scalar); } + octave_value hermitian () const { return new octave_integer (scalar); } - void increment (void) { ++scalar; } + void increment () { ++scalar; } - void decrement (void) { --scalar; } + void decrement () { --scalar; } void print (std::ostream& os, bool pr_as_read_syntax = false); diff -r e2911d0176dc -r 212145b8e5f0 examples/code/standalone.cc --- a/examples/code/standalone.cc Fri May 12 08:00:41 2023 +0200 +++ b/examples/code/standalone.cc Fri May 12 08:03:14 2023 +0200 @@ -2,7 +2,7 @@ #include int -main (void) +main () { std::cout << "Hello Octave world!\n"; diff -r e2911d0176dc -r 212145b8e5f0 examples/code/standalonebuiltin.cc --- a/examples/code/standalonebuiltin.cc Fri May 12 08:00:41 2023 +0200 +++ b/examples/code/standalonebuiltin.cc Fri May 12 08:03:14 2023 +0200 @@ -3,7 +3,7 @@ #include int -main (void) +main () { int n = 2; Matrix a_matrix = Matrix (n, n); diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/BaseControl.cc --- a/libgui/graphics/BaseControl.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/BaseControl.cc Fri May 12 08:03:14 2023 +0200 @@ -72,8 +72,8 @@ QColor bcol = Utils::fromRgb (props.get_backgroundcolor_rgb ()); QColor fcol = Utils::fromRgb (props.get_foregroundcolor_rgb ()); QString qss = QString (":enabled { background: %1 none;\n" - "color: %2; }") - .arg(bcol.name ()).arg (fcol.name ()); + "color: %2; }") + .arg(bcol.name ()).arg (fcol.name ()); w->setStyleSheet(qss); return; } @@ -95,8 +95,8 @@ QColor bcol = Utils::fromRgb (props.get_backgroundcolor_rgb ()); QColor fcol = Utils::fromRgb (props.get_foregroundcolor_rgb ()); QString qss = QString (":enabled { background: %1 none;\n" - "color: %2; }") - .arg(bcol.name ()).arg (fcol.name ()); + "color: %2; }") + .arg(bcol.name ()).arg (fcol.name ()); w->setStyleSheet(qss); return; } @@ -115,10 +115,9 @@ w->setPalette (p); } -BaseControl::BaseControl (octave::base_qobject& oct_qobj, - octave::interpreter& interp, +BaseControl::BaseControl (octave::interpreter& interp, const graphics_object& go, QWidget *w) - : Object (oct_qobj, interp, go, w), m_normalizedFont (false), + : Object (interp, go, w), m_normalizedFont (false), m_keyPressHandlerDefined (false) { qObject ()->setObjectName ("UIControl"); @@ -151,11 +150,11 @@ m_normalizedFont = up.fontunits_is ("normalized"); } -BaseControl::~BaseControl (void) +BaseControl::~BaseControl () { } void -BaseControl::redraw (void) +BaseControl::redraw () { update (uicontrol::properties::ID_POSITION); } diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/BaseControl.h --- a/libgui/graphics/BaseControl.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/BaseControl.h Fri May 12 08:03:14 2023 +0200 @@ -33,23 +33,22 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; class interpreter; class BaseControl : public Object { public: - BaseControl (octave::base_qobject& oct_qobj, octave::interpreter& interp, + BaseControl (octave::interpreter& interp, const graphics_object& go, QWidget *w); - ~BaseControl (void); + ~BaseControl (); - Container * innerContainer (void) { return nullptr; } + Container * innerContainer () { return nullptr; } bool eventFilter (QObject *watched, QEvent *e); protected: void init (QWidget *w, bool callBase = false); - void redraw (void); + void redraw (); void update (int pId); private: diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/ButtonControl.cc --- a/libgui/graphics/ButtonControl.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/ButtonControl.cc Fri May 12 08:03:14 2023 +0200 @@ -39,11 +39,10 @@ OCTAVE_BEGIN_NAMESPACE(octave) -ButtonControl::ButtonControl (octave::base_qobject& oct_qobj, - octave::interpreter& interp, +ButtonControl::ButtonControl (octave::interpreter& interp, const graphics_object& go, QAbstractButton *btn) -: BaseControl (oct_qobj, interp, go, btn), m_blockCallback (false) + : BaseControl (interp, go, btn), m_blockCallback (false) { uicontrol::properties& up = properties (); @@ -64,7 +63,7 @@ connect (btn, &QAbstractButton::toggled, this, &ButtonControl::toggled); } -ButtonControl::~ButtonControl (void) +ButtonControl::~ButtonControl () { } void @@ -144,7 +143,7 @@ } void -ButtonControl::clicked (void) +ButtonControl::clicked () { QAbstractButton *btn = qWidget (); diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/ButtonControl.h --- a/libgui/graphics/ButtonControl.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/ButtonControl.h Fri May 12 08:03:14 2023 +0200 @@ -32,7 +32,6 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; class interpreter; class ButtonControl : public BaseControl @@ -40,15 +39,15 @@ Q_OBJECT public: - ButtonControl (octave::base_qobject& oct_qobj, octave::interpreter& interp, + ButtonControl (octave::interpreter& interp, const graphics_object& go, QAbstractButton *btn); - ~ButtonControl (void); + ~ButtonControl (); protected: void update (int pId); private slots: - void clicked (void); + void clicked (); void toggled (bool checked); private: diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/ButtonGroup.cc --- a/libgui/graphics/ButtonGroup.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/ButtonGroup.cc Fri May 12 08:03:14 2023 +0200 @@ -45,9 +45,6 @@ #include "QtHandlesUtils.h" #include "qt-graphics-toolkit.h" -#include "octave-qobject.h" -#include "octave-qtutils.h" - #include "interpreter.h" #include "oct-map.h" @@ -99,8 +96,7 @@ } ButtonGroup * -ButtonGroup::create (octave::base_qobject& oct_qobj, - octave::interpreter& interp, const graphics_object& go) +ButtonGroup::create (octave::interpreter& interp, const graphics_object& go) { Object *parent = parentObject (interp, go); @@ -111,7 +107,7 @@ if (container) { QFrame *frame = new QFrame (container); - return new ButtonGroup (oct_qobj, interp, go, + return new ButtonGroup (interp, go, new QButtonGroup (frame), frame); } } @@ -119,11 +115,10 @@ return nullptr; } -ButtonGroup::ButtonGroup (octave::base_qobject& oct_qobj, - octave::interpreter& interp, +ButtonGroup::ButtonGroup (octave::interpreter& interp, const graphics_object& go, QButtonGroup *buttongroup, QFrame *frame) - : Object (oct_qobj, interp, go, frame), m_hiddenbutton (nullptr), + : Object (interp, go, frame), m_hiddenbutton (nullptr), m_container (nullptr), m_title (nullptr), m_blockUpdates (false) { uibuttongroup::properties& pp = properties (); @@ -143,7 +138,7 @@ m_hiddenbutton->hide (); m_buttongroup->addButton (m_hiddenbutton); - m_container = new Container (frame, oct_qobj, interp); + m_container = new Container (frame, interp); m_container->canvas (m_handle); connect (m_container, SIGNAL (interpeter_event (const fcn_callback&)), @@ -178,7 +173,7 @@ QTimer::singleShot (0, frame, &QFrame::show); // FIXME: What is the intent here? QButtonGroup::show is not a // member of QButtonGroup. - QTimer::singleShot (0, buttongroup, SLOT (show (void))); + QTimer::singleShot (0, buttongroup, SLOT (show ())); } else frame->hide (); @@ -188,7 +183,7 @@ this, &ButtonGroup::buttonClicked); } -ButtonGroup::~ButtonGroup (void) +ButtonGroup::~ButtonGroup () { } bool @@ -379,7 +374,7 @@ Object *selectedObject = qt_graphics_toolkit::toolkitObject (go); ToggleButtonControl *toggle = static_cast - (selectedObject); + (selectedObject); RadioButtonControl *radio = static_cast(selectedObject); if (toggle) { @@ -404,7 +399,7 @@ } void -ButtonGroup::redraw (void) +ButtonGroup::redraw () { update (uibuttongroup::properties::ID_POSITION); @@ -416,7 +411,7 @@ } void -ButtonGroup::updateLayout (void) +ButtonGroup::updateLayout () { uibuttongroup::properties& pp = properties (); QFrame *frame = qWidget (); @@ -457,7 +452,7 @@ } void -ButtonGroup::selectNothing (void) +ButtonGroup::selectNothing () { m_hiddenbutton->setChecked (true); } diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/ButtonGroup.h --- a/libgui/graphics/ButtonGroup.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/ButtonGroup.h Fri May 12 08:03:14 2023 +0200 @@ -36,7 +36,6 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; class interpreter; class Container; @@ -46,33 +45,33 @@ Q_OBJECT public: - ButtonGroup (octave::base_qobject& oct_qobj, octave::interpreter& interp, + ButtonGroup (octave::interpreter& interp, const graphics_object& go, QButtonGroup *buttongroup, QFrame *frame); - ~ButtonGroup (void); + ~ButtonGroup (); - Container * innerContainer (void) { return m_container; } + Container * innerContainer () { return m_container; } bool eventFilter (QObject *watched, QEvent *event); static ButtonGroup * - create (octave::base_qobject& oct_qobj, octave::interpreter& interp, + create (octave::interpreter& interp, const graphics_object& go); void addButton (QAbstractButton *btn); - void selectNothing (void); + void selectNothing (); protected: void update (int pId); - void redraw (void); + void redraw (); private slots: void buttonToggled (bool toggled); void buttonClicked (QAbstractButton *btn); private: - void updateLayout (void); + void updateLayout (); private: QButtonGroup *m_buttongroup; diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/Canvas.cc --- a/libgui/graphics/Canvas.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/Canvas.cc Fri May 12 08:03:14 2023 +0200 @@ -43,7 +43,7 @@ #include "qt-graphics-toolkit.h" #include "annotation-dialog.h" -#include "octave-qobject.h" +#include "gui-settings.h" #include "qt-interpreter-events.h" #include "builtin-defun-decls.h" @@ -76,9 +76,9 @@ QCursor Canvas::make_cursor (const QString& name, int hot_x, int hot_y) { - octave::resource_manager& rmgr = m_octave_qobj.get_resource_manager (); + gui_settings settings; - QIcon icon = rmgr.icon (name); + QIcon icon = settings.icon (name); return QCursor (icon.pixmap (22, 22), hot_x, hot_y); } @@ -172,9 +172,9 @@ } /* - Two updateCurrentPoint() routines are required: - 1) Used for QMouseEvents where cursor position data is in callback from Qt. - 2) Used for QKeyEvents where cursor position must be determined. + Two updateCurrentPoint() routines are required: + 1) Used for QMouseEvents where cursor position data is in callback from Qt. + 2) Used for QKeyEvents where cursor position must be determined. */ void Canvas::updateCurrentPoint (const graphics_object& fig, @@ -272,7 +272,7 @@ } void -Canvas::canvasPaintEvent (void) +Canvas::canvasPaintEvent () { if (! m_redrawBlocked) { @@ -621,9 +621,9 @@ // Make selected axes current bool valid_axes = axesObj.valid_object () - && axesObj.get_properties ().handlevisibility_is ("on") - && axesObj.get_properties ().get_tag () != "legend" - && axesObj.get_properties ().get_tag () != "colorbar"; + && axesObj.get_properties ().handlevisibility_is ("on") + && axesObj.get_properties ().get_tag () != "legend" + && axesObj.get_properties ().get_tag () != "colorbar"; if (valid_axes) Utils::properties
(figObj) @@ -868,7 +868,7 @@ octave_value_list props = ovl ("textbox", bb); - annotation_dialog anno_dlg (m_octave_qobj, w, props); + annotation_dialog anno_dlg (w, props); if (anno_dlg.exec () == QDialog::Accepted) { @@ -877,13 +877,13 @@ emit interpreter_event ([=] (octave::interpreter& interp) - { - // INTERPRETER THREAD + { + // INTERPRETER THREAD - interp.feval ("annotation", props); + interp.feval ("annotation", props); - redraw (); - }); + redraw (); + }); } } } @@ -946,18 +946,14 @@ if (axesObj.get_properties ().handlevisibility_is ("on")) { Utils::properties
(figObj) - .set_currentaxes (axesObj.get_handle ().as_octave_value ()); + .set_currentaxes (axesObj.get_handle ().as_octave_value ()); if (zoom_enabled (figObj)) { -#if defined (HAVE_QWHEELEVENT_ANGLEDELTA) if (event->angleDelta().y () > 0) -#else - if (event->delta () > 0) -#endif - newMouseMode = ZoomInMode; - else - newMouseMode = ZoomOutMode; + newMouseMode = ZoomInMode; + else + newMouseMode = ZoomOutMode; mode = zoom_mode (figObj); } @@ -996,11 +992,7 @@ { axes::properties& ap = Utils::properties (axesObj); -#if defined (HAVE_QWHEELEVENT_ANGLEDELTA) double factor = (event->angleDelta().y () > 0 ? 0.1 : -0.1); -#else - double factor = (event->delta () > 0 ? 0.1 : -0.1); -#endif if (event->modifiers () == Qt::NoModifier && mode != "horizontal") @@ -1085,12 +1077,12 @@ } Canvas * -Canvas::create (octave::base_qobject& oct_qobj, octave::interpreter& interp, +Canvas::create (octave::interpreter& interp, const graphics_handle& handle, QWidget *parent, const std::string& /* name */) { // Only OpenGL - return new GLCanvas (oct_qobj, interp, handle, parent); + return new GLCanvas (interp, handle, parent); } OCTAVE_END_NAMESPACE(octave) diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/Canvas.h --- a/libgui/graphics/Canvas.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/Canvas.h Fri May 12 08:03:14 2023 +0200 @@ -43,7 +43,6 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; class interpreter; class Canvas : public QObject @@ -52,13 +51,13 @@ public: enum EventMask - { - KeyPress = 0x01, - KeyRelease = 0x02 - }; + { + KeyPress = 0x01, + KeyRelease = 0x02 + }; public: - virtual ~Canvas (void) = default; + virtual ~Canvas () = default; void redraw (bool sync = false); void blockRedraw (bool block = true); @@ -75,14 +74,13 @@ void setCursor (MouseMode mode, std::string fallback, QImage cdata, Matrix hotspot); - virtual QWidget * qWidget (void) = 0; + virtual QWidget * qWidget () = 0; static Canvas * - create (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_handle& handle, QWidget *parent, - const std::string& name); + create (octave::interpreter& interp, const graphics_handle& handle, + QWidget *parent, const std::string& name); - virtual uint8NDArray getPixels (void) { return do_getPixels (m_handle); }; + virtual uint8NDArray getPixels () { return do_getPixels (m_handle); }; signals: @@ -114,22 +112,18 @@ const graphics_handle& handle) = 0; protected: - Canvas (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_handle& handle) - : m_octave_qobj (oct_qobj), - m_interpreter (interp), - m_handle (handle), - m_redrawBlocked (false), - m_mouseMode (NoMode), - m_clickMode (false), - m_eventMask (0), - m_rectMode (false) + + Canvas (octave::interpreter& interp, const graphics_handle& handle) + : QObject (), m_interpreter (interp), m_handle (handle), + m_redrawBlocked (false), m_mouseMode (NoMode), m_clickMode (false), + m_eventMask (0), m_rectMode (false) { } +public: void canvasToggleAxes (const graphics_handle& handle); void canvasToggleGrid (const graphics_handle& handle); void canvasAutoAxes (const graphics_handle& handle); - void canvasPaintEvent (void); + void canvasPaintEvent (); void canvasMouseDoubleClickEvent (QMouseEvent *event); void canvasMouseMoveEvent (QMouseEvent *event); void canvasMousePressEvent (QMouseEvent *event); @@ -149,12 +143,12 @@ std::vector omit = std::vector ()); protected: - octave::base_qobject& m_octave_qobj; + octave::interpreter& m_interpreter; private: - QCursor make_cursor (const QString& name, int hot_x = -1, int hot_y = -1); + QCursor make_cursor (const QString& name, int hot_x = -1, int hot_y = -1); graphics_handle m_handle; bool m_redrawBlocked; diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/CheckBoxControl.cc --- a/libgui/graphics/CheckBoxControl.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/CheckBoxControl.cc Fri May 12 08:03:14 2023 +0200 @@ -32,13 +32,10 @@ #include "CheckBoxControl.h" #include "Container.h" -#include "octave-qobject.h" - OCTAVE_BEGIN_NAMESPACE(octave) CheckBoxControl * -CheckBoxControl::create (octave::base_qobject& oct_qobj, - octave::interpreter& interp, +CheckBoxControl::create (octave::interpreter& interp, const graphics_object& go) { Object *parent = parentObject (interp, go); @@ -48,17 +45,16 @@ Container *container = parent->innerContainer (); if (container) - return new CheckBoxControl (oct_qobj, interp, go, + return new CheckBoxControl (interp, go, new QCheckBox (container)); } return nullptr; } -CheckBoxControl::CheckBoxControl (octave::base_qobject& oct_obj, - octave::interpreter& interp, +CheckBoxControl::CheckBoxControl (octave::interpreter& interp, const graphics_object& go, QCheckBox *box) - : ButtonControl (oct_obj, interp, go, box) + : ButtonControl (interp, go, box) { uicontrol::properties& up = properties (); @@ -67,7 +63,7 @@ box->setCheckable (false); } -CheckBoxControl::~CheckBoxControl (void) +CheckBoxControl::~CheckBoxControl () { } void diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/CheckBoxControl.h --- a/libgui/graphics/CheckBoxControl.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/CheckBoxControl.h Fri May 12 08:03:14 2023 +0200 @@ -32,19 +32,17 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; class interpreter; class CheckBoxControl : public ButtonControl { public: - CheckBoxControl (octave::base_qobject& oct_qobj, - octave::interpreter& interp, const graphics_object& go, + CheckBoxControl (octave::interpreter& interp, const graphics_object& go, QCheckBox *box); - ~CheckBoxControl (void); + ~CheckBoxControl (); static CheckBoxControl * - create (octave::base_qobject& oct_qobj, octave::interpreter& interp, + create (octave::interpreter& interp, const graphics_object& go); protected: diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/Container.cc --- a/libgui/graphics/Container.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/Container.cc Fri May 12 08:03:14 2023 +0200 @@ -40,15 +40,13 @@ OCTAVE_BEGIN_NAMESPACE(octave) -Container::Container (QWidget *xparent, octave::base_qobject& oct_qobj, - octave::interpreter& interp) -: ContainerBase (xparent), m_octave_qobj (oct_qobj), - m_interpreter (interp), m_canvas (nullptr) +Container::Container (QWidget *xparent, octave::interpreter& interp) + : ContainerBase (xparent), m_interpreter (interp), m_canvas (nullptr) { setFocusPolicy (Qt::ClickFocus); } -Container::~Container (void) +Container::~Container () { } Canvas * @@ -66,7 +64,7 @@ { graphics_object fig = go.get_ancestor ("figure"); - m_canvas = Canvas::create (m_octave_qobj, m_interpreter, gh, this, + m_canvas = Canvas::create (m_interpreter, gh, this, fig.get ("renderer").string_value ()); connect (m_canvas, QOverload::of (&Canvas::interpreter_event), diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/Container.h --- a/libgui/graphics/Container.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/Container.h Fri May 12 08:03:14 2023 +0200 @@ -35,11 +35,6 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; -} - -OCTAVE_BEGIN_NAMESPACE(octave) - DECLARE_GENERICEVENTNOTIFY_SENDER(ContainerBase, QWidget); class Canvas; @@ -49,9 +44,8 @@ Q_OBJECT public: - Container (QWidget *parent, octave::base_qobject& oct_qobj, - octave::interpreter& interp); - ~Container (void); + Container (QWidget *parent, octave::interpreter& interp); + ~Container (); Canvas * canvas (const graphics_handle& handle, bool create = true); @@ -80,7 +74,6 @@ void resizeEvent (QResizeEvent *event); private: - octave::base_qobject& m_octave_qobj; octave::interpreter& m_interpreter; Canvas *m_canvas; }; diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/ContextMenu.cc --- a/libgui/graphics/ContextMenu.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/ContextMenu.cc Fri May 12 08:03:14 2023 +0200 @@ -33,15 +33,12 @@ #include "QtHandlesUtils.h" #include "qt-graphics-toolkit.h" -#include "octave-qobject.h" - #include "interpreter.h" OCTAVE_BEGIN_NAMESPACE(octave) ContextMenu * -ContextMenu::create (octave::base_qobject& oct_qobj, - octave::interpreter& interp, const graphics_object& go) +ContextMenu::create (octave::interpreter& interp, const graphics_object& go) { Object *xparent = parentObject (interp, go); @@ -49,16 +46,15 @@ { QWidget *w = xparent->qWidget (); - return new ContextMenu (oct_qobj, interp, go, new QMenu (w)); + return new ContextMenu (interp, go, new QMenu (w)); } return nullptr; } -ContextMenu::ContextMenu (octave::base_qobject& oct_qobj, - octave::interpreter& interp, +ContextMenu::ContextMenu (octave::interpreter& interp, const graphics_object& go, QMenu *xmenu) - : Object (oct_qobj, interp, go, xmenu) + : Object (interp, go, xmenu) { xmenu->setAutoFillBackground (true); @@ -66,7 +62,7 @@ connect (xmenu, &QMenu::aboutToHide, this, &ContextMenu::aboutToHide); } -ContextMenu::~ContextMenu (void) +ContextMenu::~ContextMenu () { } void @@ -100,20 +96,20 @@ } void -ContextMenu::aboutToShow (void) +ContextMenu::aboutToShow () { emit gh_callback_event (m_handle, "callback"); emit gh_set_event (m_handle, "visible", "on", false); } void -ContextMenu::aboutToHide (void) +ContextMenu::aboutToHide () { emit gh_set_event (m_handle, "visible", "off", false); } QWidget * -ContextMenu::menu (void) +ContextMenu::menu () { return qWidget (); } diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/ContextMenu.h --- a/libgui/graphics/ContextMenu.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/ContextMenu.h Fri May 12 08:03:14 2023 +0200 @@ -35,7 +35,6 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; class interpreter; class ContextMenu : public Object, public MenuContainer @@ -43,27 +42,27 @@ Q_OBJECT public: - ContextMenu (octave::base_qobject& oct_qobj, octave::interpreter& interp, + ContextMenu (octave::interpreter& interp, const graphics_object& go, QMenu *menu); - ~ContextMenu (void); + ~ContextMenu (); static ContextMenu * - create (octave::base_qobject& oct_qobj, octave::interpreter& interp, + create (octave::interpreter& interp, const graphics_object& go); static void executeAt (octave::interpreter& interp, const base_properties& props, const QPoint& pt); - Container * innerContainer (void) { return nullptr; } + Container * innerContainer () { return nullptr; } - QWidget * menu (void); + QWidget * menu (); protected: void update (int pId); private slots: - void aboutToShow (void); - void aboutToHide (void); + void aboutToShow (); + void aboutToHide (); }; OCTAVE_END_NAMESPACE(octave) diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/EditControl.cc --- a/libgui/graphics/EditControl.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/EditControl.cc Fri May 12 08:03:14 2023 +0200 @@ -34,13 +34,10 @@ #include "TextEdit.h" #include "QtHandlesUtils.h" -#include "octave-qobject.h" - OCTAVE_BEGIN_NAMESPACE(octave) EditControl * -EditControl::create (octave::base_qobject& oct_qobj, - octave::interpreter& interp, const graphics_object& go) +EditControl::create (octave::interpreter& interp, const graphics_object& go) { Object *parent = parentObject (interp, go); @@ -53,10 +50,10 @@ uicontrol::properties& up = Utils::properties (go); if ((up.get_max () - up.get_min ()) > 1) - return new EditControl (oct_qobj, interp, go, + return new EditControl (interp, go, new TextEdit (container)); else - return new EditControl (oct_qobj, interp, go, + return new EditControl (interp, go, new QLineEdit (container)); } } @@ -64,10 +61,9 @@ return nullptr; } -EditControl::EditControl (octave::base_qobject& oct_qobj, - octave::interpreter& interp, +EditControl::EditControl (octave::interpreter& interp, const graphics_object& go, QLineEdit *edit) - : BaseControl (oct_qobj, interp, go, edit), m_multiLine (false), + : BaseControl (interp, go, edit), m_multiLine (false), m_textChanged (false) { init (edit); @@ -100,10 +96,9 @@ this, &EditControl::returnPressed); } -EditControl::EditControl (octave::base_qobject& oct_qobj, - octave::interpreter& interp, +EditControl::EditControl (octave::interpreter& interp, const graphics_object& go, TextEdit *edit) - : BaseControl (oct_qobj, interp, go, edit), m_multiLine (true), + : BaseControl (interp, go, edit), m_multiLine (true), m_textChanged (false) { init (edit); @@ -138,7 +133,7 @@ this, &EditControl::returnPressed); } -EditControl::~EditControl (void) +EditControl::~EditControl () { } void @@ -262,13 +257,13 @@ } void -EditControl::textChanged (void) +EditControl::textChanged () { m_textChanged = true; } void -EditControl::returnPressed (void) +EditControl::returnPressed () { QString txt = (m_multiLine ? qWidget ()->toPlainText () @@ -291,7 +286,7 @@ } void -EditControl::editingFinished (void) +EditControl::editingFinished () { if (m_textChanged) { diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/EditControl.h --- a/libgui/graphics/EditControl.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/EditControl.h Fri May 12 08:03:14 2023 +0200 @@ -33,7 +33,6 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; class interpreter; class TextEdit; @@ -43,16 +42,16 @@ Q_OBJECT public: - EditControl (octave::base_qobject& oct_qobj, octave::interpreter& interp, + EditControl (octave::interpreter& interp, const graphics_object& go, QLineEdit *edit); - EditControl (octave::base_qobject& oct_qobj, octave::interpreter& interp, + EditControl (octave::interpreter& interp, const graphics_object& go, TextEdit *edit); - ~EditControl (void); + ~EditControl (); static EditControl * - create (octave::base_qobject& oct_qobj, octave::interpreter& interp, + create (octave::interpreter& interp, const graphics_object& go); protected: @@ -66,9 +65,9 @@ bool updateMultiLine (int pId); private slots: - void textChanged (void); - void editingFinished (void); - void returnPressed (void); + void textChanged (); + void editingFinished (); + void returnPressed (); private: bool m_multiLine; diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/Figure.cc --- a/libgui/graphics/Figure.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/Figure.cc Fri May 12 08:03:14 2023 +0200 @@ -43,10 +43,8 @@ #include #include #include -#if defined (HAVE_QSCREEN_DEVICEPIXELRATIO) -# include -# include -#endif +#include +#include #include "Canvas.h" #include "Container.h" @@ -109,19 +107,19 @@ } Figure * -Figure::create (octave::base_qobject& oct_qobj, octave::interpreter& interp, +Figure::create (octave::interpreter& interp, const graphics_object& go) { - return new Figure (oct_qobj, interp, go, new FigureWindow ()); + return new Figure (interp, go, new FigureWindow ()); } -Figure::Figure (octave::base_qobject& oct_qobj, octave::interpreter& interp, +Figure::Figure (octave::interpreter& interp, const graphics_object& go, FigureWindow *win) - : Object (oct_qobj, interp, go, win), m_blockUpdates (false), + : Object (interp, go, win), m_blockUpdates (false), m_figureToolBar (nullptr), m_menuBar (nullptr), m_innerRect (), m_outerRect (), m_previousHeight (0), m_resizable (true) { - m_container = new Container (win, oct_qobj, interp); + m_container = new Container (win, interp); win->setCentralWidget (m_container); connect (m_container, QOverload::of (&Container::interpreter_event), @@ -162,7 +160,9 @@ update (figure::properties::ID_NUMBERTITLE); // Decide what keyboard events we listen to - m_container->canvas (m_handle)->setEventMask (0); + Canvas *canvas = m_container->canvas (m_handle); + if (canvas) + canvas->setEventMask (0); update (figure::properties::ID_KEYPRESSFCN); update (figure::properties::ID_KEYRELEASEFCN); @@ -189,11 +189,11 @@ m_container->addReceiver (this); } -Figure::~Figure (void) +Figure::~Figure () { } QString -Figure::fileName (void) +Figure::fileName () { gh_manager& gh_mgr = m_interpreter.get_gh_manager (); @@ -219,7 +219,7 @@ } MouseMode -Figure::mouseMode (void) +Figure::mouseMode () { gh_manager& gh_mgr = m_interpreter.get_gh_manager (); @@ -278,13 +278,13 @@ } Container * -Figure::innerContainer (void) +Figure::innerContainer () { return m_container; } void -Figure::redraw (void) +Figure::redraw () { Canvas *canvas = m_container->canvas (m_handle); @@ -307,7 +307,7 @@ } void -Figure::show (void) +Figure::show () { QWidget *win = qWidget (); @@ -325,7 +325,7 @@ } uint8NDArray -Figure::slotGetPixels (void) +Figure::slotGetPixels () { uint8NDArray retval; Canvas *canvas = m_container->canvas (m_handle); @@ -343,7 +343,7 @@ } void -Figure::beingDeleted (void) +Figure::beingDeleted () { Canvas *canvas = m_container->canvas (m_handle.value (), false); @@ -442,54 +442,69 @@ break; case figure::properties::ID_KEYPRESSFCN: - if (fp.get_keypressfcn ().isempty ()) - m_container->canvas (m_handle)->clearEventMask (Canvas::KeyPress); - else - m_container->canvas (m_handle)->addEventMask (Canvas::KeyPress); - // Signal the change to uipanels as well - for (auto *qobj : qWidget ()->findChildren ()) - { - if (qobj->objectName () == "UIPanel") - { - Object *obj = Object::fromQObject (qobj); + { + Canvas *canvas = m_container->canvas (m_handle); + + if (canvas) + { + if (fp.get_keypressfcn ().isempty ()) + canvas->clearEventMask (Canvas::KeyPress); + else + canvas->addEventMask (Canvas::KeyPress); + } - if (obj) - { - if (fp.get_keypressfcn ().isempty ()) - obj->innerContainer ()->canvas (m_handle)-> - clearEventMask (Canvas::KeyPress); - else - obj->innerContainer ()->canvas (m_handle)-> - addEventMask (Canvas::KeyPress); - } - } - } + // Signal the change to uipanels as well + for (auto *qobj : qWidget ()->findChildren ()) + { + if (qobj->objectName () == "UIPanel") + { + Object *obj = Object::fromQObject (qobj); + + if (obj) + { + if (fp.get_keypressfcn ().isempty ()) + obj->innerContainer ()->canvas (m_handle)-> + clearEventMask (Canvas::KeyPress); + else + obj->innerContainer ()->canvas (m_handle)-> + addEventMask (Canvas::KeyPress); + } + } + } + } break; case figure::properties::ID_KEYRELEASEFCN: - if (fp.get_keyreleasefcn ().isempty ()) - m_container->canvas (m_handle)->clearEventMask (Canvas::KeyRelease); - else - m_container->canvas (m_handle)->addEventMask (Canvas::KeyRelease); - break; - // Signal the change to uipanels as well - for (auto *qobj : qWidget ()->findChildren ()) - { - if (qobj->objectName () == "UIPanel") - { - Object *obj = Object::fromQObject (qobj); + { + Canvas *canvas = m_container->canvas (m_handle); - if (obj) - { - if (fp.get_keypressfcn ().isempty ()) - obj->innerContainer ()->canvas (m_handle)-> - clearEventMask (Canvas::KeyRelease); - else - obj->innerContainer ()->canvas (m_handle)-> - addEventMask (Canvas::KeyRelease); - } - } - } + if (canvas) + { + if (fp.get_keyreleasefcn ().isempty ()) + canvas->clearEventMask (Canvas::KeyRelease); + else + canvas->addEventMask (Canvas::KeyRelease); + } + break; + // Signal the change to uipanels as well + for (auto *qobj : qWidget ()->findChildren ()) + { + if (qobj->objectName () == "UIPanel") + { + Object *obj = Object::fromQObject (qobj); + + if (obj) + { + if (fp.get_keypressfcn ().isempty ()) + obj->innerContainer ()->canvas (m_handle)-> + clearEventMask (Canvas::KeyRelease); + else + obj->innerContainer ()->canvas (m_handle)-> + addEventMask (Canvas::KeyRelease); + } + } + } + } break; case figure::properties::ID_WINDOWSTYLE: @@ -521,11 +536,14 @@ case figure::properties::ID_POINTERSHAPEHOTSPOT: case figure::properties::ID___MOUSE_MODE__: case figure::properties::ID___ZOOM_MODE__: - m_container->canvas (m_handle)->setCursor (mouseMode (), - fp.get_pointer (), - m_pointer_cdata, - fp.get_pointershapehotspot () - .matrix_value()); + { + Canvas *canvas = m_container->canvas (m_handle); + + if (canvas) + canvas->setCursor (mouseMode (), fp.get_pointer (), + m_pointer_cdata, + fp.get_pointershapehotspot ().matrix_value()); + } break; default: @@ -597,7 +615,7 @@ } QWidget * -Figure::menu (void) +Figure::menu () { return qWidget ()->menuBar (); } @@ -846,7 +864,7 @@ } void -Figure::updateContainer (void) +Figure::updateContainer () { redraw (); } @@ -854,7 +872,6 @@ void Figure::figureWindowShown () { -#if defined (HAVE_QSCREEN_DEVICEPIXELRATIO) QWindow *window = qWidget ()->windowHandle (); QScreen *screen = window->screen (); @@ -866,13 +883,11 @@ fp.set___device_pixel_ratio__ (screen->devicePixelRatio ()); connect (window, &QWindow::screenChanged, this, &Figure::screenChanged); -#endif } void Figure::screenChanged (QScreen *screen) { -#if defined (HAVE_QSCREEN_DEVICEPIXELRATIO) gh_manager& gh_mgr = m_interpreter.get_gh_manager (); octave::autolock guard (gh_mgr.graphics_lock ()); @@ -888,17 +903,19 @@ // from the GUI thread does not necessarily trigger a redraw. Force it. redraw (); } -#else - octave_unused_parameter (screen); -#endif } void -Figure::enableMouseTracking (void) +Figure::enableMouseTracking () { // Enable mouse tracking on every widgets m_container->setMouseTracking (true); - m_container->canvas (m_handle)->qWidget ()->setMouseTracking (true); + + Canvas *canvas = m_container->canvas (m_handle); + + if (canvas) + canvas->qWidget ()->setMouseTracking (true); + for (auto *w : m_container->findChildren ()) w->setMouseTracking (true); } diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/Figure.h --- a/libgui/graphics/Figure.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/Figure.h Fri May 12 08:03:14 2023 +0200 @@ -39,19 +39,18 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; class interpreter; enum MouseMode - { - NoMode, - RotateMode, - ZoomInMode, - ZoomOutMode, - PanMode, - SelectMode, - TextMode - }; +{ + NoMode, + RotateMode, + ZoomInMode, + ZoomOutMode, + PanMode, + SelectMode, + TextMode +}; class Container; class FigureWindow; @@ -68,21 +67,21 @@ friend class ToolBar; public: - Figure (octave::base_qobject& oct_qobj, octave::interpreter& interp, + Figure (octave::interpreter& interp, const graphics_object& go, FigureWindow *win); - ~Figure (void); + ~Figure (); static Figure * - create (octave::base_qobject& oct_qobj, octave::interpreter& interp, + create (octave::interpreter& interp, const graphics_object& go); - QString fileName (void); + QString fileName (); void setFileName (const QString& name); - MouseMode mouseMode (void); + MouseMode mouseMode (); - Container * innerContainer (void); - QWidget * menu (void); + Container * innerContainer (); + QWidget * menu (); void updateStatusBar (ColumnVector pt); void do_connections (const QObject *receiver, @@ -93,19 +92,19 @@ protected: enum UpdateBoundingBoxFlag - { - UpdateBoundingBoxPosition = 0x1, - UpdateBoundingBoxSize = 0x2, - UpdateBoundingBoxAll = 0x3 - }; + { + UpdateBoundingBoxPosition = 0x1, + UpdateBoundingBoxSize = 0x2, + UpdateBoundingBoxAll = 0x3 + }; protected: - void redraw (void); - void show (void); + void redraw (); + void show (); void print (const QString& file_cmd, const QString& term); void update (int pId); void updateBoundingBox (bool internal = false, int flags = 0); - void beingDeleted (void); + void beingDeleted (); private: void showFigureStatusBar (bool visible); @@ -113,19 +112,19 @@ void showCustomToolBar (QToolBar *bar, bool visible); void set_geometry (QRect r); - void enableMouseTracking (void); + void enableMouseTracking (); private slots: void updateFigureHeight (int delta_h); - void updateContainer (void); + void updateContainer (); void figureWindowShown (); void screenChanged (QScreen *); public slots: - uint8NDArray slotGetPixels (void); + uint8NDArray slotGetPixels (); signals: - void asyncUpdate (void); + void asyncUpdate (); void interpreter_event (const octave::fcn_callback& fcn); void interpreter_event (const octave::meth_callback& meth); diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/FigureWindow.cc --- a/libgui/graphics/FigureWindow.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/FigureWindow.cc Fri May 12 08:03:14 2023 +0200 @@ -41,11 +41,11 @@ setWindowIcon (QIcon (global_icon_paths.at (ICON_THEME_OCTAVE))); } -FigureWindow::~FigureWindow (void) +FigureWindow::~FigureWindow () { } QMenu * -FigureWindow::createPopupMenu (void) +FigureWindow::createPopupMenu () { // For the time being, disable menubar/toolbar popup menu return nullptr; diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/FigureWindow.h --- a/libgui/graphics/FigureWindow.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/FigureWindow.h Fri May 12 08:03:14 2023 +0200 @@ -40,9 +40,9 @@ public: explicit FigureWindow (QWidget *parent = nullptr); - ~FigureWindow (void); + ~FigureWindow (); - QMenu * createPopupMenu (void); + QMenu * createPopupMenu (); protected: void showEvent(QShowEvent *ev); diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/GLCanvas.cc --- a/libgui/graphics/GLCanvas.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/GLCanvas.cc Fri May 12 08:03:14 2023 +0200 @@ -37,66 +37,54 @@ OCTAVE_BEGIN_NAMESPACE(octave) -#if defined (HAVE_QOPENGLWIDGET) -# define OCTAVE_QT_OPENGL_WIDGET_FORMAT_ARGS -#else -# if defined (Q_OS_WIN32) -# define OCTAVE_QT_OPENGL_WIDGET_FORMAT_ARGS \ - QGLFormat (QGL::SampleBuffers | QGL::AlphaChannel \ - | QGL::IndirectRendering), -# else -# define OCTAVE_QT_OPENGL_WIDGET_FORMAT_ARGS \ - QGLFormat (QGL::SampleBuffers | QGL::AlphaChannel), -# endif -#endif - -GLCanvas::GLCanvas (octave::base_qobject& oct_qobj, - octave::interpreter& interp, - const graphics_handle& gh, QWidget *xparent) -: OCTAVE_QT_OPENGL_WIDGET (OCTAVE_QT_OPENGL_WIDGET_FORMAT_ARGS xparent), - Canvas (oct_qobj, interp, gh), m_glfcns (), m_renderer (m_glfcns) +GLWidget::GLWidget (Canvas& parent_canvas, QWidget *parent) + : QOpenGLWidget (parent), m_parent_canvas (parent_canvas), + m_glfcns (), m_renderer (m_glfcns) { setFocusPolicy (Qt::ClickFocus); setFocus (); } -GLCanvas::~GLCanvas (void) -{ } +GLWidget::~GLWidget () { } void -GLCanvas::initializeGL (void) +GLWidget::initializeGL () { + // The qopengl_functions object (part of Octave, not Qt) is just + // wrapper around QOpenGLFunctions_1_1. Does initialization really + // need to be deferred until initializeGL is called? + m_glfcns.init (); + + // All other resources we need are currently (supposed to be) + // managed by the QOpenGLWidget object so there is else nothing to + // do here. If we used custom shader programs, then we would need + // to initialize them here. } void -GLCanvas::draw (const graphics_handle& gh) +GLWidget::draw (graphics_object go) { - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - - octave::autolock guard (gh_mgr.graphics_lock ()); - - graphics_object go = gh_mgr.get_object (gh); - if (go) { + begin_rendering (); + + unwind_action reset_current ([=] () { end_rendering (); }); + graphics_object fig = go.get_ancestor ("figure"); double dpr = fig.get ("__device_pixel_ratio__").double_value (); m_renderer.set_viewport (dpr * width (), dpr * height ()); m_renderer.set_device_pixel_ratio (dpr); + m_renderer.draw (go); } } uint8NDArray -GLCanvas::do_getPixels (const graphics_handle& gh) +GLWidget::do_getPixels (graphics_object go) { uint8NDArray retval; - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - - graphics_object go = gh_mgr.get_object (gh); - if (go && go.isa ("figure")) { Matrix pos = go.get ("position").matrix_value (); @@ -104,9 +92,9 @@ pos(2) *= dpr; pos(3) *= dpr; - // Make sure we have a valid current context - if (! begin_rendering ()) - return retval; + begin_rendering (); + + unwind_action reset_current ([=] () { end_rendering (); }); // When the figure is not visible or its size is frozen for printing, // we use a framebuffer object to make sure we are rendering on a @@ -114,101 +102,84 @@ if (go.get ("visible").string_value () == "off" || go.get ("__printing__").string_value () == "on") { - OCTAVE_QT_OPENGL_FBO + QOpenGLFramebufferObject fbo (pos(2), pos(3), - OCTAVE_QT_OPENGL_FBO::Attachment::Depth); + QOpenGLFramebufferObject::Attachment::Depth); fbo.bind (); + unwind_action release_fbo ([&] () { fbo.release (); }); + m_renderer.set_viewport (pos(2), pos(3)); m_renderer.set_device_pixel_ratio (dpr); m_renderer.draw (go); + retval = m_renderer.get_pixels (pos(2), pos(3)); - - fbo.release (); } else { m_renderer.set_viewport (pos(2), pos(3)); m_renderer.set_device_pixel_ratio (dpr); m_renderer.draw (go); + retval = m_renderer.get_pixels (pos(2), pos(3)); } - - end_rendering (); } return retval; } void -GLCanvas::do_print (const QString& file_cmd, const QString& term, - const graphics_handle& handle) +GLWidget::do_print (const QString& file_cmd, const QString& term, + graphics_object go) { - gh_manager& gh_mgr = m_interpreter.get_gh_manager (); - - octave::autolock guard (gh_mgr.graphics_lock ()); - - graphics_object go = gh_mgr.get_object (handle); - if (go.valid_object ()) { + begin_rendering (); + + unwind_action reset_current ([=] () { end_rendering (); }); + graphics_object fig (go.get_ancestor ("figure")); - // Make sure we have a valid current context - if (! begin_rendering ()) - error ("print: no valid OpenGL offscreen context"); - - try + if (fig.get ("visible").string_value () == "on") + octave::gl2ps_print (m_glfcns, fig, file_cmd.toStdString (), + term.toStdString ()); + else { - if (fig.get ("visible").string_value () == "on") - octave::gl2ps_print (m_glfcns, fig, file_cmd.toStdString (), - term.toStdString ()); - else - { - // When the figure is not visible, we use a framebuffer object - // to make sure we are rendering on a suitably large frame. - Matrix pos = fig.get ("position").matrix_value (); - double dpr = fig.get ("__device_pixel_ratio__").double_value (); - pos(2) *= dpr; - pos(3) *= dpr; + // When the figure is not visible, we use a framebuffer object + // to make sure we are rendering on a suitably large frame. + Matrix pos = fig.get ("position").matrix_value (); + double dpr = fig.get ("__device_pixel_ratio__").double_value (); + pos(2) *= dpr; + pos(3) *= dpr; - OCTAVE_QT_OPENGL_FBO - fbo (pos(2), pos(3), - OCTAVE_QT_OPENGL_FBO::Attachment::Depth); - - fbo.bind (); + QOpenGLFramebufferObject + fbo (pos(2), pos(3), + QOpenGLFramebufferObject::Attachment::Depth); - octave::gl2ps_print (m_glfcns, fig, file_cmd.toStdString (), - term.toStdString ()); + fbo.bind (); - fbo.release (); - } + unwind_action release_fbo ([&] () { fbo.release (); }); + + octave::gl2ps_print (m_glfcns, fig, file_cmd.toStdString (), + term.toStdString ()); } - catch (octave::execution_exception& ee) - { - emit interpreter_event - ([=] (void) - { - // INTERPRETER THREAD - throw ee; - }); - } - - end_rendering (); } } graphics_object -GLCanvas::selectFromAxes (const graphics_object& ax, const QPoint& pt) +GLWidget::selectFromAxes (const graphics_object& ax, const QPoint& pt) { - makeCurrent (); - if (ax) { + begin_rendering (); + + unwind_action reset_current ([=] () { end_rendering (); }); + octave::opengl_selector s (m_glfcns); s.set_viewport (width (), height ()); + return s.select (ax, pt.x (), height () - pt.y (), octave::select_ignore_hittest); } @@ -217,7 +188,7 @@ } void -GLCanvas::drawZoomBox (const QPoint& p1, const QPoint& p2) +GLWidget::drawZoomBox (const QPoint& p1, const QPoint& p2) { Matrix overlaycolor (3, 1); overlaycolor(0) = 0.45; @@ -235,68 +206,72 @@ } void -GLCanvas::paintGL (void) +GLWidget::paintGL () { - canvasPaintEvent (); + m_parent_canvas.canvasPaintEvent (); } void -GLCanvas::mouseDoubleClickEvent (QMouseEvent *xevent) +GLWidget::mouseDoubleClickEvent (QMouseEvent *xevent) { - canvasMouseDoubleClickEvent (xevent); + m_parent_canvas.canvasMouseDoubleClickEvent (xevent); } void -GLCanvas::mouseMoveEvent (QMouseEvent *xevent) +GLWidget::mouseMoveEvent (QMouseEvent *xevent) { - canvasMouseMoveEvent (xevent); + m_parent_canvas.canvasMouseMoveEvent (xevent); } void -GLCanvas::mousePressEvent (QMouseEvent *xevent) +GLWidget::mousePressEvent (QMouseEvent *xevent) { - canvasMousePressEvent (xevent); + m_parent_canvas.canvasMousePressEvent (xevent); } void -GLCanvas::mouseReleaseEvent (QMouseEvent *xevent) +GLWidget::mouseReleaseEvent (QMouseEvent *xevent) { - canvasMouseReleaseEvent (xevent); + m_parent_canvas.canvasMouseReleaseEvent (xevent); } void -GLCanvas::wheelEvent (QWheelEvent *xevent) +GLWidget::wheelEvent (QWheelEvent *xevent) { - canvasWheelEvent (xevent); + m_parent_canvas.canvasWheelEvent (xevent); } void -GLCanvas::keyPressEvent (QKeyEvent *xevent) +GLWidget::keyPressEvent (QKeyEvent *xevent) { - if (! canvasKeyPressEvent (xevent)) - OCTAVE_QT_OPENGL_WIDGET::keyPressEvent (xevent); + if (! m_parent_canvas.canvasKeyPressEvent (xevent)) + QOpenGLWidget::keyPressEvent (xevent); } void -GLCanvas::keyReleaseEvent (QKeyEvent *xevent) +GLWidget::keyReleaseEvent (QKeyEvent *xevent) { - if (! canvasKeyReleaseEvent (xevent)) - OCTAVE_QT_OPENGL_WIDGET::keyReleaseEvent (xevent); + if (! m_parent_canvas.canvasKeyReleaseEvent (xevent)) + QOpenGLWidget::keyReleaseEvent (xevent); } bool -GLCanvas::begin_rendering (void) +GLWidget::begin_rendering () { bool retval = true; if (! isValid ()) { -# if defined (HAVE_QT_OFFSCREEN) + // FIXME: Is this really the right way to manager offscreen + // rendering for printing? + static bool os_ctx_ok = true; + if (os_ctx_ok && ! m_os_context.isValid ()) { // Try to initialize offscreen context m_os_surface.create (); + if (! m_os_context.create ()) { os_ctx_ok = false; @@ -305,9 +280,6 @@ } retval = m_os_context.makeCurrent (&m_os_surface); -# else - retval = false; -# endif } else makeCurrent (); @@ -316,9 +288,92 @@ } void -GLCanvas::end_rendering (void) +GLWidget::end_rendering () { doneCurrent (); } +GLCanvas::GLCanvas (octave::interpreter& interp, + const graphics_handle& gh, QWidget *parent) + : Canvas (interp, gh), m_glwidget (new GLWidget (*this, parent)) +{ } + +GLCanvas::~GLCanvas () +{ + delete m_glwidget; +} + +void +GLCanvas::draw (const graphics_handle& gh) +{ + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + + octave::autolock guard (gh_mgr.graphics_lock ()); + + graphics_object go = gh_mgr.get_object (gh); + + m_glwidget->draw (go); +} + +uint8NDArray +GLCanvas::do_getPixels (const graphics_handle& gh) +{ + uint8NDArray retval; + + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + + graphics_object go = gh_mgr.get_object (gh); + + return m_glwidget->do_getPixels (go); +} + +void +GLCanvas::do_print (const QString& file_cmd, const QString& term, + const graphics_handle& handle) +{ + gh_manager& gh_mgr = m_interpreter.get_gh_manager (); + + octave::autolock guard (gh_mgr.graphics_lock ()); + + graphics_object go = gh_mgr.get_object (handle); + + try + { + m_glwidget->do_print (file_cmd, term, go); + } + catch (octave::execution_exception& ee) + { + emit interpreter_event + ([=] () + { + // INTERPRETER THREAD + throw ee; + }); + } +} + +graphics_object +GLCanvas::selectFromAxes (const graphics_object& ax, const QPoint& pt) +{ + return m_glwidget->selectFromAxes (ax, pt); +} + +void +GLCanvas::drawZoomBox (const QPoint& p1, const QPoint& p2) +{ + m_glwidget->drawZoomBox (p1, p2); +} + +bool +GLCanvas::begin_rendering () +{ + return m_glwidget->begin_rendering (); +} + +void +GLCanvas::end_rendering () +{ + m_glwidget->end_rendering (); +} + OCTAVE_END_NAMESPACE(octave) diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/GLCanvas.h --- a/libgui/graphics/GLCanvas.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/GLCanvas.h Fri May 12 08:03:14 2023 +0200 @@ -26,23 +26,10 @@ #if ! defined (octave_GLCanvas_h) #define octave_GLCanvas_h 1 -#if defined (HAVE_QOPENGLWIDGET) -# include -# define OCTAVE_QT_OPENGL_WIDGET QOpenGLWidget -# include -# define OCTAVE_QT_OPENGL_FBO QOpenGLFramebufferObject -# if defined (HAVE_QT_OFFSCREEN) -# include -# include -# endif -#elif defined (HAVE_QGLWIDGET) -# include -# define OCTAVE_QT_OPENGL_WIDGET QGLWidget -# include -# define OCTAVE_QT_OPENGL_FBO QGLFramebufferObject -#else -# error "configuration error: must have or ." -#endif +#include +#include +#include +#include #include "Canvas.h" @@ -51,19 +38,61 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; -} +class GLWidget : public QOpenGLWidget +{ + Q_OBJECT + +public: + + GLWidget (Canvas& parent_canvas, QWidget *parent); + + ~GLWidget (); + + void initializeGL (); + + void draw (graphics_object go); + uint8NDArray do_getPixels (graphics_object go); + void do_print (const QString& file_cmd, const QString& term, + graphics_object go); + void drawZoomBox (const QPoint& p1, const QPoint& p2); + void resize (int /* x */, int /* y */, + int /* width */, int /* height */) { } + graphics_object selectFromAxes (const graphics_object& ax, + const QPoint& pt); -OCTAVE_BEGIN_NAMESPACE(octave) + bool begin_rendering (); + void end_rendering (); + +protected: -class GLCanvas : public OCTAVE_QT_OPENGL_WIDGET, public Canvas + void paintGL (); + void mouseDoubleClickEvent (QMouseEvent *event); + void mouseMoveEvent (QMouseEvent *event); + void mousePressEvent (QMouseEvent *event); + void mouseReleaseEvent (QMouseEvent *event); + void wheelEvent (QWheelEvent *event); + void keyPressEvent (QKeyEvent *event); + void keyReleaseEvent (QKeyEvent *event); + +private: + + Canvas& m_parent_canvas; + + qopengl_functions m_glfcns; + opengl_renderer m_renderer; + + QOpenGLContext m_os_context; + QOffscreenSurface m_os_surface; +}; + +class GLCanvas : public Canvas { public: - GLCanvas (octave::base_qobject& oct_qobj, octave::interpreter& interp, - const graphics_handle& handle, QWidget *parent); - ~GLCanvas (void); - void initializeGL (void); + GLCanvas (octave::interpreter& interp, const graphics_handle& handle, + QWidget *parent); + + ~GLCanvas (); void draw (const graphics_handle& handle); uint8NDArray do_getPixels (const graphics_handle& handle); @@ -74,30 +103,15 @@ int /* width */, int /* height */) { } graphics_object selectFromAxes (const graphics_object& ax, const QPoint& pt); - QWidget * qWidget (void) { return this; } -protected: - void paintGL (void); - void mouseDoubleClickEvent (QMouseEvent *event); - void mouseMoveEvent (QMouseEvent *event); - void mousePressEvent (QMouseEvent *event); - void mouseReleaseEvent (QMouseEvent *event); - void wheelEvent (QWheelEvent *event); - void keyPressEvent (QKeyEvent *event); - void keyReleaseEvent (QKeyEvent *event); + QWidget * qWidget () { return m_glwidget; } private: - bool begin_rendering (void); - void end_rendering (void); + GLWidget *m_glwidget; - octave::qopengl_functions m_glfcns; - octave::opengl_renderer m_renderer; - -# if defined (HAVE_QT_OFFSCREEN) - QOpenGLContext m_os_context; - QOffscreenSurface m_os_surface; -# endif + bool begin_rendering (); + void end_rendering (); }; OCTAVE_END_NAMESPACE(octave) diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/GenericEventNotify.h --- a/libgui/graphics/GenericEventNotify.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/GenericEventNotify.h Fri May 12 08:03:14 2023 +0200 @@ -39,8 +39,8 @@ class GenericEventNotifySender { public: - GenericEventNotifySender (void) : m_receivers () { } - virtual ~GenericEventNotifySender (void) = default; + GenericEventNotifySender () : m_receivers () { } + virtual ~GenericEventNotifySender () = default; void addReceiver (GenericEventNotifyReceiver *r) { m_receivers.insert (r); } @@ -59,8 +59,8 @@ class GenericEventNotifyReceiver { public: - GenericEventNotifyReceiver (void) { } - virtual ~GenericEventNotifyReceiver (void) = default; + GenericEventNotifyReceiver () { } + virtual ~GenericEventNotifyReceiver () = default; virtual bool eventNotifyBefore (QObject *obj, QEvent *evt) = 0; virtual void eventNotifyAfter (QObject *obj, QEvent *evt) = 0; @@ -92,7 +92,7 @@ { \ public: \ T (QWidget *xparent) : B (xparent), GenericEventNotifySender () { } \ - ~ T (void) = default; \ + ~ T () = default; \ \ bool event (QEvent *evt) \ { \ diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/KeyMap.cc --- a/libgui/graphics/KeyMap.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/KeyMap.cc Fri May 12 08:03:14 2023 +0200 @@ -36,7 +36,7 @@ namespace KeyMap { - QMap makeKeyMapper (void) + QMap makeKeyMapper () { QMap keyMapper; diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/ListBoxControl.cc --- a/libgui/graphics/ListBoxControl.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/ListBoxControl.cc Fri May 12 08:03:14 2023 +0200 @@ -35,8 +35,6 @@ #include "ListBoxControl.h" #include "QtHandlesUtils.h" -#include "octave-qobject.h" - OCTAVE_BEGIN_NAMESPACE(octave) static void @@ -69,8 +67,7 @@ } ListBoxControl * -ListBoxControl::create (octave::base_qobject& oct_qobj, - octave::interpreter& interp, +ListBoxControl::create (octave::interpreter& interp, const graphics_object& go) { Object *parent = parentObject (interp, go); @@ -80,17 +77,16 @@ Container *container = parent->innerContainer (); if (container) - return new ListBoxControl (oct_qobj, interp, go, + return new ListBoxControl (interp, go, new QListWidget (container)); } return nullptr; } -ListBoxControl::ListBoxControl (octave::base_qobject& oct_qobj, - octave::interpreter& interp, +ListBoxControl::ListBoxControl (octave::interpreter& interp, const graphics_object& go, QListWidget *list) - : BaseControl (oct_qobj, interp, go, list), m_blockCallback (false), + : BaseControl (interp, go, list), m_blockCallback (false), m_selectionChanged (false) { uicontrol::properties& up = properties (); @@ -131,7 +127,7 @@ this, &ListBoxControl::itemPressed); } -ListBoxControl::~ListBoxControl (void) +ListBoxControl::~ListBoxControl () { } void @@ -201,7 +197,7 @@ } void -ListBoxControl::itemSelectionChanged (void) +ListBoxControl::itemSelectionChanged () { if (! m_blockCallback) m_selectionChanged = true; diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/ListBoxControl.h --- a/libgui/graphics/ListBoxControl.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/ListBoxControl.h Fri May 12 08:03:14 2023 +0200 @@ -34,7 +34,6 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; class interpreter; class ListBoxControl : public BaseControl @@ -42,13 +41,12 @@ Q_OBJECT public: - ListBoxControl (octave::base_qobject& oct_qobj, - octave::interpreter& interp, const graphics_object& go, + ListBoxControl (octave::interpreter& interp, const graphics_object& go, QListWidget *list); - ~ListBoxControl (void); + ~ListBoxControl (); static ListBoxControl * - create (octave::base_qobject& oct_qobj, octave::interpreter& interp, + create (octave::interpreter& interp, const graphics_object& go); protected: @@ -57,7 +55,7 @@ void sendSelectionChange (); private slots: - void itemSelectionChanged (void); + void itemSelectionChanged (); void itemActivated (const QModelIndex&); void itemPressed (QListWidgetItem *); diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/Logger.cc --- a/libgui/graphics/Logger.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/Logger.cc Fri May 12 08:03:14 2023 +0200 @@ -40,7 +40,7 @@ Logger *Logger::s_instance = nullptr; QMutex *Logger::s_mutex = nullptr; -Logger::Logger (void) +Logger::Logger () : m_debugEnabled (false) { QProcessEnvironment pe (QProcessEnvironment::systemEnvironment ()); @@ -49,11 +49,11 @@ m_debugEnabled = true; } -Logger::~Logger (void) +Logger::~Logger () { } Logger * -Logger::instance (void) +Logger::instance () { if (! s_instance) { diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/Logger.h --- a/libgui/graphics/Logger.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/Logger.h Fri May 12 08:03:14 2023 +0200 @@ -44,10 +44,10 @@ static QMutex *s_mutex; private: - Logger (void); - ~Logger (void); + Logger (); + ~Logger (); - static Logger * instance (void); + static Logger * instance (); void debugV (const char *fmt, va_list arg); }; diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/Menu.cc --- a/libgui/graphics/Menu.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/Menu.cc Fri May 12 08:03:14 2023 +0200 @@ -36,8 +36,6 @@ #include "Menu.h" #include "QtHandlesUtils.h" -#include "octave-qobject.h" - OCTAVE_BEGIN_NAMESPACE(octave) static QKeySequence @@ -62,7 +60,7 @@ } Menu * -Menu::create (octave::base_qobject& oct_qobj, octave::interpreter& interp, +Menu::create (octave::interpreter& interp, const graphics_object& go) { Object *parent_obj = parentObject (interp, go); @@ -72,16 +70,16 @@ QObject *qObj = parent_obj->qObject (); if (qObj) - return new Menu (oct_qobj, interp, go, new QAction (qObj), + return new Menu (interp, go, new QAction (qObj), parent_obj); } return nullptr; } -Menu::Menu (octave::base_qobject& oct_qobj, octave::interpreter& interp, +Menu::Menu (octave::interpreter& interp, const graphics_object& go, QAction *action, Object *xparent) - : Object (oct_qobj, interp, go, action), m_parent (nullptr), + : Object (interp, go, action), m_parent (nullptr), m_separator (nullptr) { uimenu::properties& up = properties (); @@ -127,7 +125,7 @@ count++; up.get_property ("position").set - (octave_value (static_cast (count)), true, false); + (octave_value (static_cast (count)), true, false); } else { @@ -156,14 +154,14 @@ updateSiblingPositions (); else up.get_property ("position").set - (octave_value (static_cast (count+1)), true, false); + (octave_value (static_cast (count+1)), true, false); } } connect (action, &QAction::triggered, this, &Menu::actionTriggered); } -Menu::~Menu (void) +Menu::~Menu () { } void @@ -270,7 +268,7 @@ } QWidget * -Menu::menu (void) +Menu::menu () { QAction *action = qWidget (); QMenu *action_menu = action->menu (); @@ -287,7 +285,7 @@ } void -Menu::actionTriggered (void) +Menu::actionTriggered () { QAction *action = qWidget (); @@ -297,13 +295,13 @@ } void -Menu::actionHovered (void) +Menu::actionHovered () { emit gh_callback_event (m_handle, "menuselectedfcn"); } void -Menu::updateSiblingPositions (void) +Menu::updateSiblingPositions () { if (m_parent) { @@ -326,7 +324,7 @@ uimenu::properties& up = Utils::properties (go); up.get_property ("position").set - (octave_value (count), true, false); + (octave_value (count), true, false); } } diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/Menu.h --- a/libgui/graphics/Menu.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/Menu.h Fri May 12 08:03:14 2023 +0200 @@ -35,7 +35,6 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; class interpreter; class Menu : public Object, public MenuContainer @@ -43,27 +42,27 @@ Q_OBJECT public: - Menu (octave::base_qobject& oct_qobj, octave::interpreter& interp, + Menu (octave::interpreter& interp, const graphics_object& go, QAction *action, Object *parent); - ~Menu (void); + ~Menu (); static Menu * - create (octave::base_qobject& oct_qobj, octave::interpreter& interp, + create (octave::interpreter& interp, const graphics_object& go); - Container * innerContainer (void) { return nullptr; } + Container * innerContainer () { return nullptr; } - QWidget * menu (void); + QWidget * menu (); protected: void update (int pId); private slots: - void actionTriggered (void); - void actionHovered (void); + void actionTriggered (); + void actionHovered (); private: - void updateSiblingPositions (void); + void updateSiblingPositions (); private: QWidget *m_parent; diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/MenuContainer.h --- a/libgui/graphics/MenuContainer.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/MenuContainer.h Fri May 12 08:03:14 2023 +0200 @@ -33,7 +33,7 @@ class MenuContainer { public: - virtual QWidget * menu (void) = 0; + virtual QWidget * menu () = 0; }; OCTAVE_END_NAMESPACE(octave) diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/Object.cc --- a/libgui/graphics/Object.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/Object.cc Fri May 12 08:03:14 2023 +0200 @@ -32,7 +32,6 @@ #include "Object.h" #include "QtHandlesUtils.h" -#include "octave-qobject.h" #include "qt-graphics-toolkit.h" #include "graphics.h" @@ -40,10 +39,10 @@ OCTAVE_BEGIN_NAMESPACE(octave) -Object::Object (octave::base_qobject& oct_qobj, octave::interpreter& interp, +Object::Object (octave::interpreter& interp, const graphics_object& go, QObject *obj) -: QObject (), m_octave_qobj (oct_qobj), m_interpreter (interp), - m_go (go), m_handle (go.get_handle ()), m_qobject (nullptr) + : QObject (), m_interpreter (interp), m_go (go), + m_handle (go.get_handle ()), m_qobject (nullptr) { gh_manager& gh_mgr = m_interpreter.get_gh_manager (); @@ -75,11 +74,11 @@ } } -Object::~Object (void) +Object::~Object () { } graphics_object -Object::object (void) const +Object::object () const { gh_manager& gh_mgr = m_interpreter.get_gh_manager (); @@ -102,9 +101,9 @@ switch (pId) { - // Special case for objects being deleted, as it's very likely - // that the graphics_object already has been destroyed when this - // is executed (because of the async behavior). + // Special case for objects being deleted, as it's very likely + // that the graphics_object already has been destroyed when this + // is executed (because of the async behavior). case base_properties::ID_BEINGDELETED: beingDeleted (); break; @@ -117,7 +116,7 @@ } void -Object::slotFinalize (void) +Object::slotFinalize () { gh_manager& gh_mgr = m_interpreter.get_gh_manager (); @@ -127,7 +126,7 @@ } void -Object::slotRedraw (void) +Object::slotRedraw () { gh_manager& gh_mgr = m_interpreter.get_gh_manager (); @@ -138,7 +137,7 @@ } void -Object::slotShow (void) +Object::slotShow () { gh_manager& gh_mgr = m_interpreter.get_gh_manager (); @@ -164,7 +163,7 @@ { } void -Object::finalize (void) +Object::finalize () { if (m_qobject) { @@ -175,11 +174,11 @@ } void -Object::redraw (void) +Object::redraw () { } void -Object::show (void) +Object::show () { } void @@ -187,7 +186,7 @@ { } void -Object::beingDeleted (void) +Object::beingDeleted () { } void Object::objectDestroyed (QObject *obj) @@ -204,7 +203,7 @@ octave::autolock guard (gh_mgr.graphics_lock ()); Object *parent = qt_graphics_toolkit::toolkitObject - (gh_mgr.get_object (go.get_parent ())); + (gh_mgr.get_object (go.get_parent ())); return parent; } diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/Object.h --- a/libgui/graphics/Object.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/Object.h Fri May 12 08:03:14 2023 +0200 @@ -37,7 +37,6 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; class interpreter; class Container; @@ -48,39 +47,39 @@ Q_OBJECT public: - Object (octave::base_qobject& qobj, octave::interpreter& interp, - const graphics_object& go, QObject *obj = nullptr); + Object (octave::interpreter& interp, const graphics_object& go, + QObject *obj = nullptr); - virtual ~Object (void); + virtual ~Object (); - base_properties& properties (void) + base_properties& properties () { return object ().get_properties (); } - const base_properties& properties (void) const + const base_properties& properties () const { return object ().get_properties (); } template - typename T::properties& properties (void) + typename T::properties& properties () { return dynamic_cast - (object ().get_properties ()); + (object ().get_properties ()); } template - const typename T::properties& properties (void) const + const typename T::properties& properties () const { return dynamic_cast - (object ().get_properties ()); + (object ().get_properties ()); } - graphics_object object (void) const; + graphics_object object () const; - virtual QObject * qObject (void) { return m_qobject; } + virtual QObject * qObject () { return m_qobject; } template - T * qWidget (void) { return qobject_cast(qObject ()); } + T * qWidget () { return qobject_cast(qObject ()); } - virtual Container * innerContainer (void) = 0; + virtual Container * innerContainer () = 0; static Object * fromQObject (QObject *obj); @@ -109,9 +108,9 @@ public slots: void slotUpdate (int pId); - void slotFinalize (void); - void slotRedraw (void); - void slotShow (void); + void slotFinalize (); + void slotRedraw (); + void slotShow (); void slotPrint (const QString& file_cmd, const QString& term); void objectDestroyed (QObject *obj = nullptr); @@ -123,16 +122,15 @@ void init (QObject *obj, bool callBase = false); virtual void update (int pId); - virtual void finalize (void); - virtual void redraw (void); - virtual void show (void); + virtual void finalize (); + virtual void redraw (); + virtual void show (); virtual void print (const QString& file_cmd, const QString& term); - virtual void beingDeleted (void); + virtual void beingDeleted (); protected: - octave::base_qobject& m_octave_qobj; octave::interpreter& m_interpreter; // Store the graphics object directly so that it will exist when diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/ObjectProxy.cc --- a/libgui/graphics/ObjectProxy.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/ObjectProxy.cc Fri May 12 08:03:14 2023 +0200 @@ -91,7 +91,7 @@ } void -ObjectProxy::finalize (void) +ObjectProxy::finalize () { if (! m_object) error ("ObjectProxy::finalize: invalid GUI Object"); @@ -106,13 +106,13 @@ } void -ObjectProxy::redraw (void) +ObjectProxy::redraw () { emit sendRedraw (); } void -ObjectProxy::show (void) +ObjectProxy::show () { emit sendShow (); } @@ -135,7 +135,7 @@ } uint8NDArray -ObjectProxy::get_pixels (void) +ObjectProxy::get_pixels () { if (! m_object) error ("ObjectProxy::finalize: invalid GUI Object"); diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/ObjectProxy.h --- a/libgui/graphics/ObjectProxy.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/ObjectProxy.h Fri May 12 08:03:14 2023 +0200 @@ -44,19 +44,19 @@ ObjectProxy (Object *obj = nullptr); void update (int pId); - void finalize (void); - void redraw (void); - void show (void); + void finalize (); + void redraw (); + void show (); void print (const QString& file_cmd, const QString& term); - uint8NDArray get_pixels (void); + uint8NDArray get_pixels (); - Object * object (void) { return m_object; } + Object * object () { return m_object; } void setObject (Object *obj); signals: void sendUpdate (int pId); - void sendRedraw (void); - void sendShow (void); + void sendRedraw (); + void sendShow (); private: void init (Object *obj); diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/Panel.cc --- a/libgui/graphics/Panel.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/Panel.cc Fri May 12 08:03:14 2023 +0200 @@ -39,8 +39,6 @@ #include "Panel.h" #include "QtHandlesUtils.h" -#include "octave-qobject.h" - #include "graphics.h" #include "interpreter.h" @@ -92,7 +90,7 @@ } Panel * -Panel::create (octave::base_qobject& oct_qobj, octave::interpreter& interp, +Panel::create (octave::interpreter& interp, const graphics_object& go) { Object *parent = parentObject (interp, go); @@ -102,15 +100,15 @@ Container *container = parent->innerContainer (); if (container) - return new Panel (oct_qobj, interp, go, new QFrame (container)); + return new Panel (interp, go, new QFrame (container)); } return nullptr; } -Panel::Panel (octave::base_qobject& oct_qobj, octave::interpreter& interp, +Panel::Panel (octave::interpreter& interp, const graphics_object& go, QFrame *frame) - : Object (oct_qobj, interp, go, frame), m_container (nullptr), + : Object (interp, go, frame), m_container (nullptr), m_title (nullptr), m_blockUpdates (false), m_previous_bbox (Matrix (1, 4, 0)) { @@ -127,7 +125,7 @@ setupPalette (pp, pal); frame->setPalette (pal); - m_container = new Container (frame, oct_qobj, interp); + m_container = new Container (frame, interp); m_container->canvas (m_handle); connect (m_container, SIGNAL (interpeter_event (const fcn_callback&)), @@ -168,7 +166,7 @@ frame->hide (); } -Panel::~Panel (void) +Panel::~Panel () { } bool @@ -368,7 +366,7 @@ } void -Panel::redraw (void) +Panel::redraw () { update (uipanel::properties::ID_POSITION); @@ -379,7 +377,7 @@ } void -Panel::updateLayout (void) +Panel::updateLayout () { uipanel::properties& pp = properties (); QFrame *frame = qWidget (); diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/Panel.h --- a/libgui/graphics/Panel.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/Panel.h Fri May 12 08:03:14 2023 +0200 @@ -33,7 +33,6 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; class interpreter; class Container; @@ -41,16 +40,16 @@ class Panel : public Object { public: - Panel (octave::base_qobject& oct_qobj, octave::interpreter& interp, + Panel (octave::interpreter& interp, const graphics_object& go, QFrame *frame); - ~Panel (void); + ~Panel (); - Container * innerContainer (void) { return m_container; } + Container * innerContainer () { return m_container; } bool eventFilter (QObject *watched, QEvent *event); static Panel * - create (octave::base_qobject& oct_qobj, octave::interpreter& interp, + create (octave::interpreter& interp, const graphics_object& go); void do_connections (const QObject *receiver, @@ -58,10 +57,10 @@ protected: void update (int pId); - void redraw (void); + void redraw (); private: - void updateLayout (void); + void updateLayout (); private: Container *m_container; diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/PopupMenuControl.cc --- a/libgui/graphics/PopupMenuControl.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/PopupMenuControl.cc Fri May 12 08:03:14 2023 +0200 @@ -33,14 +33,10 @@ #include "PopupMenuControl.h" #include "QtHandlesUtils.h" -#include "octave-qobject.h" -#include "octave-qtutils.h" - OCTAVE_BEGIN_NAMESPACE(octave) PopupMenuControl * -PopupMenuControl::create (octave::base_qobject& oct_qobj, - octave::interpreter& interp, +PopupMenuControl::create (octave::interpreter& interp, const graphics_object& go) { Object *parent = parentObject (interp, go); @@ -50,18 +46,17 @@ Container *container = parent->innerContainer (); if (container) - return new PopupMenuControl (oct_qobj, interp, go, + return new PopupMenuControl (interp, go, new QComboBox (container)); } return nullptr; } -PopupMenuControl::PopupMenuControl (octave::base_qobject& oct_qobj, - octave::interpreter& interp, +PopupMenuControl::PopupMenuControl (octave::interpreter& interp, const graphics_object& go, QComboBox *box) - : BaseControl (oct_qobj, interp, go, box), m_blockUpdate (false) + : BaseControl (interp, go, box), m_blockUpdate (false) { uicontrol::properties& up = properties (); @@ -73,7 +68,7 @@ this, &PopupMenuControl::currentIndexChanged); } -PopupMenuControl::~PopupMenuControl (void) +PopupMenuControl::~PopupMenuControl () { } void PopupMenuControl::update (int pId) diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/PopupMenuControl.h --- a/libgui/graphics/PopupMenuControl.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/PopupMenuControl.h Fri May 12 08:03:14 2023 +0200 @@ -32,7 +32,6 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; class interpreter; class PopupMenuControl : public BaseControl @@ -40,13 +39,12 @@ Q_OBJECT public: - PopupMenuControl (octave::base_qobject& oct_qobj, - octave::interpreter& interp, const graphics_object& go, + PopupMenuControl (octave::interpreter& interp, const graphics_object& go, QComboBox *box); - ~PopupMenuControl (void); + ~PopupMenuControl (); static PopupMenuControl * - create (octave::base_qobject& oct_qobj, octave::interpreter& interp, + create (octave::interpreter& interp, const graphics_object& go); protected: diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/PushButtonControl.cc --- a/libgui/graphics/PushButtonControl.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/PushButtonControl.cc Fri May 12 08:03:14 2023 +0200 @@ -34,13 +34,10 @@ #include "Container.h" #include "QtHandlesUtils.h" -#include "octave-qobject.h" - OCTAVE_BEGIN_NAMESPACE(octave) PushButtonControl * -PushButtonControl::create (octave::base_qobject& oct_qobj, - octave::interpreter& interp, +PushButtonControl::create (octave::interpreter& interp, const graphics_object& go) { Object *parent = parentObject (interp, go); @@ -50,18 +47,17 @@ Container *container = parent->innerContainer (); if (container) - return new PushButtonControl (oct_qobj, interp, go, + return new PushButtonControl (interp, go, new QPushButton (container)); } return nullptr; } -PushButtonControl::PushButtonControl (octave::base_qobject& oct_qobj, - octave::interpreter& interp, +PushButtonControl::PushButtonControl (octave::interpreter& interp, const graphics_object& go, QPushButton *btn) - : ButtonControl (oct_qobj, interp, go, btn) + : ButtonControl (interp, go, btn) { uicontrol::properties& up = properties (); @@ -73,7 +69,7 @@ btn->setIconSize (QSize (cdat.columns (), cdat.rows ())); } -PushButtonControl::~PushButtonControl (void) +PushButtonControl::~PushButtonControl () { } void diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/PushButtonControl.h --- a/libgui/graphics/PushButtonControl.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/PushButtonControl.h Fri May 12 08:03:14 2023 +0200 @@ -32,19 +32,17 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; class interpreter; class PushButtonControl : public ButtonControl { public: - PushButtonControl (octave::base_qobject& oct_qobj, - octave::interpreter& interp, const graphics_object& go, + PushButtonControl (octave::interpreter& interp, const graphics_object& go, QPushButton *btn); - ~PushButtonControl (void); + ~PushButtonControl (); static PushButtonControl * - create (octave::base_qobject& oct_qobj, octave::interpreter& interp, + create (octave::interpreter& interp, const graphics_object& go); protected: diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/PushTool.cc --- a/libgui/graphics/PushTool.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/PushTool.cc Fri May 12 08:03:14 2023 +0200 @@ -31,13 +31,10 @@ #include "ToolBarButton.cc" -#include "octave-qobject.h" - OCTAVE_BEGIN_NAMESPACE(octave) PushTool * -PushTool::create (octave::base_qobject& oct_qobj, - octave::interpreter& interp, const graphics_object& go) +PushTool::create (octave::interpreter& interp, const graphics_object& go) { Object *parent = parentObject (interp, go); @@ -46,22 +43,21 @@ QWidget *parentWidget = parent->qWidget (); if (parentWidget) - return new PushTool (oct_qobj, interp, go, + return new PushTool (interp, go, new QAction (parentWidget)); } return nullptr; } -PushTool::PushTool (octave::base_qobject& oct_qobj, - octave::interpreter& interp, +PushTool::PushTool (octave::interpreter& interp, const graphics_object& go, QAction *action) - : ToolBarButton (oct_qobj, interp, go, action) + : ToolBarButton (interp, go, action) { connect (action, &QAction::triggered, this, &PushTool::clicked); } -PushTool::~PushTool (void) +PushTool::~PushTool () { } void @@ -76,7 +72,7 @@ } void -PushTool::clicked (void) +PushTool::clicked () { emit gh_callback_event (m_handle, "clickedcallback"); } diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/PushTool.h --- a/libgui/graphics/PushTool.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/PushTool.h Fri May 12 08:03:14 2023 +0200 @@ -30,7 +30,6 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; class interpreter; class PushTool : public ToolBarButton @@ -38,19 +37,19 @@ Q_OBJECT public: - PushTool (octave::base_qobject& oct_qobj, octave::interpreter& interp, + PushTool (octave::interpreter& interp, const graphics_object& go, QAction *action); - ~PushTool (void); + ~PushTool (); static PushTool * - create (octave::base_qobject& oct_qobj, octave::interpreter& interp, + create (octave::interpreter& interp, const graphics_object& go); protected: void update (int pId); private slots: - void clicked (void); + void clicked (); }; OCTAVE_END_NAMESPACE(octave) diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/QtHandlesUtils.cc --- a/libgui/graphics/QtHandlesUtils.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/QtHandlesUtils.cc Fri May 12 08:03:14 2023 +0200 @@ -161,9 +161,13 @@ Matrix rgb (1, 3); double *rgbData = rgb.fortran_vec (); +#if HAVE_QCOLOR_FLOAT_TYPE + float tmp[3]; +#else // qreal is a typedef for double except for ARM CPU architectures // where it is a typedef for float (Bug #44970). qreal tmp[3]; +#endif c.getRgbF (tmp, tmp+1, tmp+2); rgbData[0] = tmp[0]; rgbData[1] = tmp[1]; rgbData[2] = tmp[2]; @@ -401,11 +405,8 @@ // We assume a standard mouse with 15 degree steps and Qt returns // 1/8 of a degree. -#if defined (HAVE_QWHEELEVENT_ANGLEDELTA) int ydelta = -(event->angleDelta().y ()); -#else - int ydelta = -(event->delta ()); -#endif + retval.setfield ("VerticalScrollCount", octave_value (ydelta / 120)); // FIXME: Is there any way to access the number of lines a scroll step diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/RadioButtonControl.cc --- a/libgui/graphics/RadioButtonControl.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/RadioButtonControl.cc Fri May 12 08:03:14 2023 +0200 @@ -34,13 +34,10 @@ #include "Container.h" #include "QtHandlesUtils.h" -#include "octave-qobject.h" - OCTAVE_BEGIN_NAMESPACE(octave) RadioButtonControl * -RadioButtonControl::create (octave::base_qobject& oct_qobj, - octave::interpreter& interp, +RadioButtonControl::create (octave::interpreter& interp, const graphics_object& go) { Object *parent = parentObject (interp, go); @@ -50,18 +47,17 @@ Container *container = parent->innerContainer (); if (container) - return new RadioButtonControl (oct_qobj, interp, go, + return new RadioButtonControl (interp, go, new QRadioButton (container)); } return nullptr; } -RadioButtonControl::RadioButtonControl (octave::base_qobject& oct_qobj, - octave::interpreter& interp, +RadioButtonControl::RadioButtonControl (octave::interpreter& interp, const graphics_object& go, QRadioButton *radio) - : ButtonControl (oct_qobj, interp, go, radio) + : ButtonControl (interp, go, radio) { Object *parent = parentObject (interp, go); ButtonGroup *btnGroup = dynamic_cast(parent); @@ -76,7 +72,7 @@ radio->setCheckable (false); } -RadioButtonControl::~RadioButtonControl (void) +RadioButtonControl::~RadioButtonControl () { } void diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/RadioButtonControl.h --- a/libgui/graphics/RadioButtonControl.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/RadioButtonControl.h Fri May 12 08:03:14 2023 +0200 @@ -32,19 +32,16 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; class interpreter; class RadioButtonControl : public ButtonControl { public: - RadioButtonControl (octave::base_qobject& oct_qobj, - octave::interpreter& interp, const graphics_object& go, + RadioButtonControl (octave::interpreter& interp, const graphics_object& go, QRadioButton *box); - ~RadioButtonControl (void); + ~RadioButtonControl (); - static RadioButtonControl * create (octave::base_qobject& oct_qobj, - octave::interpreter& interp, + static RadioButtonControl * create (octave::interpreter& interp, const graphics_object& go); protected: diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/SliderControl.cc --- a/libgui/graphics/SliderControl.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/SliderControl.cc Fri May 12 08:03:14 2023 +0200 @@ -33,8 +33,6 @@ #include "SliderControl.h" #include "QtHandlesUtils.h" -#include "octave-qobject.h" - #include "graphics.h" #include "interpreter.h" @@ -43,8 +41,7 @@ OCTAVE_BEGIN_NAMESPACE(octave) SliderControl * -SliderControl::create (octave::base_qobject& oct_qobj, - octave::interpreter& interp, +SliderControl::create (octave::interpreter& interp, const graphics_object& go) { Object *parent = parentObject (interp, go); @@ -54,18 +51,17 @@ Container *container = parent->innerContainer (); if (container) - return new SliderControl (oct_qobj, interp, go, + return new SliderControl (interp, go, new QScrollBar (container)); } return nullptr; } -SliderControl::SliderControl (octave::base_qobject& oct_qobj, - octave::interpreter& interp, +SliderControl::SliderControl (octave::interpreter& interp, const graphics_object& go, QAbstractSlider *slider) - : BaseControl (oct_qobj, interp, go, slider), m_blockUpdates (false) + : BaseControl (interp, go, slider), m_blockUpdates (false) { uicontrol::properties& up = properties (); @@ -93,7 +89,7 @@ this, &SliderControl::valueChanged); } -SliderControl::~SliderControl (void) +SliderControl::~SliderControl () { } void diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/SliderControl.h --- a/libgui/graphics/SliderControl.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/SliderControl.h Fri May 12 08:03:14 2023 +0200 @@ -32,7 +32,6 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; class interpreter; class SliderControl : public BaseControl @@ -40,12 +39,12 @@ Q_OBJECT public: - SliderControl (octave::base_qobject& oct_qobj, octave::interpreter& interp, + SliderControl (octave::interpreter& interp, const graphics_object& go, QAbstractSlider *slider); - ~SliderControl (void); + ~SliderControl (); static SliderControl * - create (octave::base_qobject& oct_qobj, octave::interpreter& interp, + create (octave::interpreter& interp, const graphics_object& go); protected: diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/Table.cc --- a/libgui/graphics/Table.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/Table.cc Fri May 12 08:03:14 2023 +0200 @@ -48,8 +48,6 @@ #include "Table.h" #include "QtHandlesUtils.h" -#include "octave-qobject.h" - #include "graphics.h" #include "interpreter.h" #include "oct-map.h" @@ -74,43 +72,43 @@ return QSize (w, h); } -#define FORMATNUMBER(type) \ - static QString formatNumber (type d, \ - char format = 'f', \ - int precision = 4) \ - { \ - type ten = 10; \ - if (format == 'n') \ - { \ - if (d == floor (d)) \ - return QString::number (d, 'g', precision); \ - else if (d <= pow (ten, precision - 1) \ - && d > pow (ten, 1 - precision)) \ - return QString::number (d, 'f', precision); \ - else \ - return QString::number (d, 'e', precision); \ - } \ - else if (format == 'F') \ - { \ - int exponent = floor (log10 (d) / 3) * 3; \ - d *= pow (ten, -exponent); \ - return QString::number (d, 'f', precision) + "e" + \ - (exponent < 0 ? "-" : "+") + \ - QString ("%1").arg (abs (exponent), 3, 10, QChar ('0')); \ - } \ - else if (format == 'E') \ - { \ - int exponent = floor (log10 (d) / 3) * 3; \ - d *= pow (ten, -exponent); \ - return QString::number (d, \ - 'f', \ - precision - floor (log10 (d)) - 1) + \ - "e" + (exponent < 0 ? "-" : "+") + \ - QString ("%1").arg (abs (exponent), 3, 10, QChar ('0')); \ - } \ - else \ - return QString::number (d, format, precision); \ - } +#define FORMATNUMBER(type) \ +static QString formatNumber (type d, \ + char format = 'f', \ + int precision = 4) \ +{ \ + type ten = 10; \ + if (format == 'n') \ + { \ + if (d == floor (d)) \ + return QString::number (d, 'g', precision); \ + else if (d <= pow (ten, precision - 1) \ + && d > pow (ten, 1 - precision)) \ + return QString::number (d, 'f', precision); \ + else \ + return QString::number (d, 'e', precision); \ + } \ + else if (format == 'F') \ + { \ + int exponent = floor (log10 (d) / 3) * 3; \ + d *= pow (ten, -exponent); \ + return QString::number (d, 'f', precision) + "e" + \ + (exponent < 0 ? "-" : "+") + \ + QString ("%1").arg (abs (exponent), 3, 10, QChar ('0')); \ + } \ + else if (format == 'E') \ + { \ + int exponent = floor (log10 (d) / 3) * 3; \ + d *= pow (ten, -exponent); \ + return QString::number (d, \ + 'f', \ + precision - floor (log10 (d)) - 1) + \ + "e" + (exponent < 0 ? "-" : "+") + \ + QString ("%1").arg (abs (exponent), 3, 10, QChar ('0')); \ + } \ + else \ + return QString::number (d, format, precision); \ +} FORMATNUMBER(double) FORMATNUMBER(float) @@ -120,75 +118,75 @@ static QString formatComplex (Complex c, char format = 'f', int precision = 4) { return formatNumber (c.real (), format, precision) + " + " - + formatNumber (c.imag (), format, precision) + "i"; + + formatNumber (c.imag (), format, precision) + "i"; } -#define FORMAT_VALUE_EXCEPT_RAT(f,l) \ - if (format == "numeric" || format == "short") \ - text = formatNumber (value, 'n', f); \ - else if (format == "short f" || format == "shortf") \ - text = formatNumber (value, 'f', f); \ - else if (format == "short e" || format == "shorte") \ - text = formatNumber (value, 'e', f); \ - else if (format == "short eng" || format == "shorteng") \ - text = formatNumber (value, 'F', f); \ - else if (format == "short g" || format == "shortg") \ - text = formatNumber (value, 'g', f + 1); \ - else if (format == "long") \ - text = formatNumber (value, 'n', l); \ - else if (format == "long f" || format == "longf") \ - text = formatNumber (value, 'f', l); \ - else if (format == "long e" || format == "longe") \ - text = formatNumber (value, 'e', l); \ - else if (format == "long eng" || format == "longeng") \ - text = formatNumber (value, 'E', l); \ - else if (format == "long g" || format == "longg") \ - text = formatNumber (value, 'g', l + 1); \ - else if (format == "bank") \ - text = QString::number (value, 'f', 2); \ - else if (format == "+") \ - if (value > 0) \ - text = Utils::fromStdString ("+"); \ - else if (value < 0) \ - text = Utils::fromStdString ("-"); \ - else \ - text = Utils::fromStdString (""); +#define FORMAT_VALUE_EXCEPT_RAT(f,l) \ +if (format == "numeric" || format == "short") \ + text = formatNumber (value, 'n', f); \ +else if (format == "short f" || format == "shortf") \ + text = formatNumber (value, 'f', f); \ +else if (format == "short e" || format == "shorte") \ + text = formatNumber (value, 'e', f); \ +else if (format == "short eng" || format == "shorteng") \ + text = formatNumber (value, 'F', f); \ +else if (format == "short g" || format == "shortg") \ + text = formatNumber (value, 'g', f + 1); \ +else if (format == "long") \ + text = formatNumber (value, 'n', l); \ +else if (format == "long f" || format == "longf") \ + text = formatNumber (value, 'f', l); \ +else if (format == "long e" || format == "longe") \ + text = formatNumber (value, 'e', l); \ +else if (format == "long eng" || format == "longeng") \ + text = formatNumber (value, 'E', l); \ +else if (format == "long g" || format == "longg") \ + text = formatNumber (value, 'g', l + 1); \ +else if (format == "bank") \ + text = QString::number (value, 'f', 2); \ +else if (format == "+") \ + if (value > 0) \ + text = Utils::fromStdString ("+"); \ + else if (value < 0) \ + text = Utils::fromStdString ("-"); \ + else \ + text = Utils::fromStdString (""); #define FORMAT_VALUE(f,l) \ - FORMAT_VALUE_EXCEPT_RAT(f,l) \ - else if (format == "rat") \ - text = Utils::fromStdString (rational_approx (double (value), 0)); \ - else \ - { \ - text = formatNumber (value, 'n', f); \ - flag = Qt::AlignLeft ; \ - } +FORMAT_VALUE_EXCEPT_RAT(f,l) \ +else if (format == "rat") \ + text = Utils::fromStdString (rational_approx (double (value), 0)); \ +else \ + { \ + text = formatNumber (value, 'n', f); \ + flag = Qt::AlignLeft ; \ + } -#define FORMAT_UINT_VALUE() \ - text = QString::number (value); \ - if (format == "char" || format == "popup") \ - flag = Qt::AlignLeft; \ - else if (format == "+") \ - { \ - if (value > 0) \ - text = Utils::fromStdString ("+"); \ - else \ - text = Utils::fromStdString (""); \ - } +#define FORMAT_UINT_VALUE() \ +text = QString::number (value); \ +if (format == "char" || format == "popup") \ + flag = Qt::AlignLeft; \ +else if (format == "+") \ + { \ + if (value > 0) \ + text = Utils::fromStdString ("+"); \ + else \ + text = Utils::fromStdString (""); \ + } -#define FORMAT_INT_VALUE() \ - text = QString::number (value); \ - if (format == "char" || format == "popup") \ - flag = Qt::AlignLeft ; \ - else if (format == "+") \ - { \ - if (value > 0) \ - text = Utils::fromStdString ("+"); \ - else if (value < 0) \ - text = Utils::fromStdString ("-"); \ - else \ - text = Utils::fromStdString (""); \ - } +#define FORMAT_INT_VALUE() \ +text = QString::number (value); \ +if (format == "char" || format == "popup") \ + flag = Qt::AlignLeft ; \ +else if (format == "+") \ + { \ + if (value > 0) \ + text = Utils::fromStdString ("+"); \ + else if (value < 0) \ + text = Utils::fromStdString ("-"); \ + else \ + text = Utils::fromStdString (""); \ + } static std::pair qStringValueFor (octave_value val, std::string format = "") @@ -238,14 +236,14 @@ } else if (format == "rat") text = Utils::fromStdString (rational_approx (c.real (), 0)) + " + " - + Utils::fromStdString (rational_approx (c.imag (), 0)) + "i"; + + Utils::fromStdString (rational_approx (c.imag (), 0)) + "i"; else if (format == "numeric") text = QString::number (c.real (), 'g', 5) + " + " - + QString::number (c.imag (), 'g', 5) + "i"; + + QString::number (c.imag (), 'g', 5) + "i"; else { text = QString::number (c.real (), 'g', 5) + " + " - + QString::number (c.imag (), 'g', 5) + "i"; + + QString::number (c.imag (), 'g', 5) + "i"; flag = Qt::AlignLeft; } } @@ -253,52 +251,52 @@ { double value = val.double_value (); FORMAT_VALUE(4, 15) - } + } else if (val.is_single_type ()) { float value = val.float_value (); FORMAT_VALUE(4, 7) - } + } else if (val.is_int8_type ()) { short int value = val.short_value (); FORMAT_INT_VALUE() - } + } else if (val.is_uint8_type ()) { unsigned short int value = val.ushort_value (); FORMAT_UINT_VALUE() - } + } else if (val.is_int16_type ()) { int value = val.int_value (); FORMAT_INT_VALUE() - } + } else if (val.is_uint16_type ()) { unsigned int value = val.uint_value (); FORMAT_UINT_VALUE() - } + } else if (val.is_int32_type ()) { long int value = val.long_value (); FORMAT_INT_VALUE() - } + } else if (val.is_uint32_type ()) { unsigned long int value = val.ulong_value (); FORMAT_UINT_VALUE() - } + } else if (val.is_int64_type ()) { int64_t value = val.int64_value (); FORMAT_INT_VALUE() - } + } else if (val.is_uint64_type ()) { uint64_t value = val.uint64_value (); FORMAT_UINT_VALUE() - } + } else if (val.islogical ()) { bool b = val.bool_value (); @@ -357,31 +355,31 @@ // Define a macro to help with the conversion of strings to integers // FIXME: these will happily integer overflow in the (u)int64 case // - this probably doesn't matter. -#define SCANF_AND_CONVERT(name,ctype,format) \ - else if (old_value.is_ ## name ## _type ()) \ - { \ - ctype val; \ - int n; \ - const std::string cxx_str = ov.string_value (); \ - const char *c_str = cxx_str.c_str (); \ - int error = sscanf (c_str, format, &val, &n); \ - if (error != 1 || c_str[n]) \ - { \ - val = 0; \ - } \ - retval = octave_value ( octave_ ## name (val)); \ - } +#define SCANF_AND_CONVERT(name,ctype,format) \ +else if (old_value.is_ ## name ## _type ()) \ + { \ + ctype val; \ + int n; \ + const std::string cxx_str = ov.string_value (); \ + const char *c_str = cxx_str.c_str (); \ + int error = sscanf (c_str, format, &val, &n); \ + if (error != 1 || c_str[n]) \ + { \ + val = 0; \ + } \ + retval = octave_value ( octave_ ## name (val)); \ + } if (old_value.is_string ()) retval = ov; SCANF_AND_CONVERT(int8, int64_t, "%" PRId64 " %n") - SCANF_AND_CONVERT(uint8, uint64_t, "%" PRIu64 " %n") - SCANF_AND_CONVERT(int16, int64_t, "%" PRId64 " %n") - SCANF_AND_CONVERT(uint16, uint64_t, "%" PRIu64 " %n") - SCANF_AND_CONVERT(int32, int64_t, "%" PRId64 " %n") - SCANF_AND_CONVERT(uint32, uint64_t, "%" PRIu64 " %n") - SCANF_AND_CONVERT(int64, int64_t, "%" PRId64 " %n") - SCANF_AND_CONVERT(uint64, uint64_t, "%" PRIu64 " %n") + SCANF_AND_CONVERT(uint8, uint64_t, "%" PRIu64 " %n") + SCANF_AND_CONVERT(int16, int64_t, "%" PRId64 " %n") + SCANF_AND_CONVERT(uint16, uint64_t, "%" PRIu64 " %n") + SCANF_AND_CONVERT(int32, int64_t, "%" PRId64 " %n") + SCANF_AND_CONVERT(uint32, uint64_t, "%" PRIu64 " %n") + SCANF_AND_CONVERT(int64, int64_t, "%" PRId64 " %n") + SCANF_AND_CONVERT(uint64, uint64_t, "%" PRIu64 " %n") #undef SCANF_AND_CONVERT @@ -432,7 +430,7 @@ } Table * -Table::create (octave::base_qobject& oct_qobj, octave::interpreter& interp, +Table::create (octave::interpreter& interp, const graphics_object& go) { Object *parent = parentObject (interp, go); @@ -442,15 +440,15 @@ Container *container = parent->innerContainer (); if (container) - return new Table (oct_qobj, interp, go, new QTableWidget (container)); + return new Table (interp, go, new QTableWidget (container)); } return 0; } -Table::Table (octave::base_qobject& oct_qobj, octave::interpreter& interp, +Table::Table (octave::interpreter& interp, const graphics_object& go, QTableWidget *tableWidget) - : Object (oct_qobj, interp, go, tableWidget), m_tableWidget (tableWidget), + : Object (interp, go, tableWidget), m_tableWidget (tableWidget), m_curData (), m_blockUpdates (false) { qObject ()->setObjectName ("UItable"); @@ -487,7 +485,7 @@ this, &Table::itemSelectionChanged); } -Table::~Table (void) { } +Table::~Table () { } void Table::itemSelectionChanged () @@ -538,7 +536,6 @@ octave_value edit_data, octave_value error) { - if (!(properties ().get_celleditcallback ().isempty ())) { Matrix indices = Matrix (1, 2); @@ -629,8 +626,8 @@ else { octave_value old_data = data.is_matrix_type () - ? data.fast_elem_extract (row + col * data.rows ()) - : octave_value (); + ? data.fast_elem_extract (row + col * data.rows ()) + : octave_value (); data.fast_elem_insert (row + col * data.rows (), attempt_type_conversion (edit_data, old_data)); @@ -877,7 +874,7 @@ } void -Table::redraw (void) +Table::redraw () { update (uitable::properties::ID_POSITION); } @@ -980,7 +977,7 @@ } void -Table::updateColumnname (void) +Table::updateColumnname () { uitable::properties& tp = properties (); @@ -1076,7 +1073,7 @@ } void -Table::updateColumnwidth (void) +Table::updateColumnwidth () { uitable::properties& tp = properties (); @@ -1304,7 +1301,7 @@ } void -Table::updateEnable (void) +Table::updateEnable () { uitable::properties& tp = properties (); bool enabled = tp.is_enable (); @@ -1362,7 +1359,7 @@ } void -Table::updateExtent (void) +Table::updateExtent () { QSize s = realQSizeForTable (m_tableWidget); Matrix extent = Matrix (1, 4); @@ -1375,7 +1372,7 @@ } void -Table::updatePalette (void) +Table::updatePalette () { uitable::properties& tp = properties (); @@ -1392,7 +1389,7 @@ } void -Table::updateRowname (void) +Table::updateRowname () { uitable::properties& tp = properties (); @@ -1490,7 +1487,7 @@ } void -Table::updateRearrangeableColumns (void) +Table::updateRearrangeableColumns () { uitable::properties& tp = properties (); @@ -1628,12 +1625,12 @@ { if (col - 1 >= 0) m_tableWidget->setCurrentCell - (m_tableWidget->rowCount () - 1, - col - 1); + (m_tableWidget->rowCount () - 1, + col - 1); else m_tableWidget->setCurrentCell - (m_tableWidget->rowCount () - 1, - m_tableWidget->columnCount () - 1); + (m_tableWidget->rowCount () - 1, + m_tableWidget->columnCount () - 1); } } } diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/Table.h --- a/libgui/graphics/Table.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/Table.h Fri May 12 08:03:14 2023 +0200 @@ -34,7 +34,6 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; class interpreter; class Container; @@ -44,35 +43,35 @@ Q_OBJECT public: - Table (octave::base_qobject& oct_qobj, octave::interpreter& interp, + Table (octave::interpreter& interp, const graphics_object& go, QTableWidget *tableWidget); - ~Table (void); + ~Table (); - Container * innerContainer (void) { return m_container; } + Container * innerContainer () { return m_container; } bool eventFilter (QObject *watched, QEvent *event); static Table * - create (octave::base_qobject& oct_qobj, octave::interpreter& interp, + create (octave::interpreter& interp, const graphics_object& go); protected: void update (int pId); - void redraw (void); - void updateColumnname (void); - void updateColumnwidth (void); - void updateData (void); - void updateEnable (void); - void updateExtent (void); - void updatePalette (void); - void updateRearrangeableColumns (void); - void updateRowname (void); + void redraw (); + void updateColumnname (); + void updateColumnwidth (); + void updateData (); + void updateEnable (); + void updateExtent (); + void updatePalette (); + void updateRearrangeableColumns (); + void updateRowname (); private slots: void itemChanged (QTableWidgetItem *item); void comboBoxCurrentIndexChanged (const QString& value); void cellClicked (int row, int col); - void itemSelectionChanged (void); + void itemSelectionChanged (); private: Container *m_container; diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/TextControl.cc --- a/libgui/graphics/TextControl.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/TextControl.cc Fri May 12 08:03:14 2023 +0200 @@ -33,13 +33,10 @@ #include "TextControl.h" #include "QtHandlesUtils.h" -#include "octave-qobject.h" - OCTAVE_BEGIN_NAMESPACE(octave) TextControl * -TextControl::create (octave::base_qobject& oct_qobj, - octave::interpreter& interp, const graphics_object& go) +TextControl::create (octave::interpreter& interp, const graphics_object& go) { Object *parent = parentObject (interp, go); @@ -48,16 +45,15 @@ Container *container = parent->innerContainer (); if (container) - return new TextControl (oct_qobj, interp, go, new QLabel (container)); + return new TextControl (interp, go, new QLabel (container)); } return nullptr; } -TextControl::TextControl (octave::base_qobject& oct_qobj, - octave::interpreter& interp, +TextControl::TextControl (octave::interpreter& interp, const graphics_object& go, QLabel *label) - : BaseControl (oct_qobj, interp, go, label) + : BaseControl (interp, go, label) { uicontrol::properties& up = properties (); @@ -65,11 +61,11 @@ label->setTextFormat (Qt::PlainText); label->setWordWrap (false); label->setAlignment (Utils::fromHVAlign (up.get_horizontalalignment (), - up.get_verticalalignment ())); + up.get_verticalalignment ())); label->setText (Utils::fromStringVector (up.get_string_vector ()).join ("\n")); } -TextControl::~TextControl (void) +TextControl::~TextControl () { } void @@ -87,7 +83,7 @@ case uicontrol::properties::ID_HORIZONTALALIGNMENT: case uicontrol::properties::ID_VERTICALALIGNMENT: label->setAlignment (Utils::fromHVAlign (up.get_horizontalalignment (), - up.get_verticalalignment ())); + up.get_verticalalignment ())); break; default: diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/TextControl.h --- a/libgui/graphics/TextControl.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/TextControl.h Fri May 12 08:03:14 2023 +0200 @@ -32,18 +32,17 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; class interpreter; class TextControl : public BaseControl { public: - TextControl (octave::base_qobject& oct_qobj, octave::interpreter& interp, + TextControl (octave::interpreter& interp, const graphics_object& go, QLabel *label); - ~TextControl (void); + ~TextControl (); static TextControl * - create (octave::base_qobject& oct_qobj, octave::interpreter& interp, + create (octave::interpreter& interp, const graphics_object& go); protected: diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/TextEdit.h --- a/libgui/graphics/TextEdit.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/TextEdit.h Fri May 12 08:03:14 2023 +0200 @@ -36,11 +36,11 @@ public: TextEdit (QWidget *xparent) : QTextEdit (xparent) { } - ~TextEdit (void) = default; + ~TextEdit () = default; signals: - void editingFinished (void); - void returnPressed (void); + void editingFinished (); + void returnPressed (); protected: void focusOutEvent (QFocusEvent *event); diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/ToggleButtonControl.cc --- a/libgui/graphics/ToggleButtonControl.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/ToggleButtonControl.cc Fri May 12 08:03:14 2023 +0200 @@ -34,13 +34,10 @@ #include "Container.h" #include "QtHandlesUtils.h" -#include "octave-qobject.h" - OCTAVE_BEGIN_NAMESPACE(octave) ToggleButtonControl * -ToggleButtonControl::create (octave::base_qobject& oct_qobj, - octave::interpreter& interp, +ToggleButtonControl::create (octave::interpreter& interp, const graphics_object& go) { Object *parent = parentObject (interp, go); @@ -50,18 +47,17 @@ Container *container = parent->innerContainer (); if (container) - return new ToggleButtonControl (oct_qobj, interp, go, + return new ToggleButtonControl (interp, go, new QPushButton (container)); } return nullptr; } -ToggleButtonControl::ToggleButtonControl (octave::base_qobject& oct_qobj, - octave::interpreter& interp, +ToggleButtonControl::ToggleButtonControl (octave::interpreter& interp, const graphics_object& go, QPushButton *btn) - : ButtonControl (oct_qobj, interp, go, btn) + : ButtonControl (interp, go, btn) { Object *parent = parentObject (interp, go); ButtonGroup *btnGroup = dynamic_cast(parent); @@ -79,7 +75,7 @@ btn->setIconSize (QSize (cdat.columns (), cdat.rows ())); } -ToggleButtonControl::~ToggleButtonControl (void) +ToggleButtonControl::~ToggleButtonControl () { } void diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/ToggleButtonControl.h --- a/libgui/graphics/ToggleButtonControl.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/ToggleButtonControl.h Fri May 12 08:03:14 2023 +0200 @@ -32,19 +32,17 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; class interpreter; class ToggleButtonControl : public ButtonControl { public: - ToggleButtonControl (octave::base_qobject& oct_qobj, - octave::interpreter& interp, + ToggleButtonControl (octave::interpreter& interp, const graphics_object& go, QPushButton *box); - ~ToggleButtonControl (void); + ~ToggleButtonControl (); static ToggleButtonControl * - create (octave::base_qobject& oct_qobj, octave::interpreter& interp, + create (octave::interpreter& interp, const graphics_object& go); protected: diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/ToggleTool.cc --- a/libgui/graphics/ToggleTool.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/ToggleTool.cc Fri May 12 08:03:14 2023 +0200 @@ -31,13 +31,10 @@ #include "ToolBarButton.cc" -#include "octave-qobject.h" - OCTAVE_BEGIN_NAMESPACE(octave) ToggleTool * -ToggleTool::create (octave::base_qobject& oct_qobj, - octave::interpreter& interp, const graphics_object& go) +ToggleTool::create (octave::interpreter& interp, const graphics_object& go) { Object *parent = parentObject (interp, go); @@ -46,17 +43,16 @@ QWidget *parentWidget = parent->qWidget (); if (parentWidget) - return new ToggleTool (oct_qobj, interp, go, + return new ToggleTool (interp, go, new QAction (parentWidget)); } return nullptr; } -ToggleTool::ToggleTool (octave::base_qobject& oct_qobj, - octave::interpreter& interp, +ToggleTool::ToggleTool (octave::interpreter& interp, const graphics_object& go, QAction *action) - : ToolBarButton (oct_qobj, interp, go, action) + : ToolBarButton (interp, go, action) { uitoggletool::properties& tp = properties (); @@ -66,7 +62,7 @@ connect (action, &QAction::toggled, this, &ToggleTool::triggered); } -ToggleTool::~ToggleTool (void) +ToggleTool::~ToggleTool () { } void diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/ToggleTool.h --- a/libgui/graphics/ToggleTool.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/ToggleTool.h Fri May 12 08:03:14 2023 +0200 @@ -30,7 +30,6 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; class interpreter; class ToggleTool : public ToolBarButton @@ -38,13 +37,13 @@ Q_OBJECT public: - ToggleTool (octave::base_qobject& oct_qobj, octave::interpreter& interp, + ToggleTool (octave::interpreter& interp, const graphics_object& go, QAction *action); - ~ToggleTool (void); + ~ToggleTool (); static ToggleTool * - create (octave::base_qobject& oct_qobj, octave::interpreter& interp, + create (octave::interpreter& interp, const graphics_object& go); protected: diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/ToolBar.cc --- a/libgui/graphics/ToolBar.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/ToolBar.cc Fri May 12 08:03:14 2023 +0200 @@ -42,11 +42,10 @@ #include "QtHandlesUtils.h" #include "gui-preferences-global.h" -#include "octave-qobject.h" OCTAVE_BEGIN_NAMESPACE(octave) -static QIcon makeEmptyIcon (void) +static QIcon makeEmptyIcon () { QPixmap pix (16, 16); @@ -69,7 +68,7 @@ } ToolBar * -ToolBar::create (octave::base_qobject& oct_qobj, octave::interpreter& interp, +ToolBar::create (octave::interpreter& interp, const graphics_object& go) { Object *parent = parentObject (interp, go); @@ -79,16 +78,16 @@ QWidget *parentWidget = parent->qWidget (); if (parentWidget) - return new ToolBar (oct_qobj, interp, go, + return new ToolBar (interp, go, new QToolBar (parentWidget)); } return nullptr; } -ToolBar::ToolBar (octave::base_qobject& oct_qobj, octave::interpreter& interp, +ToolBar::ToolBar (octave::interpreter& interp, const graphics_object& go, QToolBar *bar) - : Object (oct_qobj, interp, go, bar), m_empty (nullptr), m_figure (nullptr) + : Object (interp, go, bar), m_empty (nullptr), m_figure (nullptr) { uitoolbar::properties& tp = properties (); @@ -109,7 +108,7 @@ bar->installEventFilter (this); } -ToolBar::~ToolBar (void) +ToolBar::~ToolBar () { } void @@ -169,13 +168,13 @@ } void -ToolBar::hideEmpty (void) +ToolBar::hideEmpty () { m_empty->setVisible (false); } void -ToolBar::beingDeleted (void) +ToolBar::beingDeleted () { if (m_figure) { diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/ToolBar.h --- a/libgui/graphics/ToolBar.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/ToolBar.h Fri May 12 08:03:14 2023 +0200 @@ -33,7 +33,6 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; class interpreter; class Figure; @@ -43,24 +42,24 @@ Q_OBJECT public: - ToolBar (octave::base_qobject& oct_qobj, octave::interpreter& interp, + ToolBar (octave::interpreter& interp, const graphics_object& go, QToolBar *bar); - ~ToolBar (void); + ~ToolBar (); static ToolBar * - create (octave::base_qobject& oct_qobj, octave::interpreter& interp, + create (octave::interpreter& interp, const graphics_object& go); - Container * innerContainer (void) { return nullptr; } + Container * innerContainer () { return nullptr; } bool eventFilter (QObject *watched, QEvent *event); protected: void update (int pId); - void beingDeleted (void); + void beingDeleted (); private slots: - void hideEmpty (void); + void hideEmpty (); private: QAction *m_empty; diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/ToolBarButton.cc --- a/libgui/graphics/ToolBarButton.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/ToolBarButton.cc Fri May 12 08:03:14 2023 +0200 @@ -34,16 +34,14 @@ #include "ToolBarButton.h" #include "QtHandlesUtils.h" -#include "octave-qobject.h" #include "gui-preferences-global.h" OCTAVE_BEGIN_NAMESPACE(octave) template -ToolBarButton::ToolBarButton (octave::base_qobject& oct_qobj, - octave::interpreter& interp, +ToolBarButton::ToolBarButton (octave::interpreter& interp, const graphics_object& go, QAction *action) -: Object (oct_qobj, interp, go, action), m_separator (nullptr) + : Object (interp, go, action), m_separator (nullptr) { typename T::properties& tp = properties (); @@ -81,7 +79,7 @@ } template -ToolBarButton::~ToolBarButton (void) +ToolBarButton::~ToolBarButton () { } template diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/ToolBarButton.h --- a/libgui/graphics/ToolBarButton.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/ToolBarButton.h Fri May 12 08:03:14 2023 +0200 @@ -33,7 +33,6 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; class interpreter; class Container; @@ -42,11 +41,11 @@ class ToolBarButton : public Object { public: - ToolBarButton (octave::base_qobject& oct_qobj, octave::interpreter& interp, + ToolBarButton (octave::interpreter& interp, const graphics_object& go, QAction *action); - ~ToolBarButton (void); + ~ToolBarButton (); - Container * innerContainer (void) { return nullptr; } + Container * innerContainer () { return nullptr; } protected: void update (int pId); diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/annotation-dialog.cc --- a/libgui/graphics/annotation-dialog.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/annotation-dialog.cc Fri May 12 08:03:14 2023 +0200 @@ -33,19 +33,16 @@ #include "gui-settings.h" #include "gui-preferences-gp.h" -#include "octave-qobject.h" +#include "gui-settings.h" #include "QtHandlesUtils.h" #include "annotation-dialog.h" #include "ui-annotation-dialog.h" -using namespace octave; - -annotation_dialog::annotation_dialog (octave::base_qobject& oct_qobj, - QWidget *p, const octave_value_list& pr): - QDialog (p), m_octave_qobj (oct_qobj), ui (new Ui::annotation_dialog) +annotation_dialog::annotation_dialog (QWidget *p, const octave_value_list& pr): + QDialog (p), m_ui (new Ui::annotation_dialog) { - props = pr; + m_props = pr; init (); } @@ -53,36 +50,34 @@ void annotation_dialog::init () { - ui->setupUi (this); + m_ui->setupUi (this); - octave::resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - - octave::gui_settings *settings = rmgr.get_settings (); + octave::gui_settings settings; // restore last geometry - if (settings && settings->contains (gp_annotation_geometry.key)) - restoreGeometry (settings->value (gp_annotation_geometry).toByteArray ()); + if (settings.contains (gp_annotation_geometry.settings_key ())) + restoreGeometry (settings.byte_array_value (gp_annotation_geometry)); // connect signals - connect (ui->button_box, &QDialogButtonBox::clicked, + connect (m_ui->button_box, &QDialogButtonBox::clicked, this, &annotation_dialog::button_clicked); - connect (ui->edit_string, &QLineEdit::textChanged, + connect (m_ui->edit_string, &QLineEdit::textChanged, this, &annotation_dialog::edit_string_changed); - connect (ui->btn_color, &QPushButton::clicked, + connect (m_ui->btn_color, &QPushButton::clicked, this, &annotation_dialog::prompt_for_color); - connect (ui->btn_background_color, &QPushButton::clicked, + connect (m_ui->btn_background_color, &QPushButton::clicked, this, &annotation_dialog::prompt_for_color); - connect (ui->btn_edge_color, &QPushButton::clicked, + connect (m_ui->btn_edge_color, &QPushButton::clicked, this, &annotation_dialog::prompt_for_color); // set gui element to default values - ui->cb_fit_box_to_text->setChecked (true); - ui->cb_horz_align->setCurrentIndex (ui->cb_horz_align->findText ("left")); - ui->cb_vert_align->setCurrentIndex (ui->cb_vert_align->findText ("middle")); + m_ui->cb_fit_box_to_text->setChecked (true); + m_ui->cb_horz_align->setCurrentIndex (m_ui->cb_horz_align->findText ("left")); + m_ui->cb_vert_align->setCurrentIndex (m_ui->cb_vert_align->findText ("middle")); // set gui elements to any values from input properties set_gui_props (); @@ -90,7 +85,7 @@ annotation_dialog::~annotation_dialog () { - delete ui; + delete m_ui; } // internal slots @@ -99,15 +94,12 @@ annotation_dialog::button_clicked (QAbstractButton *button) { QDialogButtonBox::ButtonRole button_role - = ui->button_box->buttonRole (button); + = m_ui->button_box->buttonRole (button); - octave::resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - - octave::gui_settings *settings = rmgr.get_settings (); + octave::gui_settings settings; // save position - if (settings) - settings->setValue (gp_annotation_geometry.key, saveGeometry ()); + settings.setValue (gp_annotation_geometry.settings_key (), saveGeometry ()); if (button_role == QDialogButtonBox::ApplyRole || button_role == QDialogButtonBox::AcceptRole) @@ -123,83 +115,83 @@ octave_value_list annotation_dialog::get_properties () const { - return props; + return m_props; } void annotation_dialog::get_gui_props () { // set props to the values of the gui - props = octave_value_list (); + m_props = octave_value_list (); Matrix position(1, 4); - position(0) = ui->sb_x->value (); - position(1) = ui->sb_y->value (); - position(2) = ui->sb_width->value (); - position(3) = ui->sb_height->value (); - props.append (ovl ("textbox", position)); + position(0) = m_ui->sb_x->value (); + position(1) = m_ui->sb_y->value (); + position(2) = m_ui->sb_width->value (); + position(3) = m_ui->sb_height->value (); + m_props.append (ovl ("textbox", position)); - props.append (ovl ("string", ui->edit_string->text ().toStdString ())); - props.append (ovl ("fitboxtotext", - ui->cb_fit_box_to_text->isChecked () ? "on" : "off")); + m_props.append (ovl ("string", m_ui->edit_string->text ().toStdString ())); + m_props.append (ovl ("fitboxtotext", + m_ui->cb_fit_box_to_text->isChecked () ? "on" : "off")); // FIXME: only "normalized" units is selectable, change the code below // once more units are added in the UI. std::string tmpstr; - props.append (ovl ("units", "normalized")); + m_props.append (ovl ("units", "normalized")); - tmpstr = (ui->cb_horz_align->currentIndex () == 0 ? "left" : - (ui->cb_horz_align->currentIndex () == 1 ? "center" : "right")); - props.append (ovl ("horizontalalignment", tmpstr)); + tmpstr = (m_ui->cb_horz_align->currentIndex () == 0 ? "left" : + (m_ui->cb_horz_align->currentIndex () == 1 ? "center" : "right")); + m_props.append (ovl ("horizontalalignment", tmpstr)); - tmpstr = (ui->cb_vert_align->currentIndex () == 0 ? "top" : - (ui->cb_horz_align->currentIndex () == 1 ? "middle" : "bottom")); - props.append (ovl ("verticalalignment", tmpstr)); + tmpstr = (m_ui->cb_vert_align->currentIndex () == 0 ? "top" : + (m_ui->cb_horz_align->currentIndex () == 1 ? "middle" : "bottom")); + m_props.append (ovl ("verticalalignment", tmpstr)); - tmpstr = ui->cb_font_name->currentText ().toStdString (); - props.append (ovl ("fontname", tmpstr)); + tmpstr = m_ui->cb_font_name->currentText ().toStdString (); + m_props.append (ovl ("fontname", tmpstr)); - props.append (ovl ("fontsize", ui->sb_font_size->value ())); - props.append (ovl ("fontweight", - ui->cb_font_bold->isChecked () ? "bold" : "normal")); - props.append (ovl ("fontangle", - ui->cb_font_italic->isChecked () ? "italic" : "normal")); - props.append (ovl ("color", Utils::toRgb (ui->btn_color->palette (). + m_props.append (ovl ("fontsize", m_ui->sb_font_size->value ())); + m_props.append (ovl ("fontweight", + m_ui->cb_font_bold->isChecked () ? "bold" : "normal")); + m_props.append (ovl ("fontangle", + m_ui->cb_font_italic->isChecked () ? "italic" : "normal")); + m_props.append (ovl ("color", octave::Utils::toRgb (m_ui->btn_color->palette (). color (QPalette::Button)))); // FIXME: only "none" linestyle is selectable, change the code bellow // once more linestyles are added in the UI. - props.append (ovl ("linestyle", "none")); + m_props.append (ovl ("linestyle", "none")); } void annotation_dialog::set_gui_props () { // set the gui to the values from the props - octave_idx_type len = props.length (); + octave_idx_type len = m_props.length (); for (int i=0; i= 2) { - ui->sb_x->setValue (position(0)); - ui->sb_y->setValue (position(1)); + m_ui->sb_x->setValue (position(0)); + m_ui->sb_y->setValue (position(1)); } else { - ui->sb_x->setValue (0); - ui->sb_y->setValue (0); + m_ui->sb_x->setValue (0); + m_ui->sb_y->setValue (0); } if (nels >= 4) { - ui->sb_width->setValue (position(2)); - ui->sb_height->setValue (position(3)); + m_ui->sb_width->setValue (position(2)); + m_ui->sb_height->setValue (position(3)); } // FIXME: Should there be an else branch here? // In annotation.m "textbox" is forced to have a 4-elem vector. @@ -207,65 +199,65 @@ else if (name == "string") { // FIXME: handle if is array of strings ? - ui->edit_string->setText (props(2*i +1).string_value ().c_str ()); + m_ui->edit_string->setText (m_props(2*i +1).string_value ().c_str ()); } else if (name == "fitboxtotext") { - ui->cb_fit_box_to_text->setChecked (props(1*i +1).string_value () == "on"); + m_ui->cb_fit_box_to_text->setChecked (m_props(1*i +1).string_value () == "on"); } else if (name == "units") { - ui->cb_units->setCurrentIndex - (ui->cb_units->findText (props(1*i +1).string_value ().c_str ())); + m_ui->cb_units->setCurrentIndex + (m_ui->cb_units->findText (m_props(1*i +1).string_value ().c_str ())); } else if (name == "horizontalalignment") { - ui->cb_horz_align->setCurrentIndex - (ui->cb_horz_align->findText (props(1*i +1).string_value ().c_str ())); + m_ui->cb_horz_align->setCurrentIndex + (m_ui->cb_horz_align->findText (m_props(1*i +1).string_value ().c_str ())); } else if (name == "verticalalignment") { - ui->cb_vert_align->setCurrentIndex - (ui->cb_vert_align->findText (props(1*i +1).string_value ().c_str ())); + m_ui->cb_vert_align->setCurrentIndex + (m_ui->cb_vert_align->findText (m_props(1*i +1).string_value ().c_str ())); } else if (name == "fontname") { - ui->cb_vert_align->setCurrentIndex - (ui->cb_font_name->findText (props(1*i +1).string_value ().c_str ())); + m_ui->cb_vert_align->setCurrentIndex + (m_ui->cb_font_name->findText (m_props(1*i +1).string_value ().c_str ())); } else if (name == "fontsize") { - ui->sb_font_size->setValue (props(1*i +1).float_value ()); + m_ui->sb_font_size->setValue (m_props(1*i +1).float_value ()); } else if (name == "fontweight") { - ui->cb_font_bold->setChecked (props(1*i +1).string_value () == "bold"); + m_ui->cb_font_bold->setChecked (m_props(1*i +1).string_value () == "bold"); } else if (name == "fontangle") { - ui->cb_font_italic->setChecked (props(1*i +1).string_value () == "italic"); + m_ui->cb_font_italic->setChecked (m_props(1*i +1).string_value () == "italic"); } else if (name == "color") { QColor color; - if (props(1*i +1).is_matrix_type ()) - color = Utils::fromRgb (props(2*i +1).matrix_value ()); + if (m_props(1*i +1).is_matrix_type ()) + color = octave::Utils::fromRgb (m_props(2*i +1).matrix_value ()); else - color.setNamedColor (props(2*i +1).string_value ().c_str ()); + color.setNamedColor (m_props(2*i +1).string_value ().c_str ()); if (color.isValid ()) - ui->btn_color->setPalette (QPalette (color)); + m_ui->btn_color->setPalette (QPalette (color)); } } - edit_string_changed (ui->edit_string->text ()); + edit_string_changed (m_ui->edit_string->text ()); } void annotation_dialog::edit_string_changed (const QString& str) { - ui->button_box->button (QDialogButtonBox::Ok)->setEnabled (str.length () > 0); + m_ui->button_box->button (QDialogButtonBox::Ok)->setEnabled (str.length () > 0); } void diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/annotation-dialog.h --- a/libgui/graphics/annotation-dialog.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/annotation-dialog.h Fri May 12 08:03:14 2023 +0200 @@ -32,20 +32,16 @@ #include "ovl.h" -OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; -OCTAVE_END_NAMESPACE(octave) - -OCTAVE_BEGIN_NAMESPACE(Ui) -class annotation_dialog; -OCTAVE_END_NAMESPACE(Ui) +namespace Ui +{ + class annotation_dialog; +} class annotation_dialog : public QDialog { Q_OBJECT public: - annotation_dialog (octave::base_qobject& oct_qobj, QWidget *parent, - const octave_value_list& pr); + annotation_dialog (QWidget *parent, const octave_value_list& pr); ~annotation_dialog (); octave_value_list get_properties () const; @@ -62,9 +58,8 @@ void get_gui_props (); void set_gui_props (); - octave::base_qobject& m_octave_qobj; - Ui::annotation_dialog *ui; - octave_value_list props; + Ui::annotation_dialog *m_ui; + octave_value_list m_props; }; #endif diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/gl-select.cc --- a/libgui/graphics/gl-select.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/gl-select.cc Fri May 12 08:03:14 2023 +0200 @@ -32,7 +32,7 @@ OCTAVE_BEGIN_NAMESPACE(octave) void -opengl_selector::apply_pick_matrix (void) +opengl_selector::apply_pick_matrix () { GLdouble p_matrix[16]; @@ -47,12 +47,12 @@ Matrix viewport = get_viewport_scaled (); - if (size > 0) + if (m_size > 0) { - m_glfcns.glTranslatef ((viewport(2) - 2 * (xp - viewport(0))) / size, - (viewport(3) - 2 * (yp - viewport(1))) / size, 0); + m_glfcns.glTranslatef ((viewport(2) - 2 * (m_xp - viewport(0))) / m_size, + (viewport(3) - 2 * (m_yp - viewport(1))) / m_size, 0); - m_glfcns.glScalef (viewport(2) / size, viewport(3) / size, 1.0); + m_glfcns.glScalef (viewport(2) / m_size, viewport(3) / m_size, 1.0); } m_glfcns.glMultMatrixd (p_matrix); @@ -81,8 +81,8 @@ m_glfcns.glEnable (GL_DEPTH_TEST); m_glfcns.glDepthFunc (GL_LEQUAL); - xp = x; - yp = y; + m_xp = x; + m_yp = y; GLuint select_buffer[BUFFER_SIZE]; @@ -90,7 +90,7 @@ m_glfcns.glRenderMode (GL_SELECT); m_glfcns.glInitNames (); - object_map.clear (); + m_object_map.clear (); draw (ax); @@ -117,7 +117,7 @@ if ((flags & select_ignore_hittest) == 0) { - graphics_object go = object_map[name]; + graphics_object go = m_object_map[name]; if (! go.get_properties ().is_hittest ()) candidate = false; @@ -136,12 +136,12 @@ } if (current_name != 0xffffffff) - obj = object_map[current_name]; + obj = m_object_map[current_name]; } else if (hits < 0) warning ("opengl_selector::select: selection buffer overflow"); - object_map.clear (); + m_object_map.clear (); return obj; } @@ -149,9 +149,9 @@ void opengl_selector::draw (const graphics_object& go, bool toplevel) { - GLuint name = object_map.size (); + GLuint name = m_object_map.size (); - object_map[name] = go; + m_object_map[name] = go; m_glfcns.glPushName (name); set_selecting (true); opengl_renderer::draw (go, toplevel); diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/gl-select.h --- a/libgui/graphics/gl-select.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/gl-select.h Fri May 12 08:03:14 2023 +0200 @@ -44,10 +44,10 @@ { public: opengl_selector (opengl_functions& glfcns) - : opengl_renderer (glfcns), size (5) + : opengl_renderer (glfcns), m_size (5) { } - virtual ~opengl_selector (void) = default; + virtual ~opengl_selector () = default; graphics_object select (const graphics_object& ax, int x, int y, int flags = 0); @@ -61,27 +61,27 @@ virtual void setup_opengl_transformation (const axes::properties& props); - virtual void init_marker (const std::string& m, double size, float width); + virtual void init_marker (const std::string& m, double m_size, float width); virtual Matrix render_text (const std::string& txt, double x, double y, double z, int halign, int valign, double rotation = 0.0); private: - void apply_pick_matrix (void); + void apply_pick_matrix (); void fake_text (double x, double y, double z, const Matrix& bbox, bool use_scale = true); private: // The mouse coordinate of the selection/picking point - int xp, yp; + int m_xp, m_yp; // The size (in pixels) of the picking window - int size; + int m_size; // The OpenGL name mapping - std::map object_map; + std::map m_object_map; }; OCTAVE_END_NAMESPACE(octave) diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/module.mk --- a/libgui/graphics/module.mk Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/module.mk Fri May 12 08:03:14 2023 +0200 @@ -1,5 +1,3 @@ -if AMCOND_BUILD_QT_GRAPHICS - OCTAVE_GUI_GRAPHICS_MOC = \ %reldir%/moc-ButtonControl.cc \ %reldir%/moc-ButtonGroup.cc \ @@ -9,6 +7,7 @@ %reldir%/moc-EditControl.cc \ %reldir%/moc-Figure.cc \ %reldir%/moc-FigureWindow.cc \ + %reldir%/moc-GLCanvas.cc \ %reldir%/moc-ListBoxControl.cc \ %reldir%/moc-Menu.cc \ %reldir%/moc-Object.cc \ @@ -128,7 +127,7 @@ $(FONTCONFIG_CPPFLAGS) \ $(HDF5_CPPFLAGS) \ @OCTGUI_DLL_DEFS@ \ - @QT_OPENGL_CPPFLAGS@ \ + @QT_CPPFLAGS@ \ -Ilibgui/graphics -I$(srcdir)/libgui/graphics \ -Ilibgui/src -I$(srcdir)/libgui/src \ -Iliboctave \ @@ -153,5 +152,3 @@ $(libgraphics_MOC) \ $(libgraphics_MOC_H) \ $(libgraphics_UI_H) - -endif diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/qopengl-functions.h --- a/libgui/graphics/qopengl-functions.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/qopengl-functions.h Fri May 12 08:03:14 2023 +0200 @@ -42,7 +42,7 @@ { public: - qopengl_functions (void) + qopengl_functions () #if defined (HAVE_QOPENGLFUNCTIONS_1_1) : m_glfcns () #endif @@ -52,9 +52,9 @@ qopengl_functions& operator = (const qopengl_functions&) = default; - ~qopengl_functions (void) = default; + ~qopengl_functions () = default; - void init (void) + void init () { #if defined (HAVE_QOPENGLFUNCTIONS_1_1) m_glfcns.initializeOpenGLFunctions (); @@ -176,17 +176,17 @@ m_glfcns.glEnable (cap); } - void glEndList (void) + void glEndList () { m_glfcns.glEndList (); } - void glEnd (void) + void glEnd () { m_glfcns.glEnd (); } - void glFinish (void) + void glFinish () { m_glfcns.glFinish (); } @@ -211,7 +211,7 @@ m_glfcns.glGetDoublev (pname, data); } - GLenum glGetError (void) + GLenum glGetError () { return m_glfcns.glGetError (); } @@ -236,7 +236,7 @@ m_glfcns.glHint (target, mode); } - void glInitNames (void) + void glInitNames () { m_glfcns.glInitNames (); } @@ -261,7 +261,7 @@ m_glfcns.glLineWidth (width); } - void glLoadIdentity (void) + void glLoadIdentity () { m_glfcns.glLoadIdentity (); } @@ -327,17 +327,17 @@ m_glfcns.glPolygonOffset (factor, units); } - void glPopAttrib (void) + void glPopAttrib () { m_glfcns.glPopAttrib (); } - void glPopMatrix (void) + void glPopMatrix () { m_glfcns.glPopMatrix (); } - void glPopName (void) + void glPopName () { m_glfcns.glPopName (); } @@ -347,7 +347,7 @@ m_glfcns.glPushAttrib (mask); } - void glPushMatrix (void) + void glPushMatrix () { m_glfcns.glPushMatrix (); } diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/qt-graphics-toolkit.cc --- a/libgui/graphics/qt-graphics-toolkit.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/qt-graphics-toolkit.cc Fri May 12 08:03:14 2023 +0200 @@ -57,8 +57,6 @@ #include "ToolBar.h" #include "qt-graphics-toolkit.h" -#include "octave-qobject.h" - #include "event-manager.h" #include "graphics.h" #include "interpreter.h" @@ -97,10 +95,8 @@ return ""; } -qt_graphics_toolkit::qt_graphics_toolkit (octave::interpreter& interp, - octave::base_qobject& oct_qobj) - : QObject (), base_graphics_toolkit ("qt"), m_interpreter (interp), - m_octave_qobj (oct_qobj) +qt_graphics_toolkit::qt_graphics_toolkit (octave::interpreter& interp) + : QObject (), base_graphics_toolkit ("qt"), m_interpreter (interp) { // Implemented with a signal/slot connection in order to properly // cross from the interpreter thread (where requests to create @@ -411,47 +407,47 @@ Object *obj = nullptr; if (go.isa ("figure")) - obj = Figure::create (m_octave_qobj, m_interpreter, go); + obj = Figure::create (m_interpreter, go); else if (go.isa ("uicontrol")) { uicontrol::properties& up = Utils::properties (go); if (up.style_is ("pushbutton")) - obj = PushButtonControl::create (m_octave_qobj, m_interpreter, go); + obj = PushButtonControl::create (m_interpreter, go); else if (up.style_is ("edit")) - obj = EditControl::create (m_octave_qobj, m_interpreter, go); + obj = EditControl::create (m_interpreter, go); else if (up.style_is ("checkbox")) - obj = CheckBoxControl::create (m_octave_qobj, m_interpreter, go); + obj = CheckBoxControl::create (m_interpreter, go); else if (up.style_is ("radiobutton")) - obj = RadioButtonControl::create (m_octave_qobj, m_interpreter, go); + obj = RadioButtonControl::create (m_interpreter, go); else if (up.style_is ("togglebutton")) - obj = ToggleButtonControl::create (m_octave_qobj, m_interpreter, go); + obj = ToggleButtonControl::create (m_interpreter, go); else if (up.style_is ("text")) - obj = TextControl::create (m_octave_qobj, m_interpreter, go); + obj = TextControl::create (m_interpreter, go); else if (up.style_is ("popupmenu")) - obj = PopupMenuControl::create (m_octave_qobj, m_interpreter, go); + obj = PopupMenuControl::create (m_interpreter, go); else if (up.style_is ("slider")) - obj = SliderControl::create (m_octave_qobj, m_interpreter, go); + obj = SliderControl::create (m_interpreter, go); else if (up.style_is ("listbox")) - obj = ListBoxControl::create (m_octave_qobj, m_interpreter, go); + obj = ListBoxControl::create (m_interpreter, go); } else if (go.isa ("uibuttongroup")) - obj = ButtonGroup::create (m_octave_qobj, m_interpreter, go); + obj = ButtonGroup::create (m_interpreter, go); else if (go.isa ("uipanel")) - obj = Panel::create (m_octave_qobj, m_interpreter, go); + obj = Panel::create (m_interpreter, go); else if (go.isa ("uimenu")) - obj = Menu::create (m_octave_qobj, m_interpreter, go); + obj = Menu::create (m_interpreter, go); else if (go.isa ("uicontextmenu")) - obj = ContextMenu::create (m_octave_qobj, m_interpreter, go); + obj = ContextMenu::create (m_interpreter, go); else if (go.isa ("uitable")) - obj = Table::create (m_octave_qobj, m_interpreter, go); + obj = Table::create (m_interpreter, go); else if (go.isa ("uitoolbar")) - obj = ToolBar::create (m_octave_qobj, m_interpreter, go); + obj = ToolBar::create (m_interpreter, go); else if (go.isa ("uipushtool")) - obj = PushTool::create (m_octave_qobj, m_interpreter, go); + obj = PushTool::create (m_interpreter, go); else if (go.isa ("uitoggletool")) - obj = ToggleTool::create (m_octave_qobj, m_interpreter, go); + obj = ToggleTool::create (m_interpreter, go); else qWarning ("qt_graphics_toolkit::create_object: unsupported type '%s'", go.type ().c_str ()); diff -r e2911d0176dc -r 212145b8e5f0 libgui/graphics/qt-graphics-toolkit.h --- a/libgui/graphics/qt-graphics-toolkit.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/graphics/qt-graphics-toolkit.h Fri May 12 08:03:14 2023 +0200 @@ -34,7 +34,6 @@ OCTAVE_BEGIN_NAMESPACE(octave) class interpreter; -class base_qobject; class Object; class ObjectProxy; @@ -46,10 +45,9 @@ public: - qt_graphics_toolkit (octave::interpreter& interp, - octave::base_qobject& oct_qobj); + qt_graphics_toolkit (octave::interpreter& interp); - ~qt_graphics_toolkit (void) = default; + ~qt_graphics_toolkit () = default; // The interpreter may call graphics toolkit functions that we // implement here. The Qt GUI that manages these actions runs in a @@ -66,7 +64,7 @@ // we should ensure that they are correctly handling the connection // between the interpreter and GUI threads. - bool is_valid (void) const { return true; } + bool is_valid () const { return true; } void redraw_figure (const graphics_object& h) const; @@ -119,8 +117,6 @@ private: octave::interpreter& m_interpreter; - - octave::base_qobject& m_octave_qobj; }; OCTAVE_END_NAMESPACE(octave) diff -r e2911d0176dc -r 212145b8e5f0 libgui/languages/build_ts/octave-qt/qcolordialog.cpp --- a/libgui/languages/build_ts/octave-qt/qcolordialog.cpp Fri May 12 08:00:41 2023 +0200 +++ b/libgui/languages/build_ts/octave-qt/qcolordialog.cpp Fri May 12 08:03:14 2023 +0200 @@ -406,17 +406,6 @@ if(curRow < numRows()-1) setCurrent(curRow + 1, curCol); break; -#if 0 - // bad idea that shouldn't have been implemented; very counterintuitive - case Qt::Key_Return: - case Qt::Key_Enter: - /* - ignore the key, so that the dialog get it, but still select - the current row/col - */ - e->ignore(); - // fallthrough intended -#endif case Qt::Key_Space: setSelected(curRow, curCol); break; diff -r e2911d0176dc -r 212145b8e5f0 libgui/languages/build_ts/octave-qt/qdialog.cpp --- a/libgui/languages/build_ts/octave-qt/qdialog.cpp Fri May 12 08:00:41 2023 +0200 +++ b/libgui/languages/build_ts/octave-qt/qdialog.cpp Fri May 12 08:03:14 2023 +0200 @@ -559,7 +559,7 @@ QEventLoop eventLoop; d->eventLoop = &eventLoop; QPointer guard = this; - (void) eventLoop.exec(QEventLoop::DialogExec); + () eventLoop.exec(QEventLoop::DialogExec); if (guard.isNull()) return QDialog::Rejected; d->eventLoop = 0; diff -r e2911d0176dc -r 212145b8e5f0 libgui/languages/build_ts/octave-qt/qfileinfogatherer.cpp --- a/libgui/languages/build_ts/octave-qt/qfileinfogatherer.cpp Fri May 12 08:00:41 2023 +0200 +++ b/libgui/languages/build_ts/octave-qt/qfileinfogatherer.cpp Fri May 12 08:03:14 2023 +0200 @@ -234,18 +234,6 @@ info.displayType = m_iconProvider->type(fileInfo); #ifndef QT_NO_FILESYSTEMWATCHER // ### Not ready to listen all modifications - #if 0 - // Enable the next two commented out lines to get updates when the file sizes change... - if (!fileInfo.exists() && !fileInfo.isSymLink()) { - info.size = -1; - //watcher->removePath(fileInfo.absoluteFilePath()); - } else { - if (!fileInfo.absoluteFilePath().isEmpty() && fileInfo.exists() && fileInfo.isReadable() - && !watcher->files().contains(fileInfo.absoluteFilePath())) { - //watcher->addPath(fileInfo.absoluteFilePath()); - } - } - #endif #endif if (m_resolveSymlinks && info.isSymLink(/* ignoreNtfsSymLinks = */ true)) { diff -r e2911d0176dc -r 212145b8e5f0 libgui/languages/build_ts/octave-qt/qfontdialog.cpp --- a/libgui/languages/build_ts/octave-qt/qfontdialog.cpp Fri May 12 08:00:41 2023 +0200 +++ b/libgui/languages/build_ts/octave-qt/qfontdialog.cpp Fri May 12 08:03:14 2023 +0200 @@ -463,7 +463,7 @@ k->key() == Qt::Key_PageDown)) { int ci = d->sizeList->currentItem(); - (void)QApplication::sendEvent(d->sizeList, k); + ()QApplication::sendEvent(d->sizeList, k); if (ci != d->sizeList->currentItem() && style()->styleHint(QStyle::SH_FontDialog_SelectAssociatedText, 0, this)) diff -r e2911d0176dc -r 212145b8e5f0 libgui/languages/build_ts/octave-qt/qmessagebox.cpp --- a/libgui/languages/build_ts/octave-qt/qmessagebox.cpp Fri May 12 08:00:41 2023 +0200 +++ b/libgui/languages/build_ts/octave-qt/qmessagebox.cpp Fri May 12 08:03:14 2023 +0200 @@ -1717,12 +1717,7 @@ // should perhaps be a style hint #ifdef Q_WS_MAC oldMsgBox = msgBox; -#if 0 - // ### doesn't work until close button is enabled in title bar - msgBox->d_func()->autoAddOkButton = false; -#else msgBox->d_func()->buttonBox->setCenterButtons(true); -#endif msgBox->show(); #else msgBox->exec(); @@ -1807,12 +1802,7 @@ // should perhaps be a style hint #ifdef Q_WS_MAC oldMsgBox = msgBox; -#if 0 - // ### doesn't work until close button is enabled in title bar - msgBox->d_func()->autoAddOkButton = false; -#else msgBox->d_func()->buttonBox->setCenterButtons(true); -#endif msgBox->show(); #else msgBox->exec(); diff -r e2911d0176dc -r 212145b8e5f0 libgui/languages/build_ts/octave-qt/qprintdialog_win.cpp --- a/libgui/languages/build_ts/octave-qt/qprintdialog_win.cpp Fri May 12 08:00:41 2023 +0200 +++ b/libgui/languages/build_ts/octave-qt/qprintdialog_win.cpp Fri May 12 08:03:14 2023 +0200 @@ -307,7 +307,7 @@ if (!warnIfNotNative(d->printer)) return; - (void)d->openWindowsPrintDialogModally(); + ()d->openWindowsPrintDialogModally(); return; } diff -r e2911d0176dc -r 212145b8e5f0 libgui/liboctgui-build-info.h --- a/libgui/liboctgui-build-info.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/liboctgui-build-info.h Fri May 12 08:03:14 2023 +0200 @@ -30,6 +30,6 @@ #include -extern OCTGUI_API std::string liboctgui_hg_id (void); +extern OCTGUI_API std::string liboctgui_hg_id (); #endif diff -r e2911d0176dc -r 212145b8e5f0 libgui/liboctgui-build-info.in.cc --- a/libgui/liboctgui-build-info.in.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/liboctgui-build-info.in.cc Fri May 12 08:03:14 2023 +0200 @@ -32,7 +32,7 @@ #include "liboctgui-build-info.h" std::string -liboctgui_hg_id (void) +liboctgui_hg_id () { return "%OCTAVE_HG_ID%"; } diff -r e2911d0176dc -r 212145b8e5f0 libgui/qterminal/libqterminal/QTerminal.cc --- a/libgui/qterminal/libqterminal/QTerminal.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/qterminal/libqterminal/QTerminal.cc Fri May 12 08:03:14 2023 +0200 @@ -25,21 +25,24 @@ # include "config.h" #endif +#include +#include +#include +#include #include -#include -#include -#include #include #include -#include -#include -#include +#include +#include +#include #include "gui-preferences-global.h" #include "gui-preferences-cs.h" #include "gui-preferences-sc.h" -#include "octave-qobject.h" -#include "resource-manager.h" +#include "gui-settings.h" + +#include "builtin-defun-decls.h" +#include "interpreter.h" #include "QTerminal.h" #if defined (Q_OS_WIN32) @@ -49,21 +52,18 @@ #endif QTerminal * -QTerminal::create (octave::base_qobject& oct_qobj, QWidget *p) +QTerminal::create (QWidget *p) { #if defined (Q_OS_WIN32) - QTerminal *terminal = new QWinTerminalImpl (oct_qobj, p); + QTerminal *terminal = new QWinTerminalImpl (p); #else - QTerminal *terminal = new QUnixTerminalImpl (oct_qobj, p); + QTerminal *terminal = new QUnixTerminalImpl (p); #endif // FIXME: this function should probably be called from or part of the - // QTerminal constructor, but I think that would mean some major - // surgery because then the constructor for QTerminal and the derived - // Unix- and Windows-specific versions would need access to the - // base_qobject object, or the design would have to change significantly. + // QTerminal constructor? - terminal->construct (oct_qobj); + terminal->construct (); return terminal; } @@ -86,14 +86,13 @@ // detecting links and error messages yet if (has_selected_text) { - QRegExp file ("(?:[ \\t]+)(\\S+) at line (\\d+) column (?:\\d+)"); - - int pos = file.indexIn (selected_text); + QRegularExpression file {"(?:[ \\t]+)(\\S+) at line (\\d+) column (?:\\d+)"}; + QRegularExpressionMatch match = file.match (selected_text); - if (pos > -1) + if (match.hasMatch ()) { - QString file_name = file.cap (1); - QString line = file.cap (2); + QString file_name = match.captured (1); + QString line = match.captured (2); _edit_action->setVisible (true); _edit_action->setText (tr ("Edit %1 at line %2") @@ -108,13 +107,12 @@ if (has_selected_text) { - QRegExp expr (".*\b*(\\w+)\b*.*"); - - int pos = expr.indexIn (selected_text); + QRegularExpression expr {".*\b*(\\w+)\b*.*"}; + QRegularExpressionMatch match = expr.match (selected_text); - if (pos > -1) + if (match.hasMatch ()) { - QString expr_found = expr.cap (1); + QString expr_found = match.captured (1); m_edit_selected_action->setVisible (true); m_edit_selected_action->setText (tr ("Edit %1").arg (expr_found)); @@ -154,7 +152,7 @@ void QTerminal::run_selection () { - QStringList commands = selectedText ().split (QRegExp ("[\r\n]"), + QStringList commands = selectedText ().split (QRegularExpression {"[\r\n]"}, #if defined (HAVE_QT_SPLITBEHAVIOR_ENUM) Qt::SkipEmptyParts); #else @@ -194,37 +192,43 @@ // slot for showing documentation on selected epxression void QTerminal::doc_on_expression () { - QString expr = m_doc_selected_action->data ().toString (); - m_octave_qobj.show_documentation_window (expr); + std::string expr = m_doc_selected_action->data ().toString ().toStdString (); + + emit interpreter_event + ([=] (octave::interpreter& interp) + { + // INTERPRETER THREAD + + octave::F__event_manager_show_documentation__ (interp, ovl (expr)); + }); } void -QTerminal::notice_settings (const gui_settings *settings) +QTerminal::notice_settings (void) { - if (! settings) - return; + octave::gui_settings settings; // Set terminal font: QFont term_font = QFont (); term_font.setStyleHint (QFont::TypeWriter); - QString default_font = settings->value (global_mono_font).toString (); + QString default_font = settings.string_value (global_mono_font); term_font.setFamily - (settings->value (cs_font.key, default_font).toString ()); + (settings.value (cs_font.settings_key (), default_font).toString ()); term_font.setPointSize - (settings->value (cs_font_size).toInt ()); + (settings.int_value (cs_font_size)); setTerminalFont (term_font); QFontMetrics metrics (term_font); setMinimumSize (metrics.maxWidth ()*16, metrics.height ()*3); QString cursor_type - = settings->value (cs_cursor).toString (); + = settings.string_value (cs_cursor); bool cursor_blinking; - if (settings->contains (global_cursor_blinking.key)) - cursor_blinking = settings->value (global_cursor_blinking).toBool (); + if (settings.contains (global_cursor_blinking.settings_key ())) + cursor_blinking = settings.bool_value (global_cursor_blinking); else - cursor_blinking = settings->value (cs_cursor_blinking).toBool (); + cursor_blinking = settings.bool_value (cs_cursor_blinking); for (int ct = IBeamCursor; ct <= UnderlineCursor; ct++) { @@ -236,47 +240,47 @@ } bool cursorUseForegroundColor - = settings->value (cs_cursor_use_fgcol).toBool (); + = settings.bool_value (cs_cursor_use_fgcol); - int mode = settings->value (cs_color_mode).toInt (); + int mode = settings.int_value (cs_color_mode); - setForegroundColor (settings->color_value (cs_colors[0], mode)); + setForegroundColor (settings.color_value (cs_colors[0], mode)); - setBackgroundColor (settings->color_value (cs_colors[1], mode)); + setBackgroundColor (settings.color_value (cs_colors[1], mode)); - setSelectionColor (settings->color_value (cs_colors[2], mode)); + setSelectionColor (settings.color_value (cs_colors[2], mode)); setCursorColor (cursorUseForegroundColor, - settings->color_value (cs_colors[3], mode)); + settings.color_value (cs_colors[3], mode)); - setScrollBufferSize (settings->value (cs_hist_buffer).toInt ()); + setScrollBufferSize (settings.int_value (cs_hist_buffer)); // If the Copy shortcut is Ctrl+C, then the Copy action also emits // a signal for interrupting the current code executed by the worker. // If the Copy shortcut is not Ctrl+C, an extra interrupt action is // set up for emitting the interrupt signal. - QString sc = settings->sc_value (sc_main_edit_copy); + QString sc = settings.sc_value (sc_main_edit_copy); // Dis- or enable extra interrupt action: We need an extra option when // copy shortcut is not Ctrl-C or when global shortcuts (like copy) are // disabled. bool extra_ir_action = (sc != QKeySequence (Qt::ControlModifier | Qt::Key_C).toString ()) - || settings->value (sc_prevent_rl_conflicts).toBool (); + || settings.bool_value (sc_prevent_rl_conflicts); _interrupt_action->setEnabled (extra_ir_action); has_extra_interrupt (extra_ir_action); // check whether shortcut Ctrl-D is in use by the main-window - bool ctrld = settings->value (sc_main_ctrld).toBool (); + bool ctrld = settings.bool_value (sc_main_ctrld); _nop_action->setEnabled (! ctrld); } void -QTerminal::construct (octave::base_qobject& oct_qobj) +QTerminal::construct (void) { - octave::resource_manager& rmgr = oct_qobj.get_resource_manager (); + octave::gui_settings settings; // context menu setContextMenuPolicy (Qt::CustomContextMenu); @@ -284,11 +288,11 @@ _contextMenu = new QMenu (this); _copy_action - = _contextMenu->addAction (rmgr.icon ("edit-copy"), tr ("Copy"), this, + = _contextMenu->addAction (settings.icon ("edit-copy"), tr ("Copy"), this, SLOT (copyClipboard ())); _paste_action - = _contextMenu->addAction (rmgr.icon ("edit-paste"), tr ("Paste"), this, + = _contextMenu->addAction (settings.icon ("edit-paste"), tr ("Paste"), this, SLOT (pasteClipboard ())); _contextMenu->addSeparator (); @@ -325,7 +329,7 @@ addAction (_interrupt_action); _interrupt_action->setShortcut - (QKeySequence (Qt::ControlModifier + Qt::Key_C)); + (QKeySequence (Qt::ControlModifier | Qt::Key_C)); _interrupt_action->setShortcutContext (Qt::WidgetWithChildrenShortcut); bool ok = connect (_interrupt_action, SIGNAL (triggered ()), @@ -335,6 +339,6 @@ _nop_action = new QAction (this); addAction (_nop_action); - _nop_action->setShortcut (QKeySequence (Qt::ControlModifier + Qt::Key_D)); + _nop_action->setShortcut (QKeySequence (Qt::ControlModifier | Qt::Key_D)); _nop_action->setShortcutContext (Qt::WidgetWithChildrenShortcut); } diff -r e2911d0176dc -r 212145b8e5f0 libgui/qterminal/libqterminal/QTerminal.h --- a/libgui/qterminal/libqterminal/QTerminal.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/qterminal/libqterminal/QTerminal.h Fri May 12 08:03:14 2023 +0200 @@ -24,23 +24,15 @@ #ifndef QTERMINAL_H #define QTERMINAL_H +#include "octave-config.h" + #include #include #include #include #include -// For now, we need to use the following #include and using statement -// for the signal/slot macros. Could maybe change later when using -// Qt5-style signal/slot connections. -#include "gui-settings.h" - -using octave::gui_settings; - -namespace octave -{ - class base_qobject; -} +#include "qt-interpreter-events.h" class QMenu; class QAction; @@ -51,8 +43,7 @@ public: - static QTerminal * - create (octave::base_qobject& oct_qobj, QWidget *xparent); + static QTerminal * create (QWidget *xparent); virtual ~QTerminal (void) = default; @@ -116,6 +107,9 @@ void clear_command_window_request (void); + void interpreter_event (const octave::fcn_callback& fcn); + void interpreter_event (const octave::meth_callback& meth); + public slots: virtual void copyClipboard (void) = 0; @@ -126,7 +120,7 @@ virtual void handleCustomContextMenuRequested (const QPoint& at); - void notice_settings (const gui_settings *settings); + void notice_settings (void); virtual void init_terminal_size (void) { } @@ -146,15 +140,14 @@ protected: - QTerminal (octave::base_qobject& oct_qobj, QWidget *xparent = nullptr) - : QWidget (xparent), m_octave_qobj (oct_qobj) { } + QTerminal (QWidget *xparent = nullptr) + : QWidget (xparent) + { } - void construct (octave::base_qobject& oct_qobj); + void construct (); private: - octave::base_qobject& m_octave_qobj; - QMenu *_contextMenu; QAction * _copy_action; QAction * _paste_action; diff -r e2911d0176dc -r 212145b8e5f0 libgui/qterminal/libqterminal/unix/Character.h --- a/libgui/qterminal/libqterminal/unix/Character.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/qterminal/libqterminal/unix/Character.h Fri May 12 08:03:14 2023 +0200 @@ -26,7 +26,7 @@ #define CHARACTER_H // Qt -#include +#include // Local #include "unix/CharacterColor.h" diff -r e2911d0176dc -r 212145b8e5f0 libgui/qterminal/libqterminal/unix/Emulation.cpp --- a/libgui/qterminal/libqterminal/unix/Emulation.cpp Fri May 12 08:00:41 2023 +0200 +++ b/libgui/qterminal/libqterminal/unix/Emulation.cpp Fri May 12 08:03:14 2023 +0200 @@ -35,13 +35,11 @@ // Qt #include #include -#include +#include #include -#include -#include -#include - -#include +#include +#include +#include // Konsole #include "unix/KeyboardTranslator.h" diff -r e2911d0176dc -r 212145b8e5f0 libgui/qterminal/libqterminal/unix/Emulation.h --- a/libgui/qterminal/libqterminal/unix/Emulation.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/qterminal/libqterminal/unix/Emulation.h Fri May 12 08:03:14 2023 +0200 @@ -30,10 +30,9 @@ // Qt #include - -#include -#include -#include +#include +#include +#include class KeyboardTranslator; class HistoryType; diff -r e2911d0176dc -r 212145b8e5f0 libgui/qterminal/libqterminal/unix/Filter.cpp --- a/libgui/qterminal/libqterminal/unix/Filter.cpp Fri May 12 08:00:41 2023 +0200 +++ b/libgui/qterminal/libqterminal/unix/Filter.cpp Fri May 12 08:03:14 2023 +0200 @@ -24,14 +24,14 @@ #include "unix/Filter.h" // Qt -#include +#include + #include #include #include -#include - -#include -#include +#include +#include +#include // Konsole #include "unix/TerminalCharacterDecoder.h" @@ -349,11 +349,11 @@ return _capturedTexts; } -void RegExpFilter::setRegExp(const QRegExp& regExp) +void RegExpFilter::setRegExp (const QRegularExpression& regExp) { _searchText = regExp; } -QRegExp RegExpFilter::regExp() const +QRegularExpression RegExpFilter::regExp () const { return _searchText; } @@ -361,7 +361,7 @@ { _buffer = QString(); }*/ -void RegExpFilter::process() +void RegExpFilter::process () { int pos = 0; const QString* text = buffer(); @@ -371,37 +371,35 @@ // ignore any regular expressions which match an empty string. // otherwise the while loop below will run indefinitely static const QString emptyString(""); - if ( _searchText.exactMatch(emptyString) ) + QRegularExpressionMatch match = _searchText.match (emptyString); + if ( match.hasMatch () ) return; - while(pos >= 0) + match = _searchText.match (*text, pos); + while (match.hasMatch ()) { - pos = _searchText.indexIn(*text,pos); + pos = match.capturedStart (); + int startLine = 0; + int endLine = 0; + int startColumn = 0; + int endColumn = 0; - if ( pos >= 0 ) - { - - int startLine = 0; - int endLine = 0; - int startColumn = 0; - int endColumn = 0; - + //kDebug() << "pos from " << pos << " to " << pos + _searchText.matchedLength(); - //kDebug() << "pos from " << pos << " to " << pos + _searchText.matchedLength(); + getLineColumn (match.capturedStart (), startLine, startColumn); + getLineColumn (match.capturedEnd (), endLine, endColumn); - getLineColumn(pos,startLine,startColumn); - getLineColumn(pos + _searchText.matchedLength(),endLine,endColumn); + RegExpFilter::HotSpot* spot = newHotSpot(startLine,startColumn, + endLine,endColumn,_type); + spot->setCapturedTexts (match.capturedTexts ()); - RegExpFilter::HotSpot* spot = newHotSpot(startLine,startColumn, - endLine,endColumn,_type); - spot->setCapturedTexts(_searchText.capturedTexts()); + addHotSpot( spot ); + pos += match.capturedLength (); - addHotSpot( spot ); - pos += _searchText.matchedLength(); + // if matchedLength == 0, the program will get stuck in an infinite loop + Q_ASSERT( match.capturedLength () > 0 ); - // if matchedLength == 0, the program will get stuck in an infinite loop - Q_ASSERT( _searchText.matchedLength() > 0 ); - } + match = _searchText.match (*text, pos); } } @@ -419,7 +417,7 @@ endLine,endColumn,t); } -void UrlFilter::process() +void UrlFilter::process () { int pos = 0; const QString* text = buffer(); @@ -429,43 +427,40 @@ // ignore any regular expressions which match an empty string. // otherwise the while loop below will run indefinitely static const QString emptyString(""); - if ( _searchText.exactMatch(emptyString) ) + QRegularExpressionMatch match = _searchText.match (emptyString); + if ( match.hasMatch () ) return; - while(pos >= 0) + match = _searchText.match (*text, pos); + while (match.hasMatch ()) { - pos = _searchText.indexIn(*text,pos); - - if ( pos >= 0 ) - { + int startLine = 0; + int endLine = 0; + int startColumn = 0; + int endColumn = 0; - int startLine = 0; - int endLine = 0; - int startColumn = 0; - int endColumn = 0; + //kDebug() << "pos from " << pos << " to " << pos + _searchText.matchedLength(); - - //kDebug() << "pos from " << pos << " to " << pos + _searchText.matchedLength(); + getLineColumn (match.capturedStart (), startLine, startColumn); + getLineColumn (match.capturedEnd (), endLine, endColumn); - getLineColumn(pos,startLine,startColumn); - getLineColumn(pos + _searchText.matchedLength(),endLine,endColumn); - - UrlFilter::HotSpot* spot = newHotSpot(startLine,startColumn, - endLine,endColumn,_type); - spot->setCapturedTexts(_searchText.capturedTexts()); + UrlFilter::HotSpot* spot = newHotSpot(startLine,startColumn, + endLine,endColumn,_type); + spot->setCapturedTexts(match.capturedTexts ()); - // Connect the signal of the urlobject to the slot of the filter; - // the filter is then signaling to the main window - connect (spot->get_urlObject (), - SIGNAL (request_open_file_signal (const QString&, int)), - this, SLOT (request_open_file (const QString&, int))); + // Connect the signal of the urlobject to the slot of the filter; + // the filter is then signaling to the main window + connect (spot->get_urlObject (), + SIGNAL (request_open_file_signal (const QString&, int)), + this, SLOT (request_open_file (const QString&, int))); - addHotSpot( spot ); - pos += _searchText.matchedLength(); + addHotSpot( spot ); + pos += match.capturedLength(); - // if matchedLength == 0, the program will get stuck in an infinite loop - Q_ASSERT( _searchText.matchedLength() > 0 ); - } + // if matchedLength == 0, the program will get stuck in an infinite loop + Q_ASSERT( match.capturedLength () > 0 ); + + match = _searchText.match (*text, pos); } } @@ -489,23 +484,27 @@ else return QString(); } -UrlFilter::HotSpot::UrlType UrlFilter::HotSpot::urlType() const +UrlFilter::HotSpot::UrlType UrlFilter::HotSpot::urlType () const { QString url = capturedTexts().first(); - if ( FullUrlRegExp.exactMatch(url) ) + QRegularExpressionMatch match = FullUrlRegExp.match (url); + if ( match.hasMatch () ) return StandardUrl; - else if ( EmailAddressRegExp.exactMatch(url) ) + match = EmailAddressRegExp.match (url); + if ( match.hasMatch () ) return Email; - else if ( ErrorLinkRegExp.exactMatch(url) ) + match = ErrorLinkRegExp.match (url); + if ( match.hasMatch () ) return ErrorLink; - else if ( ParseErrorLinkRegExp.exactMatch(url) ) + match = ParseErrorLinkRegExp.match (url); + if ( match.hasMatch () ) return ParseErrorLink; - else - return Unknown; + + return Unknown; } -void UrlFilter::HotSpot::activate(QObject* object) +void UrlFilter::HotSpot::activate (QObject* object) { QString url = capturedTexts().first(); @@ -538,11 +537,11 @@ } else if (kind == ErrorLink) { - int pos = ErrorLinkRegExp.indexIn (url); - if (pos > -1) + QRegularExpressionMatch match = ErrorLinkRegExp.match (url); + if (match.hasMatch ()) { - QString file_name = ErrorLinkRegExp.cap (1); - QString line = ErrorLinkRegExp.cap (2); + QString file_name = match.captured (1); + QString line = match.captured (2); // call the urlobject's method for opening a file; this // method then signals to the filter _urlObject->request_open_file (file_name, line.toInt ()); @@ -550,11 +549,11 @@ } else if (kind == ParseErrorLink) { - int pos = ParseErrorLinkRegExp.indexIn (url); - if (pos > -1) + QRegularExpressionMatch match = ParseErrorLinkRegExp.match (url); + if (match.hasMatch ()) { - QString line = ParseErrorLinkRegExp.cap (1); - QString file_name = ParseErrorLinkRegExp.cap (2); + QString line = match.captured (1); + QString file_name = match.captured (2); // call the urlobject's method for opening a file; this // method then signals to the filter _urlObject->request_open_file (file_name, line.toInt ()); @@ -574,21 +573,27 @@ //regexp matches: // full url: // protocolname:// or www. followed by anything other than whitespaces, <, >, ' or ", and ends before whitespaces, <, >, ', ", ], !, comma and dot -const QRegExp UrlFilter::FullUrlRegExp("(www\\.(?!\\.)|[a-z][a-z0-9+.-]*://)[^\\s<>'\"]+[^!,\\.\\s<>'\"\\]]"); +const QRegularExpression +UrlFilter::FullUrlRegExp {"(www\\.(?!\\.)|[a-z][a-z0-9+.-]*://)[^\\s<>'\"]+[^!,\\.\\s<>'\"\\]]"}; // email address: // [word chars, dots or dashes]@[word chars, dots or dashes].[word chars] -const QRegExp UrlFilter::EmailAddressRegExp("\\b(\\w|\\.|-)+@(\\w|\\.|-)+\\.\\w+\\b"); +const QRegularExpression +UrlFilter::EmailAddressRegExp {"\\b(\\w|\\.|-)+@(\\w|\\.|-)+\\.\\w+\\b"}; // matches full url or email address -const QRegExp UrlFilter::CompleteUrlRegExp('('+FullUrlRegExp.pattern()+'|'+ - EmailAddressRegExp.pattern()+')'); +const QRegularExpression +UrlFilter::CompleteUrlRegExp {'(' + FullUrlRegExp.pattern() + '|' + + EmailAddressRegExp.pattern() + ')'}; // error link: // normal error -const QRegExp UrlFilter::ErrorLinkRegExp ("(\\S+) at line (\\d+) column (?:\\d+)"); +const QRegularExpression +UrlFilter::ErrorLinkRegExp {"(\\S+) at line (\\d+) column (?:\\d+)"}; // parse error -const QRegExp UrlFilter::ParseErrorLinkRegExp ("parse error near line (\\d+) of file (\\S+)"); +const QRegularExpression +UrlFilter::ParseErrorLinkRegExp {"parse error near line (\\d+) of file (\\S+)"}; // complete regexp -const QRegExp UrlFilter::CompleteErrorLinkRegExp ('('+ErrorLinkRegExp.pattern ()+'|'+ - ParseErrorLinkRegExp.pattern ()+')'); +const QRegularExpression +UrlFilter::CompleteErrorLinkRegExp {'('+ErrorLinkRegExp.pattern ()+'|'+ + ParseErrorLinkRegExp.pattern ()+')'}; UrlFilter::UrlFilter (Type t) @@ -607,7 +612,7 @@ { _filter->activate(sender()); } -QList UrlFilter::HotSpot::actions() +QList UrlFilter::HotSpot::actions () { QList list; @@ -633,11 +638,11 @@ else if ( kind == ErrorLink ) { QString url = capturedTexts().first(); - int pos = ErrorLinkRegExp.indexIn (url); - if (pos >= 0) + QRegularExpressionMatch match = ErrorLinkRegExp.match (url); + if (match.hasMatch ()) { - QString file_name = ErrorLinkRegExp.cap (1); - QString line = ErrorLinkRegExp.cap (2); + QString file_name = match.captured (1); + QString line = match.captured (2); openAction->setText(tr ("Edit %1 at line %2") .arg (file_name).arg (line)); } @@ -645,11 +650,11 @@ else if ( kind == ParseErrorLink ) { QString url = capturedTexts().first(); - int pos = ParseErrorLinkRegExp.indexIn (url); - if (pos >= 0) + QRegularExpressionMatch match = ParseErrorLinkRegExp.match (url); + if (match.hasMatch ()) { - QString line = ParseErrorLinkRegExp.cap (1); - QString file_name = ParseErrorLinkRegExp.cap (2); + QString line = match.captured (1); + QString file_name = match.captured (2); openAction->setText(tr ("Edit %1 at line %2") .arg (file_name).arg (line)); } diff -r e2911d0176dc -r 212145b8e5f0 libgui/qterminal/libqterminal/unix/Filter.h --- a/libgui/qterminal/libqterminal/unix/Filter.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/qterminal/libqterminal/unix/Filter.h Fri May 12 08:03:14 2023 +0200 @@ -25,11 +25,11 @@ // Qt #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include // Local #include "unix/Character.h" @@ -230,9 +230,9 @@ * Regular expressions which match the empty string are treated as not matching * anything. */ - void setRegExp(const QRegExp& text); + void setRegExp(const QRegularExpression& text); /** Returns the regular expression which the filter searches for in blocks of text */ - QRegExp regExp() const; + QRegularExpression regExp() const; /** * Reimplemented to search the filter's text buffer for text matching regExp() @@ -256,7 +256,7 @@ int endLine,int endColumn, Type); Type _type; - QRegExp _searchText; + QRegularExpression _searchText; }; class FilterObject; @@ -316,14 +316,14 @@ private: - static const QRegExp FullUrlRegExp; - static const QRegExp EmailAddressRegExp; - static const QRegExp ErrorLinkRegExp; - static const QRegExp ParseErrorLinkRegExp; - static const QRegExp CompleteErrorLinkRegExp; + static const QRegularExpression FullUrlRegExp; + static const QRegularExpression EmailAddressRegExp; + static const QRegularExpression ErrorLinkRegExp; + static const QRegularExpression ParseErrorLinkRegExp; + static const QRegularExpression CompleteErrorLinkRegExp; // combined OR of FullUrlRegExp and EmailAddressRegExp - static const QRegExp CompleteUrlRegExp; + static const QRegularExpression CompleteUrlRegExp; }; class FilterObject : public QObject diff -r e2911d0176dc -r 212145b8e5f0 libgui/qterminal/libqterminal/unix/History.h --- a/libgui/qterminal/libqterminal/unix/History.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/qterminal/libqterminal/unix/History.h Fri May 12 08:03:14 2023 +0200 @@ -24,10 +24,11 @@ #define HISTORY_H // Qt -#include -#include #include +#include +#include + // Konsole #include "unix/BlockArray.h" #include "unix/Character.h" diff -r e2911d0176dc -r 212145b8e5f0 libgui/qterminal/libqterminal/unix/KeyboardTranslator.cpp --- a/libgui/qterminal/libqterminal/unix/KeyboardTranslator.cpp Fri May 12 08:00:41 2023 +0200 +++ b/libgui/qterminal/libqterminal/unix/KeyboardTranslator.cpp Fri May 12 08:03:14 2023 +0200 @@ -29,12 +29,14 @@ #include // Qt -#include -#include -#include #include #include +#include +#include +#include +#include + // FIXME: We should not have a special case for Mac here. Instead, we // should be loading .keytab files at run time, and ideally, allowing // individual keys to be redefined from some preferences menu. @@ -509,49 +511,52 @@ { return false; } -QList KeyboardTranslatorReader::tokenize(const QString& line) +QList +KeyboardTranslatorReader::tokenize (const QString& line) { QString text = line.simplified(); // comment line: # comment - static QRegExp comment("\\#.*"); + static QRegularExpression comment {"\\#.*"}; // title line: keyboard "title" - static QRegExp title("keyboard\\s+\"(.*)\""); + static QRegularExpression title {"keyboard\\s+\"(.*)\""}; // key line: key KeySequence : "output" // key line: key KeySequence : command - static QRegExp key("key\\s+([\\w\\+\\s\\-]+)\\s*:\\s*(\"(.*)\"|\\w+)"); + static QRegularExpression key {"key\\s+([\\w\\+\\s\\-]+)\\s*:\\s*(\"(.*)\"|\\w+)"}; QList list; - if ( text.isEmpty() || comment.exactMatch(text) ) + if ( text.isEmpty() || comment.match (text).hasMatch () ) { return list; } - if ( title.exactMatch(text) ) + QRegularExpressionMatch match; + if ((match = title.match (text)).hasMatch ()) { Token titleToken = { Token::TitleKeyword , QString() }; - Token textToken = { Token::TitleText , title.capturedTexts()[1] }; + Token textToken = { Token::TitleText , match.captured (1) }; list << titleToken << textToken; } - else if ( key.exactMatch(text) ) + else if ((match = key.match (text)).hasMatch ()) { Token keyToken = { Token::KeyKeyword , QString() }; - Token sequenceToken = { Token::KeySequence , key.capturedTexts()[1].remove(' ') }; + Token sequenceToken = { Token::KeySequence, + match.captured (1).remove (' ') }; list << keyToken << sequenceToken; - if ( key.capturedTexts()[3].isEmpty() ) + if ( match.captured (3).isEmpty () ) { // capturedTexts()[2] is a command - Token commandToken = { Token::Command , key.capturedTexts()[2] }; + Token commandToken = { Token::Command , match.captured (2) }; list << commandToken; } else { // capturedTexts()[3] is the output string - Token outputToken = { Token::OutputText , key.capturedTexts()[3] }; + Token outputToken = { Token::OutputText , match.captured (3) }; list << outputToken; } } @@ -671,7 +676,7 @@ for ( int i = 0 ; i < result.count()-1 ; i++ ) { - QByteRef ch = result[i]; + char ch = result[i]; if ( ch == '\\' ) { char replacement[2] = {0,0}; diff -r e2911d0176dc -r 212145b8e5f0 libgui/qterminal/libqterminal/unix/KeyboardTranslator.h --- a/libgui/qterminal/libqterminal/unix/KeyboardTranslator.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/qterminal/libqterminal/unix/KeyboardTranslator.h Fri May 12 08:03:14 2023 +0200 @@ -25,13 +25,14 @@ #define KEYBOARDTRANSLATOR_H // Qt -#include -#include -#include +#include + +#include #include -#include -#include -#include +#include +#include +#include +#include #if QT_VERSION >= 0x050100 # define K_GLOBAL_STATIC Q_GLOBAL_STATIC diff -r e2911d0176dc -r 212145b8e5f0 libgui/qterminal/libqterminal/unix/QUnixTerminalImpl.cpp --- a/libgui/qterminal/libqterminal/unix/QUnixTerminalImpl.cpp Fri May 12 08:00:41 2023 +0200 +++ b/libgui/qterminal/libqterminal/unix/QUnixTerminalImpl.cpp Fri May 12 08:03:14 2023 +0200 @@ -24,9 +24,8 @@ #include -QUnixTerminalImpl::QUnixTerminalImpl(octave::base_qobject& oct_qobj, - QWidget *p) - : QTerminal(oct_qobj, p) +QUnixTerminalImpl::QUnixTerminalImpl(QWidget *p) + : QTerminal(p) { initialize(); } diff -r e2911d0176dc -r 212145b8e5f0 libgui/qterminal/libqterminal/unix/QUnixTerminalImpl.h --- a/libgui/qterminal/libqterminal/unix/QUnixTerminalImpl.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/qterminal/libqterminal/unix/QUnixTerminalImpl.h Fri May 12 08:03:14 2023 +0200 @@ -36,7 +36,7 @@ int fdstderr; public: - QUnixTerminalImpl(octave::base_qobject&, QWidget *parent); + QUnixTerminalImpl(QWidget *parent); virtual ~QUnixTerminalImpl(); void setTerminalFont(const QFont &font); diff -r e2911d0176dc -r 212145b8e5f0 libgui/qterminal/libqterminal/unix/Screen.cpp --- a/libgui/qterminal/libqterminal/unix/Screen.cpp Fri May 12 08:00:41 2023 +0200 +++ b/libgui/qterminal/libqterminal/unix/Screen.cpp Fri May 12 08:03:14 2023 +0200 @@ -32,8 +32,8 @@ #include // Qt -#include -#include +#include +#include // Konsole #include "unix/konsole_wcwidth.h" diff -r e2911d0176dc -r 212145b8e5f0 libgui/qterminal/libqterminal/unix/Screen.h --- a/libgui/qterminal/libqterminal/unix/Screen.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/qterminal/libqterminal/unix/Screen.h Fri May 12 08:03:14 2023 +0200 @@ -26,9 +26,9 @@ #define SCREEN_H // Qt -#include -#include -#include +#include +#include +#include // Konsole #include "unix/Character.h" diff -r e2911d0176dc -r 212145b8e5f0 libgui/qterminal/libqterminal/unix/ScreenWindow.h --- a/libgui/qterminal/libqterminal/unix/ScreenWindow.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/qterminal/libqterminal/unix/ScreenWindow.h Fri May 12 08:03:14 2023 +0200 @@ -23,9 +23,9 @@ #define SCREENWINDOW_H // Qt -#include -#include -#include +#include +#include +#include // Konsole #include "unix/Character.h" diff -r e2911d0176dc -r 212145b8e5f0 libgui/qterminal/libqterminal/unix/TerminalCharacterDecoder.cpp --- a/libgui/qterminal/libqterminal/unix/TerminalCharacterDecoder.cpp Fri May 12 08:00:41 2023 +0200 +++ b/libgui/qterminal/libqterminal/unix/TerminalCharacterDecoder.cpp Fri May 12 08:03:14 2023 +0200 @@ -25,7 +25,7 @@ #include "unix/TerminalCharacterDecoder.h" // Qt -#include +#include PlainTextDecoder::PlainTextDecoder() : _output(nullptr) diff -r e2911d0176dc -r 212145b8e5f0 libgui/qterminal/libqterminal/unix/TerminalModel.cpp --- a/libgui/qterminal/libqterminal/unix/TerminalModel.cpp Fri May 12 08:00:41 2023 +0200 +++ b/libgui/qterminal/libqterminal/unix/TerminalModel.cpp Fri May 12 08:03:14 2023 +0200 @@ -31,13 +31,12 @@ #include // Qt +#include + #include -#include -#include -#include -#include -#include -#include +#include +#include +#include #include "unix/TerminalView.h" #include "unix/Vt102Emulation.h" diff -r e2911d0176dc -r 212145b8e5f0 libgui/qterminal/libqterminal/unix/TerminalModel.h --- a/libgui/qterminal/libqterminal/unix/TerminalModel.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/qterminal/libqterminal/unix/TerminalModel.h Fri May 12 08:03:14 2023 +0200 @@ -27,8 +27,10 @@ #define TERMINALMODEL_H // Qt -#include #include + +#include +#include #include #include "unix/SelfListener.h" diff -r e2911d0176dc -r 212145b8e5f0 libgui/qterminal/libqterminal/unix/TerminalView.cpp --- a/libgui/qterminal/libqterminal/unix/TerminalView.cpp Fri May 12 08:00:41 2023 +0200 +++ b/libgui/qterminal/libqterminal/unix/TerminalView.cpp Fri May 12 08:03:14 2023 +0200 @@ -33,23 +33,24 @@ #include "unix/TerminalView.h" // Qt +#include +#include + #include #include #include +#include +#include +#include #include -#include -#include -#include -#include #include #include #include #include #include #include +#include #include -#include -#include #include "unix/Filter.h" #include "unix/konsole_wcwidth.h" @@ -331,7 +332,7 @@ setAttribute(Qt::WA_OpaquePaintEvent); _gridLayout = new QGridLayout(this); - _gridLayout->setMargin(0); + _gridLayout->setContentsMargins (0, 0, 0, 0); setLayout( _gridLayout ); } @@ -570,26 +571,6 @@ void TerminalView::setRandomSeed(uint randomSeed) { _randomSeed = randomSeed; } uint TerminalView::randomSeed() const { return _randomSeed; } -#if 0 -/*! - Set XIM Position -*/ -void TerminalDisplay::setCursorPos(const int curx, const int cury) -{ - QPoint tL = contentsRect().topLeft(); - int tLx = tL.x(); - int tLy = tL.y(); - - int xpos, ypos; - ypos = _topMargin + tLy + _fontHeight*(cury-1) + _fontAscent; - xpos = _leftMargin + tLx + _fontWidth*curx; - //setMicroFocusHint(xpos, ypos, 0, _fontHeight); //### ??? - // fprintf(stderr, "x/y = %d/%d\txpos/ypos = %d/%d\n", curx, cury, xpos, ypos); - _cursorLine = cury; - _cursorCol = curx; -} -#endif - // scrolls the image by 'lines', down if lines > 0 or up otherwise. // // the terminal emulation keeps track of the scrolling of the character @@ -1647,13 +1628,6 @@ extendSelection( ev->pos() ); } -#if 0 -void TerminalDisplay::setSelectionEnd() -{ - extendSelection( _configureRequestPoint ); -} -#endif - void TerminalView::extendSelection(const QPoint& position) { QPoint pos = position; @@ -2043,13 +2017,8 @@ void TerminalView::wheelEvent( QWheelEvent* ev ) { -#if defined (HAVE_QWHEELEVENT_ANGLEDELTA) if (ev->angleDelta().y() == 0) return; -#else - if (ev->orientation() != Qt::Vertical) - return; -#endif if ( _mouseMarks ) _scrollBar->event(ev); @@ -2064,11 +2033,8 @@ #endif getCharacterPosition( pos , charLine , charColumn ); -#if defined (HAVE_QWHEELEVENT_ANGLEDELTA) int delta = ev->angleDelta().y(); -#else - int delta = ev->delta(); -#endif + emit mouseSignal( delta > 0 ? 4 : 5, charColumn + 1, charLine + 1 +_scrollBar->value() -_scrollBar->maximum() , diff -r e2911d0176dc -r 212145b8e5f0 libgui/qterminal/libqterminal/unix/TerminalView.h --- a/libgui/qterminal/libqterminal/unix/TerminalView.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/qterminal/libqterminal/unix/TerminalView.h Fri May 12 08:03:14 2023 +0200 @@ -26,7 +26,7 @@ // Qt #include -#include +#include #include // Konsole diff -r e2911d0176dc -r 212145b8e5f0 libgui/qterminal/libqterminal/unix/Vt102Emulation.cpp --- a/libgui/qterminal/libqterminal/unix/Vt102Emulation.cpp Fri May 12 08:00:41 2023 +0200 +++ b/libgui/qterminal/libqterminal/unix/Vt102Emulation.cpp Fri May 12 08:03:14 2023 +0200 @@ -39,9 +39,8 @@ #include // Qt -#include +#include #include -#include // Konsole #include "unix/KeyboardTranslator.h" @@ -359,7 +358,7 @@ arg = 10*arg + (pbuf[i]-'0'); if (pbuf[i] != ';') { ReportErrorToken(); return; } QChar *str = new QChar[ppos-i-2]; - for (int j = 0; j < ppos-i-2; j++) str[j] = pbuf[i+1+j]; + for (int j = 0; j < ppos-i-2; j++) str[j] = QChar {pbuf[i+1+j]}; QString unistr(str,ppos-i-2); // arg == 1 doesn't change the title. In XTerm it only changes the icon name @@ -402,38 +401,6 @@ void Vt102Emulation::tau( int token, int p, int q ) { -#if 0 -int N = (token>>0)&0xff; -int A = (token>>8)&0xff; -switch( N ) -{ - case 0: printf("%c", (p < 128) ? p : '?'); - break; - case 1: if (A == 'J') printf("\r"); - else if (A == 'M') printf("\n"); - else printf("CTL-%c ", (token>>8)&0xff); - break; - case 2: printf("ESC-%c ", (token>>8)&0xff); - break; - case 3: printf("ESC_CS-%c-%c ", (token>>8)&0xff, (token>>16)&0xff); - break; - case 4: printf("ESC_DE-%c ", (token>>8)&0xff); - break; - case 5: printf("CSI-PS-%c-%d", (token>>8)&0xff, (token>>16)&0xff ); - break; - case 6: printf("CSI-PN-%c [%d]", (token>>8)&0xff, p); - break; - case 7: printf("CSI-PR-%c-%d", (token>>8)&0xff, (token>>16)&0xff ); - break; - case 8: printf("VT52-%c", (token>>8)&0xff); - break; - case 9: printf("CSI-PG-%c", (token>>8)&0xff); - break; - case 10: printf("CSI-PE-%c", (token>>8)&0xff); - break; -} -#endif - switch (token) { diff -r e2911d0176dc -r 212145b8e5f0 libgui/qterminal/libqterminal/unix/Vt102Emulation.h --- a/libgui/qterminal/libqterminal/unix/Vt102Emulation.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/qterminal/libqterminal/unix/Vt102Emulation.h Fri May 12 08:03:14 2023 +0200 @@ -29,9 +29,9 @@ #include // Qt +#include #include -#include -#include +#include // Konsole #include "unix/Emulation.h" diff -r e2911d0176dc -r 212145b8e5f0 libgui/qterminal/libqterminal/unix/konsole_wcwidth.cpp --- a/libgui/qterminal/libqterminal/unix/konsole_wcwidth.cpp Fri May 12 08:00:41 2023 +0200 +++ b/libgui/qterminal/libqterminal/unix/konsole_wcwidth.cpp Fri May 12 08:03:14 2023 +0200 @@ -131,81 +131,6 @@ (ucs >= 0x20000 && ucs <= 0x2ffff) */)); } -#if 0 -/* - * The following function is the same as konsole_wcwidth(), except that - * spacing characters in the East Asian Ambiguous (A) category as - * defined in Unicode Technical Report #11 have a column width of 2. - * This experimental variant might be useful for users of CJK legacy - * encodings who want to migrate to UCS. It is not otherwise - * recommended for general use. - */ -int konsole_wcwidth_cjk(quint16 ucs) -{ - /* sorted list of non-overlapping intervals of East Asian Ambiguous - * characters */ - static const struct interval ambiguous[] = { - { 0x00A1, 0x00A1 }, { 0x00A4, 0x00A4 }, { 0x00A7, 0x00A8 }, - { 0x00AA, 0x00AA }, { 0x00AD, 0x00AD }, { 0x00B0, 0x00B4 }, - { 0x00B6, 0x00BA }, { 0x00BC, 0x00BF }, { 0x00C6, 0x00C6 }, - { 0x00D0, 0x00D0 }, { 0x00D7, 0x00D8 }, { 0x00DE, 0x00E1 }, - { 0x00E6, 0x00E6 }, { 0x00E8, 0x00EA }, { 0x00EC, 0x00ED }, - { 0x00F0, 0x00F0 }, { 0x00F2, 0x00F3 }, { 0x00F7, 0x00FA }, - { 0x00FC, 0x00FC }, { 0x00FE, 0x00FE }, { 0x0101, 0x0101 }, - { 0x0111, 0x0111 }, { 0x0113, 0x0113 }, { 0x011B, 0x011B }, - { 0x0126, 0x0127 }, { 0x012B, 0x012B }, { 0x0131, 0x0133 }, - { 0x0138, 0x0138 }, { 0x013F, 0x0142 }, { 0x0144, 0x0144 }, - { 0x0148, 0x014A }, { 0x014D, 0x014D }, { 0x0152, 0x0153 }, - { 0x0166, 0x0167 }, { 0x016B, 0x016B }, { 0x01CE, 0x01CE }, - { 0x01D0, 0x01D0 }, { 0x01D2, 0x01D2 }, { 0x01D4, 0x01D4 }, - { 0x01D6, 0x01D6 }, { 0x01D8, 0x01D8 }, { 0x01DA, 0x01DA }, - { 0x01DC, 0x01DC }, { 0x0251, 0x0251 }, { 0x0261, 0x0261 }, - { 0x02C7, 0x02C7 }, { 0x02C9, 0x02CB }, { 0x02CD, 0x02CD }, - { 0x02D0, 0x02D0 }, { 0x02D8, 0x02DB }, { 0x02DD, 0x02DD }, - { 0x0391, 0x03A1 }, { 0x03A3, 0x03A9 }, { 0x03B1, 0x03C1 }, - { 0x03C3, 0x03C9 }, { 0x0401, 0x0401 }, { 0x0410, 0x044F }, - { 0x0451, 0x0451 }, { 0x2010, 0x2010 }, { 0x2013, 0x2016 }, - { 0x2018, 0x2019 }, { 0x201C, 0x201D }, { 0x2020, 0x2021 }, - { 0x2025, 0x2027 }, { 0x2030, 0x2030 }, { 0x2032, 0x2033 }, - { 0x2035, 0x2035 }, { 0x203B, 0x203B }, { 0x2074, 0x2074 }, - { 0x207F, 0x207F }, { 0x2081, 0x2084 }, { 0x20AC, 0x20AC }, - { 0x2103, 0x2103 }, { 0x2105, 0x2105 }, { 0x2109, 0x2109 }, - { 0x2113, 0x2113 }, { 0x2121, 0x2122 }, { 0x2126, 0x2126 }, - { 0x212B, 0x212B }, { 0x2154, 0x2155 }, { 0x215B, 0x215B }, - { 0x215E, 0x215E }, { 0x2160, 0x216B }, { 0x2170, 0x2179 }, - { 0x2190, 0x2199 }, { 0x21D2, 0x21D2 }, { 0x21D4, 0x21D4 }, - { 0x2200, 0x2200 }, { 0x2202, 0x2203 }, { 0x2207, 0x2208 }, - { 0x220B, 0x220B }, { 0x220F, 0x220F }, { 0x2211, 0x2211 }, - { 0x2215, 0x2215 }, { 0x221A, 0x221A }, { 0x221D, 0x2220 }, - { 0x2223, 0x2223 }, { 0x2225, 0x2225 }, { 0x2227, 0x222C }, - { 0x222E, 0x222E }, { 0x2234, 0x2237 }, { 0x223C, 0x223D }, - { 0x2248, 0x2248 }, { 0x224C, 0x224C }, { 0x2252, 0x2252 }, - { 0x2260, 0x2261 }, { 0x2264, 0x2267 }, { 0x226A, 0x226B }, - { 0x226E, 0x226F }, { 0x2282, 0x2283 }, { 0x2286, 0x2287 }, - { 0x2295, 0x2295 }, { 0x2299, 0x2299 }, { 0x22A5, 0x22A5 }, - { 0x22BF, 0x22BF }, { 0x2312, 0x2312 }, { 0x2460, 0x24BF }, - { 0x24D0, 0x24E9 }, { 0x2500, 0x254B }, { 0x2550, 0x2574 }, - { 0x2580, 0x258F }, { 0x2592, 0x2595 }, { 0x25A0, 0x25A1 }, - { 0x25A3, 0x25A9 }, { 0x25B2, 0x25B3 }, { 0x25B6, 0x25B7 }, - { 0x25BC, 0x25BD }, { 0x25C0, 0x25C1 }, { 0x25C6, 0x25C8 }, - { 0x25CB, 0x25CB }, { 0x25CE, 0x25D1 }, { 0x25E2, 0x25E5 }, - { 0x25EF, 0x25EF }, { 0x2605, 0x2606 }, { 0x2609, 0x2609 }, - { 0x260E, 0x260F }, { 0x261C, 0x261C }, { 0x261E, 0x261E }, - { 0x2640, 0x2640 }, { 0x2642, 0x2642 }, { 0x2660, 0x2661 }, - { 0x2663, 0x2665 }, { 0x2667, 0x266A }, { 0x266C, 0x266D }, - { 0x266F, 0x266F }, { 0x300A, 0x300B }, { 0x301A, 0x301B }, - { 0xE000, 0xF8FF }, { 0xFFFD, 0xFFFD } - }; - - /* binary search in table of non-spacing characters */ - if (bisearch(ucs, ambiguous, - sizeof(ambiguous) / sizeof(struct interval) - 1)) - return 2; - - return konsole_wcwidth(ucs); -} -#endif - // single byte char: +1, multi byte char: +2 int string_width( const QString &txt ) { diff -r e2911d0176dc -r 212145b8e5f0 libgui/qterminal/libqterminal/unix/konsole_wcwidth.h --- a/libgui/qterminal/libqterminal/unix/konsole_wcwidth.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/qterminal/libqterminal/unix/konsole_wcwidth.h Fri May 12 08:03:14 2023 +0200 @@ -11,12 +11,9 @@ #define _KONSOLE_WCWIDTH_H_ // Qt -#include +#include int konsole_wcwidth(quint16 ucs); -#if 0 -int konsole_wcwidth_cjk(Q_UINT16 ucs); -#endif int string_width( const QString &txt ); diff -r e2911d0176dc -r 212145b8e5f0 libgui/qterminal/libqterminal/unix/kpty_p.h --- a/libgui/qterminal/libqterminal/unix/kpty_p.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/qterminal/libqterminal/unix/kpty_p.h Fri May 12 08:03:14 2023 +0200 @@ -25,7 +25,7 @@ #include "unix/kpty.h" -#include +#include struct KPtyPrivate { Q_DECLARE_PUBLIC(KPty) diff -r e2911d0176dc -r 212145b8e5f0 libgui/qterminal/libqterminal/win32/QWinTerminalImpl.cpp --- a/libgui/qterminal/libqterminal/win32/QWinTerminalImpl.cpp Fri May 12 08:00:41 2023 +0200 +++ b/libgui/qterminal/libqterminal/win32/QWinTerminalImpl.cpp Fri May 12 08:03:14 2023 +0200 @@ -1437,9 +1437,8 @@ ////////////////////////////////////////////////////////////////////////////// -QWinTerminalImpl::QWinTerminalImpl (octave::base_qobject& oct_qobj, - QWidget* parent) - : QTerminal (oct_qobj, parent), d (new QConsolePrivate (this)), +QWinTerminalImpl::QWinTerminalImpl (QWidget* parent) + : QTerminal (parent), d (new QConsolePrivate (this)), allowTripleClick (false) { installEventFilter (this); diff -r e2911d0176dc -r 212145b8e5f0 libgui/qterminal/libqterminal/win32/QWinTerminalImpl.h --- a/libgui/qterminal/libqterminal/win32/QWinTerminalImpl.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/qterminal/libqterminal/win32/QWinTerminalImpl.h Fri May 12 08:03:14 2023 +0200 @@ -49,7 +49,7 @@ friend class QConsoleView; public: - QWinTerminalImpl (octave::base_qobject&, QWidget* parent); + QWinTerminalImpl (QWidget* parent); ~QWinTerminalImpl (void); void setTerminalFont (const QFont& font); diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/color-picker.cc --- a/libgui/src/color-picker.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/color-picker.cc Fri May 12 08:03:14 2023 +0200 @@ -46,7 +46,7 @@ } // Slot for button clicked: select a new color using QColorDialog -void color_picker::select_color (void) +void color_picker::select_color () { QColor new_color = QColorDialog::getColor (m_color); @@ -65,7 +65,7 @@ } // Draw the button with the actual color (using a stylesheet) -void color_picker::update_button (void) +void color_picker::update_button () { // Is this the right place to look for a "foreground" color that would // provide a reasonable border for the color swatches? diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/color-picker.h --- a/libgui/src/color-picker.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/color-picker.h Fri May 12 08:03:14 2023 +0200 @@ -42,17 +42,17 @@ color_picker (QColor color = QColor (0, 0, 0), QWidget *parent = nullptr); - QColor color (void) const { return m_color; } + QColor color () const { return m_color; } void set_color (QColor new_color); private slots: - void select_color (void); + void select_color (); private: - virtual void update_button (void); + virtual void update_button (); QColor m_color; }; diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/command-widget.cc --- a/libgui/src/command-widget.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/command-widget.cc Fri May 12 08:03:14 2023 +0200 @@ -44,16 +44,17 @@ #include "event-manager.h" #include "gui-preferences-cs.h" #include "gui-preferences-global.h" +#include "gui-settings.h" #include "gui-utils.h" #include "input.h" #include "interpreter.h" OCTAVE_BEGIN_NAMESPACE(octave) -command_widget::command_widget (base_qobject& oct_qobj, QWidget *p) -: QWidget (p), m_incomplete_parse (false), - m_prompt (QString ()), - m_console (new console (this, oct_qobj)) +command_widget::command_widget (QWidget *p) + : QWidget (p), m_incomplete_parse (false), + m_prompt (QString ()), + m_console (new console (this)) { QPushButton *pause_button = new QPushButton (tr("Pause"), this); QPushButton *stop_button = new QPushButton (tr("Stop"), this); @@ -83,9 +84,18 @@ connect (stop_button, &QPushButton::clicked, this, &command_widget::interpreter_stop); + connect (this, &command_widget::update_prompt_signal, + this, &command_widget::update_prompt); + connect (this, &command_widget::new_command_line_signal, m_console, &console::new_command_line); + connect (m_console, QOverload::of (&console::interpreter_event), + this, QOverload::of (&command_widget::interpreter_event)); + + connect (m_console, QOverload::of (&console::interpreter_event), + this, QOverload::of (&command_widget::interpreter_event)); + insert_interpreter_output ("\n\n Welcome to Octave\n\n"); } @@ -100,22 +110,23 @@ emit interpreter_event ([=] (interpreter& interp) - { - // INTERPRETER THREAD + { + // INTERPRETER THREAD - // We can skip the entire callback function because it does not - // make any changes to the interpreter state. + // We can skip the entire callback function because it does not + // make any changes to the interpreter state. + + if (this_cw.isNull ()) + return; - if (this_cw.isNull ()) - return; + std::string prompt = interp.PS1 (); + std::string decoded_prompt + = command_editor::decode_prompt_string (prompt); - event_manager& evmgr = interp.get_event_manager (); - input_system& input_sys = interp.get_input_system (); - std::string prompt = input_sys.PS1 (); - evmgr.update_prompt (command_editor::decode_prompt_string (prompt)); + emit update_prompt_signal (QString::fromStdString (decoded_prompt)); - emit new_command_line_signal (); - }); + emit new_command_line_signal (); + }); } void command_widget::update_prompt (const QString& prompt) @@ -143,52 +154,54 @@ emit interpreter_event ([=] (interpreter& interp) - { - // INTERPRETER THREAD + { + // INTERPRETER THREAD - // If THIS_CW is no longer valid, we still want to parse and - // execute INPUT_LINE but we can't emit the signals associated - // with THIS_CW. + // If THIS_CW is no longer valid, we still want to parse and + // execute INPUT_LINE but we can't emit the signals associated + // with THIS_CW. - interp.parse_and_execute (input_line.toStdString (), - m_incomplete_parse); + interp.parse_and_execute (input_line.toStdString (), + m_incomplete_parse); - if (this_cw.isNull ()) - return; + if (this_cw.isNull ()) + return; - event_manager& evmgr = interp.get_event_manager (); - input_system& input_sys = interp.get_input_system (); + std::string prompt + = m_incomplete_parse ? interp.PS2 () : interp.PS1 (); - std::string prompt - = m_incomplete_parse ? input_sys.PS2 () : input_sys.PS1 (); + std::string decoded_prompt + = command_editor::decode_prompt_string (prompt); - evmgr.update_prompt (command_editor::decode_prompt_string (prompt)); + emit update_prompt_signal (QString::fromStdString (decoded_prompt)); - emit new_command_line_signal (); - }); + emit new_command_line_signal (); + }); } -void command_widget::notice_settings (const gui_settings *settings) +void command_widget::notice_settings () { + gui_settings settings; + // Set terminal font: QFont term_font = QFont (); term_font.setStyleHint (QFont::TypeWriter); - QString default_font = settings->value (global_mono_font).toString (); + QString default_font = settings.string_value (global_mono_font); term_font.setFamily - (settings->value (cs_font.key, default_font).toString ()); + (settings.value (cs_font.settings_key (), default_font).toString ()); term_font.setPointSize - (settings->value (cs_font_size).toInt ()); + (settings.int_value (cs_font_size)); m_console->setFont (term_font); // Colors - int mode = settings->value (cs_color_mode).toInt (); - QColor fgc = settings->color_value (cs_colors[0], mode); - QColor bgc = settings->color_value (cs_colors[1], mode); + int mode = settings.int_value (cs_color_mode); + QColor fgc = settings.color_value (cs_colors[0], mode); + QColor bgc = settings.color_value (cs_colors[1], mode); m_console->setStyleSheet (QString ("color: %1; background-color:%2;") - .arg (fgc.name ()).arg (bgc.name ())); + .arg (fgc.name ()).arg (bgc.name ())); } // The console itself using QScintilla. @@ -196,7 +209,7 @@ // "qpconsole" as proposed by user "DerManu" in the Qt-forum thread // https://forum.qt.io/topic/28765/command-terminal-using-qtextedit -console::console (command_widget *p, base_qobject&) +console::console (command_widget *p) : QsciScintilla (p), m_command_position (-1), m_cursor_position (0), @@ -210,11 +223,11 @@ connect (this, SIGNAL (cursorPositionChanged (int, int)), this, SLOT (cursor_position_changed (int, int))); - connect (this, SIGNAL (textChanged (void)), - this, SLOT (text_changed (void))); + connect (this, SIGNAL (textChanged ()), + this, SLOT (text_changed ())); - connect (this, SIGNAL (modificationAttempted (void)), - this, SLOT (move_cursor_to_end (void))); + connect (this, SIGNAL (modificationAttempted ()), + this, SLOT (move_cursor_to_end ())); } // Prepare a new command line with the current prompt @@ -295,7 +308,7 @@ // User attempted to type on read only mode: move cursor at end and allow // editing -void console::move_cursor_to_end (void) +void console::move_cursor_to_end () { if ((! m_last_key_string.isEmpty ()) && (m_last_key_string.at (0).isPrint ())) { @@ -306,7 +319,7 @@ // Text has changed: is cursor still in "writable" area? // This signal seems to be emitted before cursor position changed. -void console::text_changed (void) +void console::text_changed () { m_text_changed = true; } diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/command-widget.h --- a/libgui/src/command-widget.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/command-widget.h Fri May 12 08:03:14 2023 +0200 @@ -30,14 +30,16 @@ #include -#include "octave-qobject.h" -#include "gui-settings.h" +// FIXME: We need the following header for the fcn_callback and +// meth_callback typedefs. Maybe it would be better to declare those in +// a separate file because inclding "event-manager.h" pulls in a lot of +// other unnecessary declarations. +#include "event-manager.h" class QsciScintilla; OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; class command_widget; class console : public QsciScintilla @@ -46,15 +48,20 @@ public: - console (command_widget *p, base_qobject& oct_qobj); + console (command_widget *p); + +signals: + + void interpreter_event (const fcn_callback& fcn); + void interpreter_event (const meth_callback& meth); public slots: void cursor_position_changed (int line, int col); - void text_changed (void); + void text_changed (); - void move_cursor_to_end (void); + void move_cursor_to_end (); void new_command_line (const QString& command = QString ()); @@ -68,7 +75,7 @@ void append_string (const QString& string); - void accept_command_line (void); + void accept_command_line (); int m_command_position; int m_cursor_position; @@ -84,27 +91,28 @@ public: - command_widget (base_qobject& oct_qobj, QWidget *p); + command_widget (QWidget *p); console * get_console ( ) { return m_console; }; void init_command_prompt (); - QString prompt (void); + QString prompt (); signals: - void clear_line_edit (void); + void clear_line_edit (); - void interpreter_pause (void); - void interpreter_resume (void); - void interpreter_stop (void); + void interpreter_pause (); + void interpreter_resume (); + void interpreter_stop (); + + void update_prompt_signal (const QString& prompt); + void new_command_line_signal (const QString& command = QString ()); void interpreter_event (const fcn_callback& fcn); void interpreter_event (const meth_callback& meth); - void new_command_line_signal (const QString& command = QString ()); - public slots: void process_input_line (const QString& input_line); @@ -113,7 +121,7 @@ void insert_interpreter_output (const QString& msg); - void notice_settings (const gui_settings *settings); + void notice_settings (); private: diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/community-news.cc --- a/libgui/src/community-news.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/community-news.cc Fri May 12 08:03:14 2023 +0200 @@ -35,27 +35,25 @@ #include "gui-utils.h" #include "gui-preferences-dw.h" #include "gui-preferences-nr.h" +#include "gui-settings.h" #include "news-reader.h" -#include "octave-qobject.h" OCTAVE_BEGIN_NAMESPACE(octave) -community_news::community_news (base_qobject& oct_qobj, int serial) -: QWidget (nullptr), m_browser (nullptr) +community_news::community_news (int serial) + : QWidget (nullptr), m_browser (nullptr) { - construct (oct_qobj, "https://octave.org", "community-news.html", serial); + construct ("https://octave.org", "community-news.html", serial); } -community_news::community_news (base_qobject& oct_qobj, QWidget *parent, - const QString& base_url, const QString& page, - int serial) +community_news::community_news (QWidget *parent, const QString& base_url, + const QString& page, int serial) : QWidget (parent), m_browser (nullptr) { - construct (oct_qobj, base_url, page, serial); + construct (base_url, page, serial); } -void community_news::construct (base_qobject& oct_qobj, - const QString& base_url, const QString& page, +void community_news::construct (const QString& base_url, const QString& page, int serial) { m_browser = new QTextBrowser (this); @@ -76,11 +74,10 @@ resize (win_x/2, win_y/2); move ((win_x - width ())/2, (win_y - height ())/2); - resource_manager& rmgr = oct_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); + gui_settings settings; QString icon; - QString icon_set = settings->value (dw_icon_set).toString (); + QString icon_set = settings.string_value (dw_icon_set); if (icon_set != "NONE") // No extra icon for Community news, take the one of the release notes icon = dw_icon_set_names[icon_set] + "ReleaseWidget.png"; @@ -92,15 +89,12 @@ // FIXME: This is a news reader preference, so shouldn't it be used // in the news_reader object? - bool connect_to_web - = (settings - ? settings->value (nr_allow_connection).toBool () - : true); + bool connect_to_web = settings.bool_value (nr_allow_connection); QThread *worker_thread = new QThread; - news_reader *reader = new news_reader (oct_qobj, base_url, page, - serial, connect_to_web); + news_reader *reader + = new news_reader (base_url, page, serial, connect_to_web); reader->moveToThread (worker_thread); @@ -125,7 +119,7 @@ m_browser->setHtml (news); } -void community_news::display (void) +void community_news::display () { if (! isVisible ()) show (); diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/community-news.h --- a/libgui/src/community-news.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/community-news.h Fri May 12 08:03:14 2023 +0200 @@ -33,33 +33,30 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; - class community_news : public QWidget { Q_OBJECT public: - community_news (base_qobject& oct_qobj, int serial); + community_news (int serial); - community_news (base_qobject& oct_qobj, QWidget *parent = nullptr, + community_news (QWidget *parent = nullptr, const QString& base_url = "https://octave.org", const QString& page = "community-news.html", int serial = -1); - ~community_news (void) = default; + ~community_news () = default; public slots: void set_news (const QString& news); - void display (void); + void display (); private: - void construct (base_qobject& oct_qobj, const QString& base_url, - const QString& page, int serial); + void construct (const QString& base_url, const QString& page, int serial); QTextBrowser *m_browser; }; diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/dialog.cc --- a/libgui/src/dialog.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/dialog.cc Fri May 12 08:03:14 2023 +0200 @@ -39,17 +39,18 @@ #include #include #include +#include #include #include "dialog.h" -#include "octave-qobject.h" #include "gui-preferences-global.h" +#include "gui-settings.h" OCTAVE_BEGIN_NAMESPACE(octave) -QUIWidgetCreator::QUIWidgetCreator (base_qobject& oct_qobj) -: QObject (), m_octave_qobj (oct_qobj), m_dialog_result (-1), - m_dialog_button (), m_string_list (), m_list_index (), m_path_name () +QUIWidgetCreator::QUIWidgetCreator () + : QObject (), m_dialog_result (-1), m_dialog_button (), + m_string_list (), m_list_index (), m_path_name () { connect (this, &QUIWidgetCreator::create_dialog, this, &QUIWidgetCreator::handle_create_dialog); @@ -67,7 +68,7 @@ QString QUIWidgetCreator::rm_amp (const QString& text) { QString text_wo_amp = text; - text_wo_amp.replace (QRegExp ("&(\\w)"), "\\1"); + text_wo_amp.replace (QRegularExpression {"&(\\w)"}, "\\1"); return text_wo_amp; } @@ -180,8 +181,7 @@ const QStringList& role) { MessageDialog *message_dialog - = new MessageDialog (m_octave_qobj, message, title, icon, - button, defbutton, role); + = new MessageDialog (message, title, icon, button, defbutton, role); connect (message_dialog, &MessageDialog::buttonClicked, this, &QUIWidgetCreator::dialog_button_clicked); @@ -232,7 +232,7 @@ const QString& cancel_string) { ListDialog *list_dialog - = new ListDialog (m_octave_qobj, list, mode, wd, ht, initial, + = new ListDialog (list, mode, wd, ht, initial, name, prompt, ok_string, cancel_string); connect (list_dialog, &ListDialog::finish_selection, @@ -264,7 +264,7 @@ const QStringList& defaults) { InputDialog *input_dialog - = new InputDialog (m_octave_qobj, prompt, title, nr, nc, defaults); + = new InputDialog (prompt, title, nr, nc, defaults); connect (input_dialog, &InputDialog::finish_input, this, &QUIWidgetCreator::input_finished); @@ -292,8 +292,7 @@ const QString& multimode) { FileDialog *file_dialog - = new FileDialog (m_octave_qobj, filters, title, filename, - dirname, multimode); + = new FileDialog (filters, title, filename, dirname, multimode); connect (file_dialog, &FileDialog::finish_input, this, &QUIWidgetCreator::filedialog_finished); @@ -316,7 +315,7 @@ wake_all (); } -MessageDialog::MessageDialog (base_qobject&, const QString& message, +MessageDialog::MessageDialog (const QString& message, const QString& title, const QString& qsicon, const QStringList& qsbutton, const QString& defbutton, @@ -388,7 +387,7 @@ } } -ListDialog::ListDialog (base_qobject&, const QStringList& list, +ListDialog::ListDialog (const QStringList& list, const QString& mode, int wd, int ht, const QList& initial, const QString& title, const QStringList& prompt, @@ -406,13 +405,12 @@ else view->setSelectionMode (QAbstractItemView::NoSelection); - selector = view->selectionModel (); - int i = 0; - for (auto it = initial.begin (); it != initial.end (); it++) + m_selector = view->selectionModel (); + for (int i = 0; i < initial.count(); i++) { - QModelIndex idx = m_model->index (initial.value (i++) - 1, 0, + QModelIndex idx = m_model->index (initial.value (i) - 1, 0, QModelIndex ()); - selector->select (idx, QItemSelectionModel::Select); + m_selector->select (idx, QItemSelectionModel::Select); } bool fixed_layout = false; @@ -427,26 +425,17 @@ QVBoxLayout *listLayout = new QVBoxLayout; if (! prompt.isEmpty ()) { - // For now, assume html-like Rich Text. May be incompatible - // with something down the road, but just testing capability. + // Note: Assume html-like Rich Text. + // Check for future incompatibilities if any. QString prompt_string; - for (int j = 0; j < prompt.length (); j++) + prompt_string.append (prompt.at (0)); + for (int j = 1; j < prompt.length (); j++) { - if (j > 0) - // FIXME: Why define and then immediately test value? -#define RICH_TEXT 1 -#if RICH_TEXT - prompt_string.append ("
"); -#else - prompt_string.append ("\n"); -#endif + prompt_string.append ("
"); prompt_string.append (prompt.at (j)); } QLabel *plabel = new QLabel (prompt_string); -#if RICH_TEXT plabel->setTextFormat (Qt::RichText); -#endif -#undef RICH_TEXT listLayout->addWidget (plabel); } listLayout->addWidget (view); @@ -486,12 +475,12 @@ this, &ListDialog::item_double_clicked); } -void ListDialog::buttonOk_clicked (void) +void ListDialog::buttonOk_clicked () { // Store information about what button was pressed so that builtin // functions can retrieve. - QModelIndexList selected_index = selector->selectedIndexes (); + QModelIndexList selected_index = m_selector->selectedIndexes (); QIntList selected_int; for (int i = 0; i < selected_index.size (); i++) @@ -502,7 +491,7 @@ done (QDialog::Accepted); } -void ListDialog::buttonCancel_clicked (void) +void ListDialog::buttonCancel_clicked () { // Store information about what button was pressed so that builtin // functions can retrieve. @@ -514,7 +503,7 @@ done (QDialog::Rejected); } -void ListDialog::reject (void) +void ListDialog::reject () { buttonCancel_clicked (); } @@ -524,7 +513,7 @@ buttonOk_clicked (); } -InputDialog::InputDialog (base_qobject&, const QStringList& prompt, +InputDialog::InputDialog (const QStringList& prompt, const QString& title, const QFloatList& nr, const QFloatList& nc, const QStringList& defaults) : QDialog () @@ -557,7 +546,7 @@ line_edit->setFixedWidth (intval); } } - input_line << line_edit; + m_input_line << line_edit; #if LINE_EDIT_FOLLOWS_PROMPT promptInputLayout->addWidget (label, i + 1, 0); promptInputLayout->addWidget (line_edit, i + 1, 1); @@ -591,19 +580,19 @@ this, &InputDialog::buttonCancel_clicked); } -void InputDialog::buttonOk_clicked (void) +void InputDialog::buttonOk_clicked () { // Store information about what button was pressed so that builtin // functions can retrieve. QStringList string_result; - for (int i = 0; i < input_line.size (); i++) - string_result << input_line.at (i)->text (); + for (int i = 0; i < m_input_line.size (); i++) + string_result << m_input_line.at (i)->text (); emit finish_input (string_result, 1); done (QDialog::Accepted); } -void InputDialog::buttonCancel_clicked (void) +void InputDialog::buttonCancel_clicked () { // Store information about what button was pressed so that builtin // functions can retrieve. @@ -613,13 +602,12 @@ done (QDialog::Rejected); } -void InputDialog::reject (void) +void InputDialog::reject () { buttonCancel_clicked (); } -FileDialog::FileDialog (base_qobject& oct_qobj, - const QStringList& name_filters, +FileDialog::FileDialog (const QStringList& name_filters, const QString& title, const QString& filename, const QString& dirname, const QString& multimode) : QFileDialog () @@ -631,9 +619,10 @@ setDirectory (dirname); // FIXME: Remove, if for all common KDE versions (bug #54607) is resolved. - resource_manager& rmgr = oct_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - if (! settings->value (global_use_native_dialogs).toBool ()) + + gui_settings settings; + + if (! settings.bool_value (global_use_native_dialogs)) setOption(QFileDialog::DontUseNativeDialog); if (multimode == "on") // uigetfile multiselect=on @@ -669,13 +658,13 @@ connect (this, &FileDialog::rejected, this, &FileDialog::rejectSelection); } -void FileDialog::rejectSelection (void) +void FileDialog::rejectSelection () { QStringList empty; emit finish_input (empty, "", 0); } -void FileDialog::acceptSelection (void) +void FileDialog::acceptSelection () { QStringList string_result; QString path; diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/dialog.h --- a/libgui/src/dialog.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/dialog.h Fri May 12 08:03:14 2023 +0200 @@ -44,17 +44,15 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; - class QUIWidgetCreator : public QObject { Q_OBJECT public: - QUIWidgetCreator (base_qobject& oct_qobj); + QUIWidgetCreator (); - ~QUIWidgetCreator (void) = default; + ~QUIWidgetCreator () = default; public: @@ -64,9 +62,9 @@ const QString& icon, const QStringList& button, const QString& defbutton, const QStringList& role); - int get_dialog_result (void) { return m_dialog_result; } + int get_dialog_result () { return m_dialog_result; } - QString get_dialog_button (void) { return m_dialog_button; } + QString get_dialog_button () { return m_dialog_button; } QPair list_dialog (const QStringList& list, const QString& mode, @@ -77,24 +75,24 @@ const QString& ok_string, const QString& cancel_string); - QIntList get_list_index (void) const { return m_list_index; } + QIntList get_list_index () const { return m_list_index; } QStringList input_dialog (const QStringList& prompt, const QString& title, const QFloatList& nr, const QFloatList& nc, const QStringList& defaults); - QStringList get_string_list (void) const { return m_string_list; } + QStringList get_string_list () const { return m_string_list; } QStringList file_dialog (const QStringList& filters, const QString& title, const QString& filename, const QString& dirname, const QString& multimode); - QString get_dialog_path (void) const { return m_path_name; } + QString get_dialog_path () const { return m_path_name; } - void lock (void) { m_mutex.lock (); } - void wait (void) { m_waitcondition.wait (&m_mutex); } - void unlock (void) { m_mutex.unlock (); } - void wake_all (void) { m_waitcondition.wakeAll (); } + void lock () { m_mutex.lock (); } + void wait () { m_waitcondition.wait (&m_mutex); } + void unlock () { m_mutex.unlock (); } + void wake_all () { m_waitcondition.wakeAll (); } signals: @@ -148,8 +146,6 @@ private: - base_qobject& m_octave_qobj; - int m_dialog_result; QString m_dialog_button; @@ -176,12 +172,12 @@ public: - MessageDialog (base_qobject& oct_qobj, const QString& message, + MessageDialog (const QString& message, const QString& title, const QString& icon, const QStringList& button, const QString& defbutton, const QStringList& role); - ~MessageDialog (void) = default; + ~MessageDialog () = default; private: @@ -197,17 +193,15 @@ { Q_OBJECT - QItemSelectionModel *selector; - public: - ListDialog (base_qobject& oct_qobj, const QStringList& list, + ListDialog (const QStringList& list, const QString& mode, int width, int height, const QList& initial, const QString& name, const QStringList& prompt, const QString& ok_string, const QString& cancel_string); - ~ListDialog (void) = default; + ~ListDialog () = default; signals: @@ -215,32 +209,31 @@ public slots: - void buttonOk_clicked (void); + void buttonOk_clicked (); - void buttonCancel_clicked (void); + void buttonCancel_clicked (); - void reject (void); + void reject (); void item_double_clicked (const QModelIndex&); private: QAbstractItemModel *m_model; + QItemSelectionModel *m_selector; }; class InputDialog : public QDialog { Q_OBJECT - QList input_line; - public: - InputDialog (base_qobject& oct_qobj, const QStringList& prompt, + InputDialog (const QStringList& prompt, const QString& title, const QFloatList& nr, const QFloatList& nc, const QStringList& defaults); - ~InputDialog (void) = default; + ~InputDialog () = default; signals: @@ -248,11 +241,15 @@ public slots: - void buttonOk_clicked (void); + void buttonOk_clicked (); + + void buttonCancel_clicked (); - void buttonCancel_clicked (void); + void reject (); - void reject (void); +private: + + QList m_input_line; }; class FileDialog : public QFileDialog @@ -261,11 +258,11 @@ public: - FileDialog (base_qobject& oct_qobj, const QStringList& filters, + FileDialog (const QStringList& filters, const QString& title, const QString& filename, const QString& dirname, const QString& multimode); - ~FileDialog (void) = default; + ~FileDialog () = default; signals: @@ -273,9 +270,9 @@ private slots: - void acceptSelection (void); + void acceptSelection (); - void rejectSelection (void); + void rejectSelection (); }; OCTAVE_END_NAMESPACE(octave) diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/documentation-bookmarks.cc --- a/libgui/src/documentation-bookmarks.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/documentation-bookmarks.cc Fri May 12 08:03:14 2023 +0200 @@ -28,20 +28,22 @@ #endif #include +#include +#include +#include +#include #include -#include +#include #include #include #include "documentation.h" #include "documentation-bookmarks.h" -#include "gui-settings.h" #include "gui-preferences-global.h" #include "gui-preferences-dc.h" #include "gui-preferences-sc.h" -#include "octave-qtutils.h" -#include "shortcut-manager.h" +#include "gui-settings.h" #include "defaults.h" #include "file-ops.h" @@ -49,17 +51,14 @@ OCTAVE_BEGIN_NAMESPACE(octave) -documentation_bookmarks::documentation_bookmarks ( - documentation *doc, documentation_browser *browser, - base_qobject& oct_qobj, QWidget *p) -: QWidget (p), - m_doc (doc), m_browser (browser), m_octave_qobj (oct_qobj), - m_ctx_menu_item (nullptr) +documentation_bookmarks::documentation_bookmarks (documentation *doc, + documentation_browser *browser, + QWidget *p) + : QWidget (p), m_doc (doc), m_browser (browser), m_ctx_menu_item (nullptr) { setObjectName ("documentation_tab_bookmarks"); - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); + gui_settings settings; // Setup the tree view with the bookmarks m_tree = new QTreeWidget (p); @@ -82,14 +81,14 @@ this, &documentation_bookmarks::handle_double_click); // Define the icons for the tree view - icon_folder.addPixmap (style ()->standardPixmap(QStyle::SP_DirClosedIcon), + m_icon_folder.addPixmap (style ()->standardPixmap(QStyle::SP_DirClosedIcon), QIcon::Normal, QIcon::Off); - icon_folder.addPixmap (style ()->standardPixmap(QStyle::SP_DirOpenIcon), + m_icon_folder.addPixmap (style ()->standardPixmap(QStyle::SP_DirOpenIcon), QIcon::Normal, QIcon::On); - icon_bookmark.addPixmap (style ()->standardPixmap(QStyle::SP_FileIcon)); + m_icon_bookmark.addPixmap (style ()->standardPixmap(QStyle::SP_FileIcon)); // Setup and read the bookmarkfile - QFileInfo f (settings->fileName ()); + QFileInfo f (settings.fileName ()); QString f_path = f.absolutePath (); f.setFile (QDir (f_path), dc_bookmark_file); m_xbel_file.setFileName (f.absoluteFilePath ()); @@ -121,7 +120,7 @@ m_filter->setSizePolicy (size_pol); m_filter->completer ()->setCaseSensitivity (Qt::CaseSensitive); - m_filter->addItems (settings->value (dc_bookmark_filter_mru).toStringList ()); + m_filter->addItems (settings.string_list_value (dc_bookmark_filter_mru)); connect (m_filter, &QComboBox::editTextChanged, this, &documentation_bookmarks::filter_bookmarks); @@ -129,7 +128,7 @@ this, &documentation_bookmarks::update_filter_history); m_filter_checkbox = new QCheckBox (m_filter_widget); - bool filter_state = settings->value (dc_bookmark_filter_active).toBool (); + bool filter_state = settings.bool_value (dc_bookmark_filter_active); m_filter_checkbox->setChecked (filter_state); filter_activate (filter_state); @@ -141,10 +140,10 @@ h_box_bm->addWidget (filter_label); h_box_bm->addWidget (m_filter_checkbox); h_box_bm->addWidget (m_filter); - h_box_bm->setMargin (2); + h_box_bm->setContentsMargins (2, 2, 2, 2); m_filter_widget->setLayout (h_box_bm); - m_filter_shown = settings->value (dc_bookmark_filter_shown).toBool (); + m_filter_shown = settings.bool_value (dc_bookmark_filter_shown); m_filter_widget->setVisible (m_filter_shown); // Resulting Layout of this widget @@ -155,7 +154,7 @@ } // Slot for adding the current page as a bookmark -void documentation_bookmarks::add_bookmark (void) +void documentation_bookmarks::add_bookmark () { QUrl url = m_browser->historyUrl (0); @@ -189,9 +188,9 @@ new_item->setData (0, tag_role, QVariant (bookmark_tag)); new_item->setData (0, url_role, QVariant (url)); new_item->setFlags ((new_item->flags () & (~Qt::ItemIsDropEnabled)) - | Qt::ItemIsEditable - | Qt::ItemIsDragEnabled); - new_item->setIcon (0, icon_bookmark); + | Qt::ItemIsEditable + | Qt::ItemIsDragEnabled); + new_item->setIcon (0, m_icon_bookmark); // Insert as top level or child item // TODO: Open dialog allowing to select a target folder if this @@ -227,15 +226,15 @@ // Function for actually adding a folder to the tree QTreeWidgetItem* documentation_bookmarks::add_folder (const QString& folder, - QTreeWidgetItem *item, bool expanded) + QTreeWidgetItem *item, bool expanded) { QTreeWidgetItem *new_folder = new QTreeWidgetItem (QStringList (folder)); new_folder->setData (0, tag_role, QVariant (folder_tag)); new_folder->setFlags (new_folder->flags() | Qt::ItemIsEditable - | Qt::ItemIsDragEnabled - | Qt::ItemIsDropEnabled); + | Qt::ItemIsDragEnabled + | Qt::ItemIsDropEnabled); new_folder->setChildIndicatorPolicy (QTreeWidgetItem::DontShowIndicatorWhenChildless); - new_folder->setIcon (0, icon_folder); + new_folder->setIcon (0, m_icon_folder); new_folder->setExpanded (expanded); // Insert as top level or child item @@ -283,7 +282,7 @@ filter_bookmarks (pattern); } -void documentation_bookmarks::update_filter_history (void) +void documentation_bookmarks::update_filter_history () { QString text = m_filter->currentText (); // get current text int index = m_filter->findText (text); // and its actual index @@ -322,11 +321,11 @@ if (m_ctx_menu_item) { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); + gui_settings settings; menu.addAction (tr ("&Open"), this, &documentation_bookmarks::open); menu.addAction (tr ("&Rename"), this, &documentation_bookmarks::edit); - menu.addAction (rmgr.icon ("window-close"), tr ("Remo&ve"), + menu.addAction (settings.icon ("window-close"), tr ("Remo&ve"), this, &documentation_bookmarks::remove); menu.addSeparator (); } @@ -366,12 +365,9 @@ { QList items = m_tree->selectedItems (); - for (auto it = items.begin () ; it != items.end (); it++) - { - if (*it) - m_tree->takeTopLevelItem ( - m_tree->indexOfTopLevelItem (*it)); - } + for (const auto& it : items) + if (it) + m_tree->takeTopLevelItem (m_tree->indexOfTopLevelItem (it)); } void documentation_bookmarks::show_filter (bool) @@ -380,32 +376,34 @@ m_filter_widget->setVisible (m_filter_shown); } -void documentation_bookmarks::save_settings (gui_settings *settings) +void documentation_bookmarks::save_settings () { // Write the bookmarks to the xbel-file write_bookmarks (); // Store settings - settings->setValue (dc_bookmark_filter_active.key, m_filter_checkbox->isChecked ()); - settings->setValue (dc_bookmark_filter_shown.key, m_filter_shown); + gui_settings settings; + + settings.setValue (dc_bookmark_filter_active.settings_key (), m_filter_checkbox->isChecked ()); + settings.setValue (dc_bookmark_filter_shown.settings_key (), m_filter_shown); QStringList mru; for (int i = 0; i < m_filter->count (); i++) mru.append (m_filter->itemText (i)); - settings->setValue (dc_bookmark_filter_mru.key, mru); + settings.setValue (dc_bookmark_filter_mru.settings_key (), mru); - settings->sync (); + settings.sync (); } -void documentation_bookmarks::write_bookmarks (void) +void documentation_bookmarks::write_bookmarks () { if (! m_xbel_file.open (QFile::WriteOnly | QFile::Text)) { QMessageBox::warning (this, tr("Octave: Saving Documentation Bookmarks"), tr("Unable to write file %1:\n%2.\n\n" "Documentation bookmarks are not saved!\n") - .arg (m_xbel_file.fileName ()) - .arg (m_xbel_file.errorString())); + .arg (m_xbel_file.fileName ()) + .arg (m_xbel_file.errorString())); return; } @@ -450,7 +448,7 @@ } } -QString documentation_bookmarks::read_bookmarks (void) +QString documentation_bookmarks::read_bookmarks () { QString error_message; @@ -458,8 +456,8 @@ if (! m_xbel_file.open (QFile::ReadOnly | QFile::Text)) { error_message = tr ("Unable to read file %1:\n%2.") - .arg (m_xbel_file.fileName ()) - .arg (m_xbel_file.errorString()); + .arg (m_xbel_file.fileName ()) + .arg (m_xbel_file.errorString()); return error_message; } @@ -469,7 +467,7 @@ { error_message = tr ("No start element found in %1.\n" "Invalid bookmark file?") - .arg (m_xbel_file.fileName ()); + .arg (m_xbel_file.fileName ()); return error_message; } @@ -479,7 +477,7 @@ error_message = tr ("The file\n" "%1\n" "is not a valid XBEL file version 1.0.") - .arg (m_xbel_file.fileName ()); + .arg (m_xbel_file.fileName ()); return error_message; } diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/documentation-bookmarks.h --- a/libgui/src/documentation-bookmarks.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/documentation-bookmarks.h Fri May 12 08:03:14 2023 +0200 @@ -28,15 +28,14 @@ #include #include +#include #include #include #include "documentation.h" -#include "octave-qobject.h" OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; class documentation; class documentation_bookmarks : public QWidget @@ -45,23 +44,23 @@ public: - documentation_bookmarks ( - documentation *doc, documentation_browser *browser, - base_qobject& oct_qobj, QWidget *p = nullptr); + documentation_bookmarks (documentation *doc, + documentation_browser *browser, + QWidget *p = nullptr); - ~documentation_bookmarks (void) = default; + ~documentation_bookmarks () = default; public slots: - void add_bookmark (void); + void add_bookmark (); void add_folder (bool); - void save_settings (gui_settings *settings); + void save_settings (); private slots: void filter_bookmarks (const QString& pattern); void filter_activate (bool state); - void update_filter_history (void); + void update_filter_history (); void handle_double_click (QTreeWidgetItem *item, int col = 0); void ctx_menu (const QPoint& xpos); void open (bool); @@ -72,15 +71,15 @@ private: enum item_role - { - url_role = Qt::UserRole, - tag_role = Qt::UserRole + 1 - }; + { + url_role = Qt::UserRole, + tag_role = Qt::UserRole + 1 + }; enum item_tag - { - bookmark_tag, - folder_tag - }; + { + bookmark_tag, + folder_tag + }; void add_bookmark (const QString& title, const QString& url, QTreeWidgetItem *item = nullptr); @@ -89,28 +88,27 @@ bool expanded = true); /*! - Writing to and reading bookmarks from an xbel-file as - proposed in the qt example - [QXmlStream Bookmarks Example](https://doc.qt.io/qt-5/qtxml-streambookmarks-example.html) + Writing to and reading bookmarks from an xbel-file as + proposed in the qt example + [QXmlStream Bookmarks Example](https://doc.qt.io/qt-5/qtxml-streambookmarks-example.html) */ - void write_bookmarks (void); + void write_bookmarks (); void write_tree_item (QXmlStreamWriter *xml_writer, const QTreeWidgetItem *item); - QString read_bookmarks (void); + QString read_bookmarks (); void read_next_item (QXmlStreamReader *xml_writer, item_tag tag, QTreeWidgetItem *item = nullptr); documentation *m_doc; documentation_browser *m_browser; - base_qobject& m_octave_qobj; QComboBox *m_filter; QTreeWidget *m_tree; QTreeWidgetItem *m_ctx_menu_item; - QIcon icon_folder; - QIcon icon_bookmark; + QIcon m_icon_folder; + QIcon m_icon_bookmark; QWidget *m_filter_widget; QCheckBox *m_filter_checkbox; diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/documentation-dock-widget.cc --- a/libgui/src/documentation-dock-widget.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/documentation-dock-widget.cc Fri May 12 08:03:14 2023 +0200 @@ -33,10 +33,9 @@ OCTAVE_BEGIN_NAMESPACE(octave) -documentation_dock_widget::documentation_dock_widget (QWidget *p, - base_qobject& oct_qobj) -: octave_dock_widget ("DocumentationDockWidget", p, oct_qobj), - m_docs (new documentation (this, oct_qobj)) +documentation_dock_widget::documentation_dock_widget (QWidget *p) + : octave_dock_widget ("DocumentationDockWidget", p), + m_docs (new documentation (this)) { set_title (tr ("Documentation")); setStatusTip (tr ("See the documentation for help.")); @@ -47,28 +46,28 @@ make_window (); } -void documentation_dock_widget::notice_settings (const gui_settings *settings) +void documentation_dock_widget::notice_settings () { - m_docs->notice_settings (settings); + m_docs->notice_settings (); } -void documentation_dock_widget::save_settings (void) +void documentation_dock_widget::save_settings () { m_docs->save_settings (); octave_dock_widget::save_settings (); } -void documentation_dock_widget::copyClipboard (void) +void documentation_dock_widget::copyClipboard () { m_docs->copyClipboard (); } -void documentation_dock_widget::pasteClipboard (void) +void documentation_dock_widget::pasteClipboard () { m_docs->pasteClipboard (); } -void documentation_dock_widget::selectAll (void) +void documentation_dock_widget::selectAll () { m_docs->selectAll (); } diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/documentation-dock-widget.h --- a/libgui/src/documentation-dock-widget.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/documentation-dock-widget.h Fri May 12 08:03:14 2023 +0200 @@ -31,26 +31,24 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; - class documentation_dock_widget : public octave_dock_widget { Q_OBJECT public: - documentation_dock_widget (QWidget *parent, base_qobject& oct_qobj); + documentation_dock_widget (QWidget *parent); - ~documentation_dock_widget (void) = default; + ~documentation_dock_widget () = default; public slots: - void notice_settings (const gui_settings *settings); - void save_settings (void); + void notice_settings (); + void save_settings (); - void copyClipboard (void); - void pasteClipboard (void); - void selectAll (void); + void copyClipboard (); + void pasteClipboard (); + void selectAll (); void showDoc (const QString& name); void registerDoc (const QString& name); diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/documentation.cc --- a/libgui/src/documentation.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/documentation.cc Fri May 12 08:03:14 2023 +0200 @@ -47,17 +47,19 @@ #include #include #include +#include #include #include +#include #include +#include #include "documentation.h" #include "documentation-bookmarks.h" #include "gui-preferences-global.h" #include "gui-preferences-dc.h" #include "gui-preferences-sc.h" -#include "octave-qobject.h" -#include "shortcut-manager.h" +#include "gui-settings.h" #include "defaults.h" #include "file-ops.h" @@ -67,19 +69,19 @@ // The documentation splitter, which is the main widget // of the doc dock widget -documentation::documentation (QWidget *p, base_qobject& oct_qobj) -: QSplitter (Qt::Horizontal, p), - m_octave_qobj (oct_qobj), m_doc_widget (this), - m_tool_bar (new QToolBar (this)), - m_query_string (QString ()), - m_indexed (false), - m_current_ref_name (QString ()), - m_prev_pages_menu (new QMenu (this)), - m_next_pages_menu (new QMenu (this)), - m_prev_pages_count (0), - m_next_pages_count (0), - m_findnext_shortcut (new QShortcut (this)), - m_findprev_shortcut (new QShortcut (this)) +documentation::documentation (QWidget *p) + : QSplitter (Qt::Horizontal, p), + m_doc_widget (this), + m_tool_bar (new QToolBar (this)), + m_query_string (QString ()), + m_indexed (false), + m_current_ref_name (QString ()), + m_prev_pages_menu (new QMenu (this)), + m_next_pages_menu (new QMenu (this)), + m_prev_pages_count (0), + m_next_pages_count (0), + m_findnext_shortcut (new QShortcut (this)), + m_findprev_shortcut (new QShortcut (this)) { // Get original collection QString collection = getenv ("OCTAVE_QTHELP_COLLECTION"); @@ -156,14 +158,16 @@ QToolButton *forward_button = new QToolButton (find_footer); forward_button->setText (tr ("Search forward")); forward_button->setToolTip (tr ("Search forward")); - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - forward_button->setIcon (rmgr.icon ("go-down")); + + gui_settings settings; + + forward_button->setIcon (settings.icon ("go-down")); connect (forward_button, &QToolButton::pressed, this, [=] () { find (); }); QToolButton *backward_button = new QToolButton (find_footer); backward_button->setText (tr ("Search backward")); backward_button->setToolTip (tr ("Search backward")); - backward_button->setIcon (rmgr.icon ("go-up")); + backward_button->setIcon (settings.icon ("go-up")); connect (backward_button, &QToolButton::pressed, this, &documentation::find_backward); QHBoxLayout *h_box_find_footer = new QHBoxLayout (find_footer); @@ -171,7 +175,7 @@ h_box_find_footer->addWidget (m_find_line_edit); h_box_find_footer->addWidget (forward_button); h_box_find_footer->addWidget (backward_button); - h_box_find_footer->setMargin (2); + h_box_find_footer->setContentsMargins (2, 2, 2, 2); find_footer->setLayout (h_box_find_footer); QVBoxLayout *v_box_browser_find = new QVBoxLayout (browser_find); @@ -180,7 +184,7 @@ v_box_browser_find->addWidget (find_footer); browser_find->setLayout (v_box_browser_find); - notice_settings (rmgr.get_settings ()); + notice_settings (); m_findnext_shortcut->setContext (Qt::WidgetWithChildrenShortcut); connect (m_findnext_shortcut, &QShortcut::activated, @@ -232,7 +236,7 @@ QHBoxLayout *h_box_index = new QHBoxLayout (filter_all); h_box_index->addWidget (filter_label); h_box_index->addWidget (m_filter); - h_box_index->setMargin (2); + h_box_index->setContentsMargins (2, 2, 2, 2); filter_all->setLayout (h_box_index); QWidget *index_all = new QWidget (navi); @@ -262,8 +266,7 @@ this, &documentation::filter_update_history); // Bookmarks (own class) - m_bookmarks - = new documentation_bookmarks (this, m_doc_browser, m_octave_qobj, navi); + m_bookmarks = new documentation_bookmarks (this, m_doc_browser, navi); navi->addTab (m_bookmarks, tr ("Bookmarks")); connect (m_action_bookmark, &QAction::triggered, @@ -300,7 +303,7 @@ } } -documentation::~documentation (void) +documentation::~documentation () { // Cleanup temporary file and directory QFile file (m_collection); @@ -345,17 +348,18 @@ return a; } -void documentation::construct_tool_bar (void) +void documentation::construct_tool_bar () { // Home, Previous, Next - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); + gui_settings settings; + m_action_go_home - = add_action (rmgr.icon ("go-home"), tr ("Go home"), SLOT (home (void)), + = add_action (settings.icon ("go-home"), tr ("Go home"), SLOT (home ()), m_doc_browser, m_tool_bar); m_action_go_prev - = add_action (rmgr.icon ("go-previous"), tr ("Go back"), - SLOT (backward (void)), m_doc_browser, m_tool_bar); + = add_action (settings.icon ("go-previous"), tr ("Go back"), + SLOT (backward ()), m_doc_browser, m_tool_bar); m_action_go_prev->setEnabled (false); // popdown menu with prev pages files @@ -369,8 +373,8 @@ m_tool_bar->addWidget (popdown_button_prev_pages); m_action_go_next - = add_action (rmgr.icon ("go-next"), tr ("Go forward"), - SLOT (forward (void)), m_doc_browser, m_tool_bar); + = add_action (settings.icon ("go-next"), tr ("Go forward"), + SLOT (forward ()), m_doc_browser, m_tool_bar); m_action_go_next->setEnabled (false); // popdown menu with prev pages files @@ -412,29 +416,29 @@ // Find m_tool_bar->addSeparator (); m_action_find - = add_action (rmgr.icon ("edit-find"), tr ("Find"), - SLOT (activate_find (void)), this, m_tool_bar); + = add_action (settings.icon ("edit-find"), tr ("Find"), + SLOT (activate_find ()), this, m_tool_bar); // Zoom m_tool_bar->addSeparator (); m_action_zoom_in - = add_action (rmgr.icon ("view-zoom-in"), tr ("Zoom in"), - SLOT (zoom_in (void)), m_doc_browser, m_tool_bar); + = add_action (settings.icon ("view-zoom-in"), tr ("Zoom in"), + SLOT (zoom_in ()), m_doc_browser, m_tool_bar); m_action_zoom_out - = add_action (rmgr.icon ("view-zoom-out"), tr ("Zoom out"), - SLOT (zoom_out (void)), m_doc_browser, m_tool_bar); + = add_action (settings.icon ("view-zoom-out"), tr ("Zoom out"), + SLOT (zoom_out ()), m_doc_browser, m_tool_bar); m_action_zoom_original - = add_action (rmgr.icon ("view-zoom-original"), tr ("Zoom original"), - SLOT (zoom_original (void)), m_doc_browser, m_tool_bar); + = add_action (settings.icon ("view-zoom-original"), tr ("Zoom original"), + SLOT (zoom_original ()), m_doc_browser, m_tool_bar); // Bookmarks (connect slots later) m_tool_bar->addSeparator (); m_action_bookmark - = add_action (rmgr.icon ("bookmark-new"), tr ("Bookmark current page"), - nullptr, nullptr, m_tool_bar); + = add_action (settings.icon ("bookmark-new"), + tr ("Bookmark current page"), nullptr, nullptr, m_tool_bar); } -void documentation::global_search (void) +void documentation::global_search () { if (! m_help_engine) return; @@ -458,20 +462,21 @@ return; // Get quoted search strings first, then take first string as fall back - QRegExp rx ("\"([^\"]*)\""); - if (rx.indexIn (query_string, 0) != -1) - m_internal_search = rx.cap (1); + QRegularExpression rx {"\"([^\"]*)\""}; + QRegularExpressionMatch match = rx.match (query_string); + if (match.hasMatch ()) + m_internal_search = match.captured (1); else #if defined (HAVE_QT_SPLITBEHAVIOR_ENUM) m_internal_search = query_string.split (" ", Qt::SkipEmptyParts).first (); #else - m_internal_search = query_string.split (" ", QString::SkipEmptyParts).first (); + m_internal_search = query_string.split (" ", QString::SkipEmptyParts).first (); #endif m_help_engine->searchEngine ()->search (queries); } -void documentation::global_search_started (void) +void documentation::global_search_started () { qApp->setOverrideCursor(QCursor(Qt::WaitCursor)); } @@ -504,21 +509,21 @@ #if defined (HAVE_QHELPSEARCHQUERYWIDGET_SEARCHINPUT) url = res.front ().url (); #else - url = res.front ().first; + url = res.front ().first; #endif else { // Remove the quotes we added QString search_string = m_internal_search; - for (auto r = res.begin (); r != res.end (); r++) + for (const auto& r : res) { #if defined (HAVE_QHELPSEARCHQUERYWIDGET_SEARCHINPUT) - QString title = r->title ().toLower (); - QUrl tmpurl = r->url (); + QString title = r.title ().toLower (); + QUrl tmpurl = r.url (); #else - QString title = r->second.toLower (); - QUrl tmpurl = r->first; + QString title = r.second.toLower (); + QUrl tmpurl = r.first; #endif if (title.contains (search_string.toLower ())) { @@ -603,15 +608,17 @@ m_doc_browser->moveCursor (QTextCursor::Start); } -void documentation::notice_settings (const gui_settings *settings) +void documentation::notice_settings () { + gui_settings settings; + // If m_help_engine is not defined, the objects accessed by this method // are not valid. Thus, just return in this case. if (! m_help_engine) return; // Icon size in the toolbar. - int size_idx = settings->value (global_icon_size).toInt (); + int size_idx = settings.int_value (global_icon_size); size_idx = (size_idx > 0) - (size_idx < 0) + 1; // Make valid index from 0 to 2 QStyle *st = style (); @@ -619,33 +626,30 @@ m_tool_bar->setIconSize (QSize (icon_size, icon_size)); // Shortcuts - shortcut_manager& scmgr = m_octave_qobj.get_shortcut_manager (); - - scmgr.set_shortcut (m_action_find, sc_edit_edit_find_replace); - scmgr.shortcut (m_findnext_shortcut, sc_edit_edit_find_next); - scmgr.shortcut (m_findprev_shortcut, sc_edit_edit_find_previous); - scmgr.set_shortcut (m_action_zoom_in, sc_edit_view_zoom_in); - scmgr.set_shortcut (m_action_zoom_out, sc_edit_view_zoom_out); - scmgr.set_shortcut (m_action_zoom_original, sc_edit_view_zoom_normal); - scmgr.set_shortcut (m_action_go_home, sc_doc_go_home); - scmgr.set_shortcut (m_action_go_prev, sc_doc_go_back); - scmgr.set_shortcut (m_action_go_next, sc_doc_go_next); - scmgr.set_shortcut (m_action_bookmark, sc_doc_bookmark); + settings.set_shortcut (m_action_find, sc_edit_edit_find_replace); + settings.shortcut (m_findnext_shortcut, sc_edit_edit_find_next); + settings.shortcut (m_findprev_shortcut, sc_edit_edit_find_previous); + settings.set_shortcut (m_action_zoom_in, sc_edit_view_zoom_in); + settings.set_shortcut (m_action_zoom_out, sc_edit_view_zoom_out); + settings.set_shortcut (m_action_zoom_original, sc_edit_view_zoom_normal); + settings.set_shortcut (m_action_go_home, sc_doc_go_home); + settings.set_shortcut (m_action_go_prev, sc_doc_go_back); + settings.set_shortcut (m_action_go_next, sc_doc_go_next); + settings.set_shortcut (m_action_bookmark, sc_doc_bookmark); // Settings for the browser - m_doc_browser->notice_settings (settings); + m_doc_browser->notice_settings (); } -void documentation::save_settings (void) +void documentation::save_settings () { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); + gui_settings settings; - m_doc_browser->save_settings (settings); - m_bookmarks->save_settings (settings); + m_doc_browser->save_settings (); + m_bookmarks->save_settings (); } -void documentation::copyClipboard (void) +void documentation::copyClipboard () { if (m_doc_browser->hasFocus ()) { @@ -653,11 +657,11 @@ } } -void documentation::pasteClipboard (void) { } +void documentation::pasteClipboard () { } -void documentation::selectAll (void) { } +void documentation::selectAll () { } -void documentation::load_index (void) +void documentation::load_index () { m_indexed = true; @@ -737,7 +741,7 @@ } } -void documentation::activate_find (void) +void documentation::activate_find () { if (m_find_line_edit->parentWidget ()->isVisible ()) { @@ -764,7 +768,7 @@ m_help_engine->indexWidget ()->filterIndices(expression, wildcard); } -void documentation::filter_update_history (void) +void documentation::filter_update_history () { QString text = m_filter->currentText (); // get current text int index = m_filter->findText (text); // and its actual index @@ -776,7 +780,7 @@ m_filter->setCurrentIndex (0); } -void documentation::find_backward (void) +void documentation::find_backward () { find (true); } @@ -824,7 +828,7 @@ } } -void documentation::record_anchor_position (void) +void documentation::record_anchor_position () { if (! m_help_engine) return; @@ -832,7 +836,7 @@ m_search_anchor_position = m_doc_browser->textCursor ().position (); } -void documentation::handle_cursor_position_change (void) +void documentation::handle_cursor_position_change () { if (! m_help_engine) return; @@ -885,7 +889,7 @@ } } -void documentation::update_history_menus (void) +void documentation::update_history_menus () { if (m_prev_pages_count != m_doc_browser->backwardHistoryCount ()) { @@ -952,7 +956,7 @@ QString retval = title; QString u = url.toString (); - retval.remove (QRegExp ("\\s*\\(*GNU Octave \\(version [^\\)]*\\)[: \\)]*")); + retval.remove (QRegularExpression {"\\s*\\(*GNU Octave \\(version [^\\)]*\\)[: \\)]*"}); // Since the title only contains the section name and not the // specific anchor, extract the latter from the url and append @@ -962,19 +966,22 @@ // Get the anchor from the url QString anchor = u.split ('#').last (); // Remove internal string parts - anchor.remove (QRegExp ("^index-")); - anchor.remove (QRegExp ("^SEC_")); - anchor.remove (QRegExp ("^XREF")); + anchor.remove (QRegularExpression {"^index-"}); + anchor.remove (QRegularExpression {"^SEC_"}); + anchor.remove (QRegularExpression {"^XREF"}); anchor.remove ("Concept-Index_cp_letter-"); anchor.replace ("-", " "); // replace encoded special chars by their unencoded versions - QRegExp rx = QRegExp ("_00([0-7][0-9a-f])"); + QRegularExpression rx {"_00([0-7][0-9a-f])"}; + QRegularExpressionMatch match = rx.match (anchor, 0); int pos = 0; - while ((pos = rx.indexIn(anchor, pos)) != -1) + while (match.hasMatch ()) { - anchor.replace ("_00"+rx.cap (1), QChar (rx.cap (1).toInt (nullptr, 16))); - pos += rx.matchedLength(); + anchor.replace ("_00" + match.captured (1), + QChar (match.captured (1).toInt (nullptr, 16))); + pos += match.capturedLength (); + match = rx.match (anchor, pos); } if (retval != anchor) @@ -998,7 +1005,7 @@ // Make sure we have access to one of the monospace fonts listed in // octave.css for rendering formated code blocks QStringList fonts = {"Fantasque Sans Mono", "FreeMono", "Courier New", - "Cousine", "Courier"}; + "Cousine", "Courier"}; bool load_default_font = true; @@ -1019,7 +1026,7 @@ + sys::file_ops::dir_sep_str ()); QStringList default_fonts = {"FreeMono", "FreeMonoBold", - "FreeMonoBoldOblique", "FreeMonoOblique"}; + "FreeMonoBoldOblique", "FreeMonoOblique"}; for (int i = 0; i < default_fonts.size (); ++i) { @@ -1039,12 +1046,14 @@ QDesktopServices::openUrl (url); } -void documentation_browser::notice_settings (const gui_settings *settings) +void documentation_browser::notice_settings () { + gui_settings settings; + // Zoom level only at startup, not when other settings have changed if (m_zoom_level > max_zoom_level) { - m_zoom_level = settings->value (dc_browser_zoom_level).toInt (); + m_zoom_level = settings.int_value (dc_browser_zoom_level); zoomIn (m_zoom_level); } } @@ -1057,14 +1066,16 @@ return QTextBrowser::loadResource(type, url); } -void documentation_browser::save_settings (gui_settings *settings) +void documentation_browser::save_settings () { - settings->setValue (dc_browser_zoom_level.key, m_zoom_level); + gui_settings settings; - settings->sync (); + settings.setValue (dc_browser_zoom_level.settings_key (), m_zoom_level); + + settings.sync (); } -void documentation_browser::zoom_in (void) +void documentation_browser::zoom_in () { if (m_zoom_level < max_zoom_level) { @@ -1073,7 +1084,7 @@ } } -void documentation_browser::zoom_out (void) +void documentation_browser::zoom_out () { if (m_zoom_level > min_zoom_level) { @@ -1082,7 +1093,7 @@ } } -void documentation_browser::zoom_original (void) +void documentation_browser::zoom_original () { zoomIn (- m_zoom_level); m_zoom_level = 0; @@ -1092,14 +1103,10 @@ { if (we->modifiers () == Qt::ControlModifier) { -#if defined (HAVE_QWHEELEVENT_ANGLEDELTA) if (we->angleDelta().y () > 0) -#else - if (we->delta() > 0) -#endif - zoom_in (); - else - zoom_out (); + zoom_in (); + else + zoom_out (); we->accept (); } diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/documentation.h --- a/libgui/src/documentation.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/documentation.h Fri May 12 08:03:14 2023 +0200 @@ -37,11 +37,8 @@ #include #include -#include "gui-settings.h" - OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; class documentation; class documentation_bookmarks; @@ -54,7 +51,7 @@ public: documentation_browser (QHelpEngine *help_engine, QWidget *parent = nullptr); - ~documentation_browser (void) = default; + ~documentation_browser () = default; virtual QVariant loadResource (int type, const QUrl& url); @@ -62,14 +59,14 @@ void handle_index_clicked (const QUrl& url, const QString& keyword = QString ()); - void notice_settings (const gui_settings *settings); - void save_settings (gui_settings *settings); + void notice_settings (); + void save_settings (); //! Zooming in and out while taking care of the zoom level //!@{ - void zoom_in (void); - void zoom_out (void); - void zoom_original (void); + void zoom_in (); + void zoom_out (); + void zoom_original (); //!@} protected: @@ -87,10 +84,10 @@ //! zoom_in and zoom_out without actually zooming but //! with changing the stored zoom level enum - { - min_zoom_level = -5, - max_zoom_level = 10 - }; + { + min_zoom_level = -5, + max_zoom_level = 10 + }; }; //! The documentation main class derived from QSplitter @@ -101,17 +98,17 @@ public: - documentation (QWidget *parent, base_qobject& oct_qobj); - ~documentation (void); + documentation (QWidget *parent); + ~documentation (); /*! - Generate a string with page name @p title and current anchor - from @p url for using in prev/next or bookmarks menu: + Generate a string with page name @p title and current anchor + from @p url for using in prev/next or bookmarks menu: - @param title current title of the page as QString - @param url current url as QUrl + @param title current title of the page as QString + @param url current url as QUrl - @return QString "title: anchor" + @return QString "title: anchor" */ QString title_and_anchor (const QString& title, const QUrl& url); @@ -121,39 +118,39 @@ public slots: - void notice_settings (const gui_settings *settings); - void save_settings (void); + void notice_settings (); + void save_settings (); - void copyClipboard (void); - void pasteClipboard (void); - void selectAll (void); + void copyClipboard (); + void pasteClipboard (); + void selectAll (); - void load_index (void); + void load_index (); void load_ref (const QString& name = QString ()); void registerDoc (const QString& name); void unregisterDoc (const QString& name); private slots: - void activate_find (void); - void global_search (void); - void global_search_started (void); + void activate_find (); + void global_search (); + void global_search_started (); void global_search_finished (int hits); void filter_update (const QString& expression); - void filter_update_history (void); + void filter_update_history (); void find (bool backward = false); - void find_backward (void); + void find_backward (); void find_forward_from_anchor (const QString& text); - void record_anchor_position (void); - void handle_cursor_position_change (void); + void record_anchor_position (); + void handle_cursor_position_change (); void handle_search_result_clicked (const QUrl& url); - void update_history_menus (void); + void update_history_menus (); void open_hist_url (QAction *a); private: - void construct_tool_bar (void); + void construct_tool_bar (); QAction * add_action (const QIcon& icon, const QString& text, const char *member, QWidget *receiver = nullptr, QToolBar *tool_bar = nullptr); @@ -162,8 +159,6 @@ //! Select all occurrences of a string in the doc browser void select_all_occurrences (const QString& text); - base_qobject& m_octave_qobj; - QHelpEngine *m_help_engine; QString m_internal_search; documentation_browser *m_doc_browser; diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/dw-main-window.cc --- a/libgui/src/dw-main-window.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/dw-main-window.cc Fri May 12 08:03:14 2023 +0200 @@ -33,31 +33,31 @@ #endif #include +#include #include #include "dw-main-window.h" -#include "octave-qobject.h" -#include "shortcut-manager.h" #include "gui-preferences-sc.h" +#include "gui-settings.h" OCTAVE_BEGIN_NAMESPACE(octave) -dw_main_window::dw_main_window (base_qobject& oct_qobj, QWidget *p) -: QMainWindow (p), m_octave_qobj (oct_qobj) +dw_main_window::dw_main_window (QWidget *p) + : QMainWindow (p) { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); + gui_settings settings; // Adding the actions for closing the dock widgets m_close_action - = add_action (nullptr, rmgr.icon ("window-close", false), + = add_action (nullptr, settings.icon ("window-close", false), tr ("&Close"), SLOT (request_close ()), this); m_close_all_action - = add_action (nullptr, rmgr.icon ("window-close", false), + = add_action (nullptr, settings.icon ("window-close", false), tr ("Close &All"), SLOT (request_close_all ()), this); m_close_others_action - = add_action (nullptr, rmgr.icon ("window-close", false), + = add_action (nullptr, settings.icon ("window-close", false), tr ("Close &Other"), SLOT (request_close_other ()), this); m_switch_left_action @@ -75,7 +75,7 @@ m_actions_list << m_switch_left_action; m_actions_list << m_switch_right_action; - notice_settings (rmgr.get_settings ()); + notice_settings (); } // Re-implementing the popup menu of the main window @@ -127,16 +127,16 @@ } // Update the settings -void dw_main_window::notice_settings (const gui_settings *) +void dw_main_window::notice_settings () { - shortcut_manager& scmgr = m_octave_qobj.get_shortcut_manager (); + gui_settings settings; - scmgr.set_shortcut (m_close_action, sc_edit_file_close); - scmgr.set_shortcut (m_close_all_action, sc_edit_file_close_all); - scmgr.set_shortcut (m_close_others_action, sc_edit_file_close_other); + settings.set_shortcut (m_close_action, sc_edit_file_close); + settings.set_shortcut (m_close_all_action, sc_edit_file_close_all); + settings.set_shortcut (m_close_others_action, sc_edit_file_close_other); - scmgr.set_shortcut (m_switch_left_action, sc_edit_tabs_switch_left_tab); - scmgr.set_shortcut (m_switch_right_action, sc_edit_tabs_switch_right_tab); + settings.set_shortcut (m_switch_left_action, sc_edit_tabs_switch_left_tab); + settings.set_shortcut (m_switch_right_action, sc_edit_tabs_switch_right_tab); } // Slots for handling actions diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/dw-main-window.h --- a/libgui/src/dw-main-window.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/dw-main-window.h Fri May 12 08:03:14 2023 +0200 @@ -26,33 +26,27 @@ #if ! defined (octave_dw_main_window_h) #define octave_dw_main_window_h 1 +#include "octave-config.h" + #include -#include "gui-settings.h" - OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; - class dw_main_window : public QMainWindow { Q_OBJECT public: - dw_main_window (base_qobject& oct_qboj, QWidget *parent = nullptr); - - ~dw_main_window (void) = default; + dw_main_window (QWidget *parent = nullptr); - // No copying! + ~dw_main_window () = default; - dw_main_window (const dw_main_window&) = delete; - - dw_main_window& operator = (const dw_main_window&) = delete; + OCTAVE_DISABLE_COPY_MOVE (dw_main_window) public slots: - void notice_settings (const gui_settings *); + void notice_settings (); protected slots: @@ -76,8 +70,6 @@ QAction * add_action (QMenu *menu, const QIcon& icon, const QString& text, const char *member, QWidget *receiver); - base_qobject& m_octave_qobj; - QList m_dw_list; QAction *m_close_action; diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/external-editor-interface.cc --- a/libgui/src/external-editor-interface.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/external-editor-interface.cc Fri May 12 08:03:14 2023 +0200 @@ -29,17 +29,16 @@ #include #include +#include #include "external-editor-interface.h" #include "gui-settings.h" #include "gui-preferences-global.h" -#include "octave-qobject.h" OCTAVE_BEGIN_NAMESPACE(octave) -external_editor_interface::external_editor_interface (QWidget *p, - base_qobject& oct_qobj) -: QWidget (p), m_octave_qobj (oct_qobj) +external_editor_interface::external_editor_interface (QWidget *p) + : QWidget (p) { } // Calling the external editor @@ -57,7 +56,7 @@ editor.replace ("%f", file); editor.replace ("%l", QString::number (line)); - QStringList arguments = editor.split (QRegExp("\\s+")); + QStringList arguments = editor.split (QRegularExpression {"\\s+"}); editor = arguments.takeFirst (); // start the process and check for success @@ -100,12 +99,12 @@ } // Get and verify the settings of the external editor program -QString external_editor_interface::external_editor (void) +QString external_editor_interface::external_editor () { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - QString editor = settings->value (global_custom_editor.key, - global_custom_editor.def).toString (); + gui_settings settings; + + QString editor = settings.value (global_custom_editor.settings_key (), + global_custom_editor.def ()).toString (); // check the settings (avoid an empty string) if (editor.trimmed ().isEmpty ()) diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/external-editor-interface.h --- a/libgui/src/external-editor-interface.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/external-editor-interface.h Fri May 12 08:03:14 2023 +0200 @@ -31,17 +31,15 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; - class external_editor_interface : public QWidget { Q_OBJECT public: - external_editor_interface (QWidget *main_win, base_qobject& oct_qobj); + external_editor_interface (QWidget *main_win); - ~external_editor_interface (void) = default; + ~external_editor_interface () = default; signals: @@ -63,9 +61,7 @@ private: - QString external_editor (void); - - base_qobject& m_octave_qobj; + QString external_editor (); }; OCTAVE_END_NAMESPACE(octave) diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/files-dock-widget.cc --- a/libgui/src/files-dock-widget.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/files-dock-widget.cc Fri May 12 08:03:14 2023 +0200 @@ -49,8 +49,7 @@ #include "files-dock-widget.h" #include "gui-preferences-fb.h" #include "gui-preferences-global.h" -#include "octave-qobject.h" -#include "octave-qtutils.h" +#include "gui-settings.h" #include "qt-interpreter-events.h" #include "oct-env.h" @@ -63,7 +62,7 @@ FileTreeViewer (QWidget *p) : QTreeView (p) { } - ~FileTreeViewer (void) = default; + ~FileTreeViewer () = default; void mousePressEvent (QMouseEvent *e) { @@ -130,9 +129,9 @@ { const QString message = - files_dock_widget::tr ("Could not rename file \"%1\" to \"%2\".") - .arg (old_name) - .arg (new_name); + files_dock_widget::tr ("Could not rename file \"%1\" to \"%2\".") + .arg (old_name) + .arg (new_name); QMessageBox::information (static_cast (parent ()), QFileSystemModel::tr ("Invalid filename"), message, QMessageBox::Ok); @@ -145,7 +144,7 @@ { public: RenameItemDelegate (QObject *parent = nullptr) - : QStyledItemDelegate{ parent } + : QStyledItemDelegate{ parent } { } @@ -178,8 +177,8 @@ } }; -files_dock_widget::files_dock_widget (QWidget *p, base_qobject& oct_qobj) - : octave_dock_widget ("FilesDockWidget", p, oct_qobj) +files_dock_widget::files_dock_widget (QWidget *p) + : octave_dock_widget ("FilesDockWidget", p) { set_title (tr ("File Browser")); setToolTip (tr ("Browse your files")); @@ -194,18 +193,18 @@ m_columns_shown.append (tr ("Alternating row colors")); m_columns_shown_keys = QStringList (); - m_columns_shown_keys.append (fb_show_size.key); - m_columns_shown_keys.append (fb_show_type.key); - m_columns_shown_keys.append (fb_show_date.key); - m_columns_shown_keys.append (fb_show_hidden.key); - m_columns_shown_keys.append (fb_show_altcol.key); + m_columns_shown_keys.append (fb_show_size.settings_key ()); + m_columns_shown_keys.append (fb_show_type.settings_key ()); + m_columns_shown_keys.append (fb_show_date.settings_key ()); + m_columns_shown_keys.append (fb_show_hidden.settings_key ()); + m_columns_shown_keys.append (fb_show_altcol.settings_key ()); m_columns_shown_defs = QList (); - m_columns_shown_defs.append (fb_show_size.def); - m_columns_shown_defs.append (fb_show_type.def); - m_columns_shown_defs.append (fb_show_date.def); - m_columns_shown_defs.append (fb_show_hidden.def); - m_columns_shown_defs.append (fb_show_altcol.def); + m_columns_shown_defs.append (fb_show_size.def ()); + m_columns_shown_defs.append (fb_show_type.def ()); + m_columns_shown_defs.append (fb_show_date.def ()); + m_columns_shown_defs.append (fb_show_hidden.def ()); + m_columns_shown_defs.append (fb_show_altcol.def ()); QWidget *container = new QWidget (this); @@ -225,20 +224,21 @@ QSizePolicy sizePol (QSizePolicy::Expanding, QSizePolicy::Preferred); m_current_directory->setSizePolicy (sizePol); - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); + gui_settings settings; QAction *directory_up_action - = new QAction (rmgr.icon ("folder-up", false, "go-up"), "", m_navigation_tool_bar); + = new QAction (settings.icon ("folder-up", false, "go-up"), "", + m_navigation_tool_bar); directory_up_action->setToolTip (tr ("One directory up")); m_sync_browser_directory_action - = new QAction (rmgr.icon ("go-first"), tr ("Show Octave directory"), + = new QAction (settings.icon ("go-first"), tr ("Show Octave directory"), m_navigation_tool_bar); m_sync_browser_directory_action->setToolTip (tr ("Go to current Octave directory")); m_sync_browser_directory_action->setEnabled (false); m_sync_octave_directory_action - = new QAction (rmgr.icon ("go-last"), tr ("Set Octave directory"), + = new QAction (settings.icon ("go-last"), tr ("Set Octave directory"), m_navigation_tool_bar); m_sync_octave_directory_action->setToolTip (tr ("Set Octave directory to current browser directory")); m_sync_octave_directory_action->setEnabled (false); @@ -246,30 +246,31 @@ QToolButton *popdown_button = new QToolButton (); popdown_button->setToolTip (tr ("Actions on current directory")); QMenu *popdown_menu = new QMenu (); - popdown_menu->addAction (rmgr.icon ("user-home"), + popdown_menu->addAction (settings.icon ("user-home"), tr ("Show Home Directory"), this, SLOT (popdownmenu_home (bool))); popdown_menu->addAction (m_sync_browser_directory_action); popdown_menu->addAction (m_sync_octave_directory_action); popdown_button->setMenu (popdown_menu); popdown_button->setPopupMode (QToolButton::InstantPopup); - popdown_button->setDefaultAction ( - new QAction (rmgr.icon ("folder-settings", false, "applications-system"), - "", m_navigation_tool_bar)); + popdown_button->setDefaultAction + (new QAction (settings.icon ("folder-settings", false, + "applications-system"), + "", m_navigation_tool_bar)); popdown_menu->addSeparator (); - popdown_menu->addAction (rmgr.icon ("folder"), + popdown_menu->addAction (settings.icon ("folder"), tr ("Set Browser Directory..."), this, &files_dock_widget::popdownmenu_search_dir); popdown_menu->addSeparator (); - popdown_menu->addAction (rmgr.icon ("edit-find"), + popdown_menu->addAction (settings.icon ("edit-find"), tr ("Find Files..."), this, &files_dock_widget::popdownmenu_findfiles); popdown_menu->addSeparator (); - popdown_menu->addAction (rmgr.icon ("document-new"), + popdown_menu->addAction (settings.icon ("document-new"), tr ("New File..."), this, &files_dock_widget::popdownmenu_newfile); - popdown_menu->addAction (rmgr.icon ("folder-new"), + popdown_menu->addAction (settings.icon ("folder-new"), tr ("New Directory..."), this, &files_dock_widget::popdownmenu_newdir); @@ -284,24 +285,21 @@ connect (m_sync_browser_directory_action, &QAction::triggered, this, &files_dock_widget::do_sync_browser_directory); - gui_settings *settings = rmgr.get_settings (); - // FIXME: what should happen if settings is 0? - // Create the QFileSystemModel starting in the desired directory QDir startup_dir; // take current dir - if (settings->value (fb_restore_last_dir).toBool ()) + if (settings.bool_value (fb_restore_last_dir)) { // restore last dir from previous session QStringList last_dirs - = settings->value (fb_mru_list.key).toStringList (); + = settings.value (fb_mru_list.settings_key ()).toStringList (); if (last_dirs.length () > 0) startup_dir = QDir (last_dirs.at (0)); // last dir in previous session } - else if (! settings->value (fb_startup_dir).toString ().isEmpty ()) + else if (! settings.string_value (fb_startup_dir).isEmpty ()) { // do not restore but there is a startup dir configured - startup_dir = QDir (settings->value (fb_startup_dir.key).toString ()); + startup_dir = QDir (settings.value (fb_startup_dir.settings_key ()).toString ()); } if (! startup_dir.exists ()) @@ -312,8 +310,8 @@ m_file_system_model = new file_system_model (this); m_file_system_model->setResolveSymlinks (false); - m_file_system_model->setFilter ( - QDir::System | QDir::NoDotAndDotDot | QDir::AllEntries); + m_file_system_model->setFilter + (QDir::System | QDir::NoDotAndDotDot | QDir::AllEntries); QModelIndex rootPathIndex = m_file_system_model->setRootPath (startup_dir.absolutePath ()); @@ -348,14 +346,14 @@ // get sort column and order as well as column state (order and width) m_file_tree_view->sortByColumn - (settings->value (fb_sort_column).toInt (), - static_cast (settings->value (fb_sort_order).toUInt ())); - // FIXME: use value instead of static cast after - // dropping support of Qt 5.4 + (settings.int_value (fb_sort_column), + static_cast (settings.uint_value (fb_sort_order))); + // FIXME: use value instead of static cast after + // dropping support of Qt 5.4 - if (settings->contains (fb_column_state.key)) + if (settings.contains (fb_column_state.settings_key ())) m_file_tree_view->header ()->restoreState - (settings->value (fb_column_state.key).toByteArray ()); + (settings.value (fb_column_state.settings_key ()).toByteArray ()); // Set header properties for sorting m_file_tree_view->header ()->setSectionsClickable (true); @@ -363,7 +361,7 @@ m_file_tree_view->header ()->setSortIndicatorShown (true); QStringList mru_dirs = - settings->value (fb_mru_list.key).toStringList (); + settings.value (fb_mru_list.settings_key ()).toStringList (); m_current_directory->addItems (mru_dirs); m_current_directory->setEditText @@ -387,7 +385,7 @@ vbox_layout->setSpacing (0); vbox_layout->addWidget (m_navigation_tool_bar); vbox_layout->addWidget (m_file_tree_view); - vbox_layout->setMargin (1); + vbox_layout->setContentsMargins (1, 1, 1, 1); container->setLayout (vbox_layout); @@ -427,29 +425,25 @@ make_window (); } -void files_dock_widget::save_settings (void) +void files_dock_widget::save_settings () { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - - if (! settings) - return; + gui_settings settings; int sort_column = m_file_tree_view->header ()->sortIndicatorSection (); Qt::SortOrder sort_order = m_file_tree_view->header ()->sortIndicatorOrder (); - settings->setValue (fb_sort_column.key, sort_column); - settings->setValue (fb_sort_order.key, sort_order); - settings->setValue (fb_column_state.key, - m_file_tree_view->header ()->saveState ()); + settings.setValue (fb_sort_column.settings_key (), sort_column); + settings.setValue (fb_sort_order.settings_key (), sort_order); + settings.setValue (fb_column_state.settings_key (), + m_file_tree_view->header ()->saveState ()); QStringList dirs; for (int i=0; i< m_current_directory->count (); i++) { dirs.append (m_current_directory->itemText (i)); } - settings->setValue (fb_mru_list.key, dirs); + settings.setValue (fb_mru_list.settings_key (), dirs); - settings->sync (); + settings.sync (); octave_dock_widget::save_settings (); @@ -469,12 +463,12 @@ display_directory (dir); } -void files_dock_widget::accept_directory_line_edit (void) +void files_dock_widget::accept_directory_line_edit () { display_directory (m_current_directory->currentText ()); } -void files_dock_widget::change_directory_up (void) +void files_dock_widget::change_directory_up () { QDir dir = QDir (m_file_system_model->filePath (m_file_tree_view->rootIndex ())); @@ -483,7 +477,7 @@ display_directory (dir.absolutePath ()); } -void files_dock_widget::do_sync_octave_directory (void) +void files_dock_widget::do_sync_octave_directory () { QDir dir = QDir (m_file_system_model->filePath (m_file_tree_view->rootIndex ())); @@ -491,7 +485,7 @@ emit displayed_directory_changed (dir.absolutePath ()); } -void files_dock_widget::do_sync_browser_directory (void) +void files_dock_widget::do_sync_browser_directory () { display_directory (m_octave_dir, false); // false: no sync of octave dir } @@ -533,9 +527,10 @@ QString abs_fname = fileInfo.absoluteFilePath (); QString suffix = fileInfo.suffix ().toLower (); - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - QString ext = settings->value (fb_txt_file_ext).toString (); + + gui_settings settings; + + QString ext = settings.string_value (fb_txt_file_ext); #if defined (HAVE_QT_SPLITBEHAVIOR_ENUM) QStringList extensions = ext.split (";", Qt::SkipEmptyParts); #else @@ -564,13 +559,12 @@ void files_dock_widget::toggle_header (int col) { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); + gui_settings settings; QString key = m_columns_shown_keys.at (col); - bool shown = settings->value (key, false).toBool (); - settings->setValue (key, ! shown); - settings->sync (); + bool shown = settings.value (key, false).toBool (); + settings.setValue (key, ! shown); + settings.sync (); switch (col) { @@ -583,7 +577,7 @@ case 3: case 4: // other actions depending on new settings - notice_settings (settings); + notice_settings (); break; } } @@ -596,8 +590,7 @@ delete m_sig_mapper; m_sig_mapper = new QSignalMapper (this); - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); + gui_settings settings; for (int i = 0; i < m_columns_shown.size (); i++) { @@ -606,8 +599,8 @@ m_sig_mapper->setMapping (action, i); action->setCheckable (true); action->setChecked - (settings->value (m_columns_shown_keys.at (i), - m_columns_shown_defs.at (i)).toBool ()); + (settings.value (m_columns_shown_keys.at (i), + m_columns_shown_defs.at (i)).toBool ()); } // FIXME: We could use @@ -654,10 +647,10 @@ | QItemSelectionModel::Rows); } - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); + gui_settings settings; // construct the context menu depending on item - menu.addAction (rmgr.icon ("document-open"), tr ("Open"), + menu.addAction (settings.icon ("document-open"), tr ("Open"), this, &files_dock_widget::contextmenu_open); if (info.isDir ()) @@ -674,7 +667,7 @@ this, &files_dock_widget::contextmenu_copy_selection); if (info.isFile () && info.suffix () == "m") - menu.addAction (rmgr.icon ("media-playback-start"), tr ("Run"), + menu.addAction (settings.icon ("media-playback-start"), tr ("Run"), this, &files_dock_widget::contextmenu_run); if (info.isFile ()) @@ -684,7 +677,7 @@ if (info.isDir ()) { menu.addSeparator (); - menu.addAction (rmgr.icon ("go-first"), tr ("Set Current Directory"), + menu.addAction (settings.icon ("go-first"), tr ("Set Current Directory"), this, &files_dock_widget::contextmenu_setcurrentdir); QMenu *add_path_menu = menu.addMenu (tr ("Add to Path")); @@ -703,21 +696,21 @@ menu.addSeparator (); - menu.addAction (rmgr.icon ("edit-find"), tr ("Find Files..."), + menu.addAction (settings.icon ("edit-find"), tr ("Find Files..."), this, &files_dock_widget::contextmenu_findfiles); } menu.addSeparator (); menu.addAction (m_rename_action); - menu.addAction (rmgr.icon ("edit-delete"), tr ("Delete..."), + menu.addAction (settings.icon ("edit-delete"), tr ("Delete..."), this, &files_dock_widget::contextmenu_delete); if (info.isDir ()) { menu.addSeparator (); - menu.addAction (rmgr.icon ("document-new"), tr ("New File..."), + menu.addAction (settings.icon ("document-new"), tr ("New File..."), this, &files_dock_widget::contextmenu_newfile); - menu.addAction (rmgr.icon ("folder-new"), tr ("New Directory..."), + menu.addAction (settings.icon ("folder-new"), tr ("New Directory..."), this, &files_dock_widget::contextmenu_newdir); } @@ -733,9 +726,9 @@ QItemSelectionModel *m = m_file_tree_view->selectionModel (); QModelIndexList rows = m->selectedRows (); - for (auto it = rows.begin (); it != rows.end (); it++) + for (const auto& it : rows) { - QFileInfo file = m_file_system_model->fileInfo (*it); + QFileInfo file = m_file_system_model->fileInfo (it); if (file.exists ()) display_directory (file.absoluteFilePath ()); } @@ -747,9 +740,9 @@ QItemSelectionModel *m = m_file_tree_view->selectionModel (); QModelIndexList rows = m->selectedRows (); - for (auto it = rows.begin (); it != rows.end (); it++) + for (const auto& it : rows) { - QFileInfo file = m_file_system_model->fileInfo (*it); + QFileInfo file = m_file_system_model->fileInfo (it); if (file.exists ()) emit open_file (file.absoluteFilePath ()); } @@ -760,8 +753,8 @@ QItemSelectionModel *m = m_file_tree_view->selectionModel (); QModelIndexList rows = m->selectedRows (); - for (auto it = rows.begin (); it != rows.end (); it++) - open_item_in_app (*it); + for (const auto& it : rows) + open_item_in_app (it); } void files_dock_widget::contextmenu_copy_selection (bool) @@ -771,10 +764,9 @@ QStringList selection; - for (auto it = rows.begin (); it != rows.end (); it++) + for (const auto& it : rows) { - QFileInfo info = m_file_system_model->fileInfo (*it); - + QFileInfo info = m_file_system_model->fileInfo (it); selection << info.fileName (); } @@ -853,10 +845,10 @@ else { dlg_answer = QMessageBox::question (this, - tr ("Delete file/directory"), - tr ("Are you sure you want to delete\n") - + info.filePath (), - QMessageBox::Yes | QMessageBox::No); + tr ("Delete file/directory"), + tr ("Are you sure you want to delete\n") + + info.filePath (), + QMessageBox::Yes | QMessageBox::No); } if (dlg_answer == QMessageBox::Yes) @@ -865,9 +857,9 @@ { // see if directory is empty QDir path (info.absoluteFilePath ()); - QList fileLst = path.entryInfoList ( - QDir::Hidden | QDir::AllEntries | - QDir::NoDotAndDotDot | QDir::System); + QList fileLst + = path.entryInfoList (QDir::Hidden | QDir::AllEntries + | QDir::NoDotAndDotDot | QDir::System); if (fileLst.count () != 0) QMessageBox::warning (this, tr ("Delete file/directory"), @@ -906,11 +898,9 @@ QList infos; - for (auto it = rows.begin (); it != rows.end (); it++) + for (const auto& idx : rows) { - QModelIndex index = *it; - - QFileInfo info = m_file_system_model->fileInfo (index); + QFileInfo info = m_file_system_model->fileInfo (idx); if (info.exists () && ((dir & info.isDir ()) || (! dir && info.isFile ()))) @@ -1006,11 +996,13 @@ } } -void files_dock_widget::notice_settings (const gui_settings *settings) +void files_dock_widget::notice_settings () { + gui_settings settings; + // QSettings pointer is checked before emitting. - int size_idx = settings->value (global_icon_size).toInt (); + int size_idx = settings.int_value (global_icon_size); size_idx = (size_idx > 0) - (size_idx < 0) + 1; // Make valid index from 0 to 2 QStyle *st = style (); @@ -1020,22 +1012,22 @@ // filenames are always shown, other columns can be hidden by settings for (int i = 0; i < 3; i++) m_file_tree_view->setColumnHidden (i + 1, - ! settings->value (m_columns_shown_keys.at (i),false).toBool ()); + ! settings.value (m_columns_shown_keys.at (i),false).toBool ()); QDir::Filters current_filter = m_file_system_model->filter (); - if (settings->value (m_columns_shown_keys.at (3), false).toBool ()) + if (settings.value (m_columns_shown_keys.at (3), false).toBool ()) m_file_system_model->setFilter (current_filter | QDir::Hidden); else m_file_system_model->setFilter (current_filter & (~QDir::Hidden)); m_file_tree_view->setAlternatingRowColors - (settings->value (m_columns_shown_keys.at (4),true).toBool ()); + (settings.value (m_columns_shown_keys.at (4),true).toBool ()); m_file_tree_view->setModel (m_file_system_model); // enable the buttons to sync octave/browser dir // only if this is not done by default m_sync_octave_dir - = settings->value (fb_sync_octdir).toBool (); + = settings.bool_value (fb_sync_octdir); m_sync_octave_directory_action->setEnabled (! m_sync_octave_dir); m_sync_browser_directory_action->setEnabled (! m_sync_octave_dir); @@ -1063,15 +1055,16 @@ { // FIXME: Remove, if for all common KDE versions (bug #54607) is resolved. int opts = QFileDialog::ShowDirsOnly; - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - if (! settings->value (global_use_native_dialogs).toBool ()) + + gui_settings settings; + + if (! settings.bool_value (global_use_native_dialogs)) opts |= QFileDialog::DontUseNativeDialog; QString dir = QFileDialog::getExistingDirectory (this, - tr ("Set directory of file browser"), - m_file_system_model->rootPath (), - QFileDialog::Option (opts)); + tr ("Set directory of file browser"), + m_file_system_model->rootPath (), + QFileDialog::Option (opts)); set_current_directory (dir); } diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/files-dock-widget.h --- a/libgui/src/files-dock-widget.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/files-dock-widget.h Fri May 12 08:03:14 2023 +0200 @@ -46,8 +46,6 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; - //! Dock widget to display files in the current directory. class files_dock_widget : public octave_dock_widget @@ -56,9 +54,9 @@ public: - files_dock_widget (QWidget *parent, base_qobject& oct_qobj); + files_dock_widget (QWidget *parent); - ~files_dock_widget (void) = default; + ~files_dock_widget () = default; signals: @@ -107,15 +105,15 @@ //! Slot for handling the up-directory button in the toolbar. - void change_directory_up (void); + void change_directory_up (); //! Slot for handling the sync octave directory button in the toolbar. - void do_sync_octave_directory (void); + void do_sync_octave_directory (); //! Slot for handling the sync browser directory button in the toolbar. - void do_sync_browser_directory (void); + void do_sync_browser_directory (); //! Sets the current directory being displayed. @@ -123,7 +121,7 @@ //! Accepts user input a the line edit for the current directory. - void accept_directory_line_edit (void); + void accept_directory_line_edit (); //! Set the internal variable that holds the actual octave variable. @@ -131,9 +129,9 @@ //! Tells the widget to react on changed settings. - void notice_settings (const gui_settings *settings); + void notice_settings (); - void save_settings (void); + void save_settings (); private slots: diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/find-files-dialog.cc --- a/libgui/src/find-files-dialog.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/find-files-dialog.cc Fri May 12 08:03:14 2023 +0200 @@ -49,17 +49,17 @@ #include "find-files-model.h" #include "gui-preferences-global.h" #include "gui-preferences-ff.h" -#include "octave-qobject.h" +#include "gui-settings.h" OCTAVE_BEGIN_NAMESPACE(octave) -find_files_dialog::find_files_dialog (QWidget *p, base_qobject& oct_qobj) -: QDialog (p), m_octave_qobj (oct_qobj) +find_files_dialog::find_files_dialog (QWidget *p) + : QDialog (p) { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); + gui_settings settings; setWindowTitle (tr ("Find Files")); - setWindowIcon (rmgr.icon ("edit-find")); + setWindowIcon (settings.icon ("edit-find")); m_dir_iterator = nullptr; @@ -67,20 +67,18 @@ connect (m_timer, &QTimer::timeout, this, &find_files_dialog::look_for_files); - gui_settings *settings = rmgr.get_settings (); - QLabel *file_name_label = new QLabel (tr ("Named:")); m_file_name_edit = new QLineEdit; m_file_name_edit->setToolTip (tr ("Enter the filename search expression")); - m_file_name_edit->setText (settings->value (ff_file_name).toString ()); + m_file_name_edit->setText (settings.string_value (ff_file_name)); file_name_label->setBuddy (m_file_name_edit); QLabel *start_dir_label = new QLabel (tr ("Start in:")); m_start_dir_edit = new QLineEdit; - m_start_dir_edit->setText (settings->value (ff_start_dir.key, - QDir::currentPath ()).toString ()); + m_start_dir_edit->setText (settings.value (ff_start_dir.settings_key (), + QDir::currentPath ()).toString ()); m_start_dir_edit->setToolTip (tr ("Enter the start directory")); start_dir_label->setBuddy (m_start_dir_edit); @@ -90,27 +88,27 @@ this, &find_files_dialog::browse_folders); m_recurse_dirs_check = new QCheckBox (tr ("Search subdirectories")); - m_recurse_dirs_check->setChecked (settings->value (ff_recurse_dirs).toBool ()); + m_recurse_dirs_check->setChecked (settings.bool_value (ff_recurse_dirs)); m_recurse_dirs_check->setToolTip (tr ("Search recursively through directories for matching files")); m_include_dirs_check = new QCheckBox (tr ("Include directory names")); - m_include_dirs_check->setChecked (settings->value (ff_include_dirs).toBool ()); + m_include_dirs_check->setChecked (settings.bool_value (ff_include_dirs)); m_include_dirs_check->setToolTip (tr ("Include matching directories in search results")); m_name_case_check = new QCheckBox (tr ("Name case insensitive")); - m_name_case_check->setChecked (settings->value (ff_name_case).toBool ()); + m_name_case_check->setChecked (settings.bool_value (ff_name_case)); m_name_case_check->setToolTip (tr ("Set matching name is case insensitive")); m_contains_text_check = new QCheckBox (tr ("Contains text:")); m_contains_text_check->setToolTip (tr ("Enter the file content search expression")); - m_contains_text_check->setChecked (settings->value (ff_check_text).toBool ()); + m_contains_text_check->setChecked (settings.bool_value (ff_check_text)); m_contains_text_edit = new QLineEdit (); m_contains_text_edit->setToolTip (tr ("Text to match")); - m_contains_text_edit->setText (settings->value (ff_contains_text).toString ()); + m_contains_text_edit->setText (settings.string_value (ff_contains_text)); m_content_case_check = new QCheckBox (tr ("Text case insensitive")); - m_content_case_check->setChecked (settings->value (ff_content_case).toBool ()); + m_content_case_check->setChecked (settings.bool_value (ff_content_case)); m_content_case_check->setToolTip (tr ("Set text content is case insensitive")); find_files_model *model = new find_files_model (this); @@ -124,15 +122,15 @@ m_file_list->setAlternatingRowColors (true); m_file_list->setToolTip (tr ("Search results")); m_file_list->setSortingEnabled (true); - m_file_list->horizontalHeader ()->restoreState (settings->value (ff_column_state.key).toByteArray ()); + m_file_list->horizontalHeader ()->restoreState (settings.value (ff_column_state.settings_key ()).toByteArray ()); m_file_list->horizontalHeader ()->setSortIndicatorShown (true); m_file_list->horizontalHeader ()->setSectionsClickable (true); m_file_list->horizontalHeader ()->setStretchLastSection (true); - m_file_list->sortByColumn (settings->value (ff_sort_files_by_column).toInt (), + m_file_list->sortByColumn (settings.int_value (ff_sort_files_by_column), static_cast - (settings->value (ff_sort_files_by_order).toUInt ())); - // FIXME: use value instead of static cast after - // dropping support of Qt 5.4 + (settings.uint_value (ff_sort_files_by_order))); + // FIXME: use value instead of static cast after + // dropping support of Qt 5.4 connect (m_file_list, &QTableView::doubleClicked, this, &find_files_dialog::item_double_clicked); @@ -202,39 +200,35 @@ this, &find_files_dialog::handle_done); } -find_files_dialog::~find_files_dialog (void) +find_files_dialog::~find_files_dialog () { delete m_dir_iterator; } -void find_files_dialog::save_settings (void) +void find_files_dialog::save_settings () { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - - if (! settings) - return; + gui_settings settings; int sort_column = m_file_list->horizontalHeader ()->sortIndicatorSection (); Qt::SortOrder sort_order = m_file_list->horizontalHeader ()->sortIndicatorOrder (); - settings->setValue (ff_sort_files_by_column.key, sort_column); - settings->setValue (ff_sort_files_by_order.key, sort_order); - settings->setValue (ff_column_state.key, m_file_list->horizontalHeader ()->saveState ()); + settings.setValue (ff_sort_files_by_column.settings_key (), sort_column); + settings.setValue (ff_sort_files_by_order.settings_key (), sort_order); + settings.setValue (ff_column_state.settings_key (), m_file_list->horizontalHeader ()->saveState ()); - settings->setValue (ff_file_name.key, m_file_name_edit->text ()); + settings.setValue (ff_file_name.settings_key (), m_file_name_edit->text ()); - settings->setValue (ff_start_dir.key, m_start_dir_edit->text ()); + settings.setValue (ff_start_dir.settings_key (), m_start_dir_edit->text ()); - settings->setValue (ff_recurse_dirs.key, m_recurse_dirs_check->text ()); - settings->setValue (ff_include_dirs.key, m_include_dirs_check->text ()); - settings->setValue (ff_name_case.key, m_name_case_check->text ()); + settings.setValue (ff_recurse_dirs.settings_key (), m_recurse_dirs_check->text ()); + settings.setValue (ff_include_dirs.settings_key (), m_include_dirs_check->text ()); + settings.setValue (ff_name_case.settings_key (), m_name_case_check->text ()); - settings->setValue (ff_contains_text.key, m_contains_text_edit->text ()); - settings->setValue (ff_check_text.key, m_contains_text_check->isChecked ()); - settings->setValue (ff_content_case.key, m_content_case_check->isChecked ()); + settings.setValue (ff_contains_text.settings_key (), m_contains_text_edit->text ()); + settings.setValue (ff_check_text.settings_key (), m_contains_text_check->isChecked ()); + settings.setValue (ff_content_case.settings_key (), m_content_case_check->isChecked ()); - settings->sync (); + settings.sync (); } void find_files_dialog::set_search_dir (const QString& dir) @@ -243,7 +237,7 @@ m_start_dir_edit->setText (dir); } -void find_files_dialog::start_find (void) +void find_files_dialog::start_find () { stop_find (); @@ -285,7 +279,7 @@ m_timer->start (0); } -void find_files_dialog::stop_find (void) +void find_files_dialog::stop_find () { m_timer->stop (); @@ -308,13 +302,15 @@ m_status_bar->showMessage (res_str); } -void find_files_dialog::browse_folders (void) +void find_files_dialog::browse_folders () { int opts = 0; // No options by default. + // FIXME: Remove, if for all common KDE versions (bug #54607) is resolved. - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - if (! settings->value (global_use_native_dialogs).toBool ()) + + gui_settings settings; + + if (! settings.bool_value (global_use_native_dialogs)) opts = QFileDialog::DontUseNativeDialog; QString dir = @@ -347,7 +343,7 @@ } } -void find_files_dialog::look_for_files (void) +void find_files_dialog::look_for_files () { if (m_dir_iterator && m_dir_iterator->hasNext ()) { @@ -395,8 +391,8 @@ QString match_str = m_contains_text_edit->text (); Qt::CaseSensitivity cs = m_content_case_check->isChecked () - ? Qt::CaseInsensitive - : Qt::CaseSensitive; + ? Qt::CaseInsensitive + : Qt::CaseSensitive; do { diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/find-files-dialog.h --- a/libgui/src/find-files-dialog.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/find-files-dialog.h Fri May 12 08:03:14 2023 +0200 @@ -39,19 +39,17 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; - class find_files_dialog : public QDialog { Q_OBJECT public: - find_files_dialog (QWidget *parent, base_qobject& oct_qobj); + find_files_dialog (QWidget *parent); - virtual ~find_files_dialog (void); + virtual ~find_files_dialog (); - void save_settings (void); + void save_settings (); signals: @@ -64,10 +62,10 @@ private slots: - void start_find (void); - void stop_find (void); - void browse_folders (void); - void look_for_files (void); + void start_find (); + void stop_find (); + void browse_folders (); + void look_for_files (); void item_double_clicked (const QModelIndex&); void handle_done (int); @@ -75,8 +73,6 @@ bool is_match (const QFileInfo& info); - base_qobject& m_octave_qobj; - QLineEdit *m_start_dir_edit; QLineEdit *m_file_name_edit; QPushButton *m_stop_button; diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/find-files-model.cc --- a/libgui/src/find-files-model.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/find-files-model.cc Fri May 12 08:03:14 2023 +0200 @@ -95,7 +95,7 @@ m_sortorder = 0; } -void find_files_model::clear (void) +void find_files_model::clear () { beginResetModel (); @@ -111,6 +111,9 @@ QList::Iterator it; find_file_less_than less_than (m_sortorder); + // FIXME: This loop is trying to insert info in a sorted QList. + // Is there a library function or data structure + // that can do this without a loop? for (it = m_files.begin (); it != m_files.end (); it++) { if (less_than (info, *it)) diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/find-files-model.h --- a/libgui/src/find-files-model.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/find-files-model.h Fri May 12 08:03:14 2023 +0200 @@ -41,9 +41,9 @@ find_files_model (QObject *p = nullptr); - ~find_files_model (void) = default; + ~find_files_model () = default; - void clear (void); + void clear (); void addFile (const QFileInfo& info); diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/graphics-init.cc --- a/libgui/src/graphics-init.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/graphics-init.cc Fri May 12 08:03:14 2023 +0200 @@ -32,7 +32,6 @@ #include #include "graphics-init.h" -#include "octave-qobject.h" #include "qt-graphics-toolkit.h" #include "QtHandlesUtils.h" @@ -42,10 +41,8 @@ OCTAVE_BEGIN_NAMESPACE(octave) -void graphics_init (interpreter& interp, base_qobject& oct_qobj) +void graphics_init (interpreter& interp) { -#if defined (HAVE_QT_GRAPHICS) - gh_manager& gh_mgr = interp.get_gh_manager (); autolock guard (gh_mgr.graphics_lock ()); @@ -54,7 +51,7 @@ gh_mgr.enable_event_processing (true); - qt_graphics_toolkit *qt_gtk = new qt_graphics_toolkit (interp, oct_qobj); + qt_graphics_toolkit *qt_gtk = new qt_graphics_toolkit (interp); if (QThread::currentThread () != QApplication::instance ()->thread ()) @@ -67,13 +64,6 @@ gtk_mgr.register_toolkit ("qt"); gtk_mgr.load_toolkit (tk); - -#else - - octave_unused_parameter (interp); - octave_unused_parameter (oct_qobj); - -#endif } OCTAVE_END_NAMESPACE(octave) diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/graphics-init.h --- a/libgui/src/graphics-init.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/graphics-init.h Fri May 12 08:03:14 2023 +0200 @@ -33,9 +33,8 @@ OCTAVE_BEGIN_NAMESPACE(octave) class interpreter; -class base_qobject; -extern void graphics_init (interpreter& interp, base_qobject& oct_qobj); +extern void graphics_init (interpreter& interp); OCTAVE_END_NAMESPACE(octave) diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/gui-preferences-cs.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/gui-preferences-cs.cc Fri May 12 08:03:14 2023 +0200 @@ -0,0 +1,74 @@ +//////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2017-2023 The Octave Project Developers +// +// See the file COPYRIGHT.md in the top-level directory of this +// distribution or . +// +// 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 +// . +// +//////////////////////////////////////////////////////////////////////// + +#if defined (HAVE_CONFIG_H) +# include "config.h" +#endif + +#include + +#include "gui-preferences-cs.h" +#include "gui-settings.h" + +// Console preferences + +gui_pref +cs_font ("terminal/fontName", QVariant ()); + +gui_pref +cs_font_size ("terminal/fontSize", QVariant (10)); + +gui_pref +cs_cursor ("terminal/cursorType", QVariant ("ibeam")); + +gui_pref +cs_cursor_blinking ("terminal/cursorBlinking", QVariant (true)); + +gui_pref +cs_cursor_use_fgcol ("terminal/cursorUseForegroundColor", QVariant (true)); + +gui_pref +cs_hist_buffer ("terminal/history_buffer", QVariant (1000)); + +gui_pref +cs_color_mode ("terminal/color_mode", QVariant (0)); + +gui_pref cs_colors[2*cs_colors_count] = +{ + {"terminal/color_f" + settings_color_modes_ext[0], QVariant (QPalette::WindowText)}, + {"terminal/color_b" + settings_color_modes_ext[0], QVariant (QPalette::Base)}, + {"terminal/color_s" + settings_color_modes_ext[0], QVariant (QPalette::Highlight)}, + {"terminal/color_c" + settings_color_modes_ext[0], QVariant (QPalette::QPalette::WindowText)}, + {"terminal/color_f" + settings_color_modes_ext[1], QVariant ()}, // Default colors for 2nd mode empty, + {"terminal/color_b" + settings_color_modes_ext[1], QVariant ()}, // since they are determined at runtime + {"terminal/color_s" + settings_color_modes_ext[1], QVariant ()}, // by inverting the lightness of the + {"terminal/color_c" + settings_color_modes_ext[1], QVariant ()} // default colors in light mode +}; + +gui_pref +cs_focus_cmd ("terminal/focus_after_command", QVariant (false)); + +gui_pref +cs_dbg_location ("terminal/print_debug_location", QVariant (false)); diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/gui-preferences-cs.h --- a/libgui/src/gui-preferences-cs.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/gui-preferences-cs.h Fri May 12 08:03:14 2023 +0200 @@ -27,15 +27,12 @@ #define octave_gui_preferences_cs_h 1 #include "gui-preferences.h" -#include "gui-settings.h" // Console preferences -const gui_pref -cs_font ("terminal/fontName", QVariant ()); +extern gui_pref cs_font; -const gui_pref -cs_font_size ("terminal/fontSize", QVariant (10)); +extern gui_pref cs_font_size; const std::vector cs_cursor_types = { @@ -44,33 +41,20 @@ "underline" }; -const gui_pref -cs_cursor ("terminal/cursorType", QVariant ("ibeam")); +extern gui_pref cs_cursor; -const gui_pref -cs_cursor_blinking ("terminal/cursorBlinking", QVariant (true)); +extern gui_pref cs_cursor_blinking; -const gui_pref -cs_cursor_use_fgcol ("terminal/cursorUseForegroundColor", QVariant (true)); +extern gui_pref cs_cursor_use_fgcol; -const gui_pref -cs_hist_buffer ("terminal/history_buffer", QVariant (1000)); +extern gui_pref cs_hist_buffer; -const gui_pref -cs_color_mode ("terminal/color_mode", QVariant (0)); +extern gui_pref cs_color_mode; const unsigned int cs_colors_count = 4; -const gui_pref cs_colors[2*cs_colors_count] = -{ - {"terminal/color_f" + settings_color_modes_ext[0], QVariant (QPalette::WindowText)}, - {"terminal/color_b" + settings_color_modes_ext[0], QVariant (QPalette::Base)}, - {"terminal/color_s" + settings_color_modes_ext[0], QVariant (QPalette::Highlight)}, - {"terminal/color_c" + settings_color_modes_ext[0], QVariant (QPalette::QPalette::WindowText)}, - {"terminal/color_f" + settings_color_modes_ext[1], QVariant ()}, // Default colors for 2nd mode empty, - {"terminal/color_b" + settings_color_modes_ext[1], QVariant ()}, // since they are determined at runtime - {"terminal/color_s" + settings_color_modes_ext[1], QVariant ()}, // by inverting the lightness of the - {"terminal/color_c" + settings_color_modes_ext[1], QVariant ()} // default colors in light mode -}; + +extern gui_pref cs_colors[]; + const QStringList cs_color_names = { QT_TRANSLATE_NOOP ("octave::settings_dialog", "foreground"), @@ -79,10 +63,8 @@ QT_TRANSLATE_NOOP ("octave::settings_dialog", "cursor") }; -const gui_pref -cs_focus_cmd ("terminal/focus_after_command", QVariant (false)); +extern gui_pref cs_focus_cmd; -const gui_pref -cs_dbg_location ("terminal/print_debug_location", QVariant (false)); +extern gui_pref cs_dbg_location; #endif diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/gui-preferences-dc.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/gui-preferences-dc.cc Fri May 12 08:03:14 2023 +0200 @@ -0,0 +1,45 @@ +//////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2017-2023 The Octave Project Developers +// +// See the file COPYRIGHT.md in the top-level directory of this +// distribution or . +// +// 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 +// . +// +//////////////////////////////////////////////////////////////////////// + +#if defined (HAVE_CONFIG_H) +# include "config.h" +#endif + +#include "gui-preferences-dc.h" + +// documentation properties + +gui_pref +dc_bookmark_filter_active ("documentation_widget/filter_active", QVariant (false)); + +gui_pref +dc_bookmark_filter_shown ("documentation_widget/filter_shown", QVariant (true)); + +gui_pref +dc_bookmark_filter_mru ("documentation_widget/bookmark_filter_mru", QVariant ()); + +// Zoom level +gui_pref +dc_browser_zoom_level ("documentation_widget/browser_zoom_level", QVariant (0)); diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/gui-preferences-dc.h --- a/libgui/src/gui-preferences-dc.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/gui-preferences-dc.h Fri May 12 08:03:14 2023 +0200 @@ -32,14 +32,12 @@ const QString dc_bookmark_file ("octave-doc-bookmarks.xbel"); -const gui_pref -dc_bookmark_filter_active ("documentation_widget/filter_active", QVariant (false)); + +extern gui_pref dc_bookmark_filter_active; -const gui_pref -dc_bookmark_filter_shown ("documentation_widget/filter_shown", QVariant (true)); +extern gui_pref dc_bookmark_filter_shown; -const gui_pref -dc_bookmark_filter_mru ("documentation_widget/bookmark_filter_mru", QVariant ()); +extern gui_pref dc_bookmark_filter_mru; // Constants for the xbel file format const QLatin1String dc_xbel_doctype (""); @@ -55,7 +53,6 @@ const QLatin1String dc_xbel_name_format ("xbel"); // Zoom level -const gui_pref -dc_browser_zoom_level ("documentation_widget/browser_zoom_level", QVariant (0)); +extern gui_pref dc_browser_zoom_level; #endif diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/gui-preferences-dw.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/gui-preferences-dw.cc Fri May 12 08:03:14 2023 +0200 @@ -0,0 +1,69 @@ +//////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2017-2023 The Octave Project Developers +// +// See the file COPYRIGHT.md in the top-level directory of this +// distribution or . +// +// 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 +// . +// +//////////////////////////////////////////////////////////////////////// + +#if defined (HAVE_CONFIG_H) +# include "config.h" +#endif + +#include +#include + +#include "gui-preferences-dw.h" + +gui_pref +dw_focus_follows_mouse ("DockWidgets/focus_follows_mouse", QVariant (false)); + +gui_pref +dw_title_custom_style ("DockWidgets/widget_title_custom_style", + QVariant (true)); + +gui_pref dw_title_3d ("DockWidgets/widget_title_3d", QVariant (20)); + +gui_pref dw_title_fg_color ("DockWidgets/title_fg_color", + QVariant (QColor (0, 0, 0))); + +gui_pref dw_title_fg_color_active ("DockWidgets/title_fg_color_active", + QVariant (QColor (255, 255, 255))); + +gui_pref dw_title_bg_color ("DockWidgets/title_bg_color", + QVariant (QColor (192, 192, 192))); + +gui_pref dw_title_bg_color_active ("DockWidgets/title_bg_color_active", + QVariant (QColor (128, 128, 128))); + +gui_pref dw_icon_set ("DockWidgets/widget_icon_set", QVariant ("NONE")); + +// The following keys have to be used with .arg (objectName ()) +gui_pref dw_float_geometry ("DockWidgets/%1_floating_geometry", + QVariant (QRect (50, 50, 480, 640))); + +gui_pref dw_dock_geometry ("DockWidgets/%1", + QVariant (QRect (10, 10, 240, 320))); + +gui_pref dw_is_visible ("DockWidgets/%1Visible", QVariant (true)); + +gui_pref dw_is_floating ("DockWidgets/%1Floating", QVariant (false)); + +gui_pref dw_is_minimized ("DockWidgets/%1_minimized", QVariant (false)); diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/gui-preferences-dw.h --- a/libgui/src/gui-preferences-dw.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/gui-preferences-dw.h Fri May 12 08:03:14 2023 +0200 @@ -28,28 +28,21 @@ #include "gui-preferences.h" -const gui_pref -dw_focus_follows_mouse ("DockWidgets/focus_follows_mouse", QVariant (false)); +extern gui_pref dw_focus_follows_mouse; + +extern gui_pref dw_title_custom_style; -const gui_pref -dw_title_custom_style ("DockWidgets/widget_title_custom_style", - QVariant (true)); +extern gui_pref dw_title_3d; -const gui_pref dw_title_3d ("DockWidgets/widget_title_3d", QVariant (20)); +extern gui_pref dw_title_fg_color; -const gui_pref dw_title_fg_color ("DockWidgets/title_fg_color", - QVariant (QColor (0, 0, 0))); +extern gui_pref dw_title_fg_color_active; -const gui_pref dw_title_fg_color_active ("DockWidgets/title_fg_color_active", - QVariant (QColor (255, 255, 255))); +extern gui_pref dw_title_bg_color; -const gui_pref dw_title_bg_color ("DockWidgets/title_bg_color", - QVariant (QColor (192, 192, 192))); +extern gui_pref dw_title_bg_color_active; -const gui_pref dw_title_bg_color_active ("DockWidgets/title_bg_color_active", - QVariant (QColor (128, 128, 128))); - -const gui_pref dw_icon_set ("DockWidgets/widget_icon_set", QVariant ("NONE")); +extern gui_pref dw_icon_set; const QHash dw_icon_set_names = { @@ -61,16 +54,14 @@ }; // The following keys have to be used with .arg (objectName ()) -const gui_pref dw_float_geometry ("DockWidgets/%1_floating_geometry", - QVariant (QRect (50, 50, 480, 640))); +extern gui_pref dw_float_geometry; -const gui_pref dw_dock_geometry ("DockWidgets/%1", - QVariant (QRect (10, 10, 240, 320))); +extern gui_pref dw_dock_geometry; -const gui_pref dw_is_visible ("DockWidgets/%1Visible", QVariant (true)); +extern gui_pref dw_is_visible; -const gui_pref dw_is_floating ("DockWidgets/%1Floating", QVariant (false)); +extern gui_pref dw_is_floating; -const gui_pref dw_is_minimized ("DockWidgets/%1_minimized", QVariant (false)); +extern gui_pref dw_is_minimized; #endif diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/gui-preferences-ed.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/gui-preferences-ed.cc Fri May 12 08:03:14 2023 +0200 @@ -0,0 +1,255 @@ +//////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2017-2023 The Octave Project Developers +// +// See the file COPYRIGHT.md in the top-level directory of this +// distribution or . +// +// 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 +// . +// +//////////////////////////////////////////////////////////////////////// + +#if defined (HAVE_CONFIG_H) +# include "config.h" +#endif + +#if defined (HAVE_QSCINTILLA) +#include +#endif + +#include "gui-preferences-ed.h" +#include "gui-settings.h" +#include "localcharset-wrapper.h" + +// Editor preferences + +// Lexer + +gui_pref +ed_color_mode ("editor/color_mode", QVariant (0)); + +// Code completion + +gui_pref +ed_code_completion_octave_builtins ("editor/codeCompletion_octave_builtins", + QVariant (true)); + +gui_pref +ed_code_completion_octave_functions ("editor/codeCompletion_octave_functions", + QVariant (true)); + +gui_pref +ed_code_completion_keywords ("editor/codeCompletion_keywords", QVariant (true)); + +gui_pref +ed_code_completion_document ("editor/codeCompletion_document", QVariant (true)); + +gui_pref +ed_code_completion_replace ("editor/codeCompletion_replace", QVariant (false)); + +gui_pref +ed_code_completion_case ("editor/codeCompletion_case", QVariant (true)); + +gui_pref +ed_code_completion ("editor/codeCompletion", QVariant (true)); + +gui_pref +ed_code_completion_threshold ("editor/codeCompletion_threshold", QVariant (3)); + +// Code formatting + +gui_pref +ed_code_folding ("editor/code_folding", QVariant (true)); + +gui_pref +ed_auto_indent ("editor/auto_indent", QVariant (true)); + +gui_pref +ed_tab_indents_line ("editor/tab_indents_line", QVariant (false)); + +gui_pref +ed_backspace_unindents_line ("editor/backspace_unindents_line", + QVariant (false)); + +gui_pref +ed_show_indent_guides ("editor/show_indent_guides", QVariant (false)); + +gui_pref +ed_indent_uses_tabs ("editor/indent_uses_tabs", QVariant (false)); + +gui_pref +ed_indent_width ("editor/indent_width", QVariant (2)); + +gui_pref +ed_tab_width ("editor/tab_width", QVariant (2)); + +gui_pref +ed_auto_endif ("editor/auto_endif", QVariant (1)); + +// Long line handling + +gui_pref +ed_long_line_column ("editor/long_line_column", QVariant (80)); + +gui_pref +ed_long_line_marker ("editor/long_line_marker", QVariant (true)); + +gui_pref +ed_long_line_marker_line ("editor/long_line_marker_line", QVariant (true)); + +gui_pref +ed_long_line_marker_background ("editor/long_line_marker_background", + QVariant (false)); + +gui_pref +ed_wrap_lines ("editor/wrap_lines", QVariant (false)); + +gui_pref +ed_break_lines ("editor/break_lines", QVariant (false)); + +gui_pref +ed_break_lines_comments ("editor/break_lines_comments", QVariant (false)); + +// Other + +gui_pref +ed_highlight_all_occurrences ("editor/highlight_all_occurrences", + QVariant (true)); + +gui_pref +ed_show_Line_numbers ("editor/showLineNumbers", QVariant (true)); + +gui_pref +ed_line_numbers_size ("editor/line_numbers_size", QVariant ( 0)); + +gui_pref +ed_show_edit_status_bar ("editor/show_edit_status_bar", QVariant (true)); + +gui_pref +ed_highlight_current_line ("editor/highlightCurrentLine", QVariant (true)); + +gui_pref +ed_highlight_current_line_color ("editor/highlightCurrentLineColor", + QVariant (settings_color_no_change)); + +gui_pref +ed_show_white_space ("editor/show_white_space", QVariant (false)); + +gui_pref +ed_show_white_space_indent ("editor/show_white_space_indent", QVariant (false)); + +gui_pref +ed_show_line_numbers ("editor/showLineNumbers", QVariant (true)); + +gui_pref +ed_show_eol_chars ("editor/show_eol_chars", QVariant (false)); + +gui_pref +ed_show_toolbar ("editor/show_toolbar", QVariant (true)); + +gui_pref +ed_show_hscroll_bar ("editor/show_hscroll_bar", QVariant (true)); + +// Octave comment strings + +gui_pref +ed_comment_str_old ("editor/octave_comment_string", QVariant (0)); + +gui_pref +ed_comment_str ("editor/oct_comment_str", QVariant (0)); + +gui_pref +ed_uncomment_str ("editor/oct_uncomment_str", QVariant (1 + 2 + 4 + 8)); + +// Session data + +gui_pref +ed_restore_session ("editor/restoreSession", QVariant (true)); + +gui_pref +ed_session_names ("editor/savedSessionTabs", QVariant (QStringList ())); + +gui_pref +ed_session_enc ("editor/saved_session_encodings", QVariant (QStringList ())); + +gui_pref +ed_session_ind ("editor/saved_session_tab_index", QVariant (QStringList ())); + +gui_pref +ed_session_lines ("editor/saved_session_lines", QVariant (QStringList ())); + +gui_pref +ed_session_bookmarks ("editor/saved_session_bookmarks", QVariant (QStringList ())); + +// Tabs + +gui_pref +ed_tab_position ("editor/tab_position", QVariant (QTabWidget::North)); + +gui_pref +ed_tabs_rotated ("editor/tabs_rotated", QVariant (false)); + +gui_pref +ed_tabs_max_width ("editor/tabs_max_width", QVariant (0)); + +// File handling + +gui_pref +ed_force_newline ("editor/force_newline", QVariant (true)); + +gui_pref +ed_rm_trailing_spaces ("editor/rm_trailing_spaces", QVariant (true)); + +gui_pref +ed_default_eol_mode ("editor/default_eol_mode", QVariant (os_eol_mode)); + +gui_pref +ed_show_dbg_file ("editor/show_dbg_file", QVariant (true)); + +gui_pref +ed_default_enc ("editor/default_encoding", QVariant ("UTF-8")); + +gui_pref +ed_create_new_file ("editor/create_new_file", QVariant (false)); + +gui_pref +ed_hiding_closes_files ("editor/hiding_closes_files", QVariant (false)); + +gui_pref +ed_always_reload_changed_files ("editor/always_reload_changed_files", + QVariant (false)); + +gui_pref +ed_mru_file_list ("editor/mru_file_list", QVariant ()); + +gui_pref +ed_mru_file_encodings ("editor/mru_file_encodings", QVariant ()); + +// The find dialog + +// Dialog position, the default will be calculated from the editor's geometry +gui_pref +ed_fdlg_pos ("editor/fdgl_pos", QVariant (QPoint (0, 0))); + +gui_pref +ed_fdlg_opts ("editor/fdgl_opts", QVariant (FIND_DLG_WRAP)); + +gui_pref +ed_fdlg_search ("editor/fdgl_search", QVariant ()); + +gui_pref +ed_fdlg_replace ("editor/fdgl_replace", QVariant ()); diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/gui-preferences-ed.h --- a/libgui/src/gui-preferences-ed.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/gui-preferences-ed.h Fri May 12 08:03:14 2023 +0200 @@ -31,150 +31,103 @@ #endif #include "gui-settings.h" -#include "localcharset-wrapper.h" // Editor preferences // Lexer -const gui_pref -ed_color_mode ("editor/color_mode", QVariant (0)); +extern gui_pref ed_color_mode; const int ed_max_lexer_styles = 64; const int ed_max_style_number = 128; // Code completion -const gui_pref -ed_code_completion_octave_builtins ("editor/codeCompletion_octave_builtins", - QVariant (true)); +extern gui_pref ed_code_completion_octave_builtins; + +extern gui_pref ed_code_completion_octave_functions; -const gui_pref -ed_code_completion_octave_functions ("editor/codeCompletion_octave_functions", - QVariant (true)); +extern gui_pref ed_code_completion_keywords; -const gui_pref -ed_code_completion_keywords ("editor/codeCompletion_keywords", QVariant (true)); +extern gui_pref ed_code_completion_document; -const gui_pref -ed_code_completion_document ("editor/codeCompletion_document", QVariant (true)); +extern gui_pref ed_code_completion_replace; -const gui_pref -ed_code_completion_replace ("editor/codeCompletion_replace", QVariant (false)); +extern gui_pref ed_code_completion_case; -const gui_pref -ed_code_completion_case ("editor/codeCompletion_case", QVariant (true)); +extern gui_pref ed_code_completion; -const gui_pref -ed_code_completion ("editor/codeCompletion", QVariant (true)); - -const gui_pref -ed_code_completion_threshold ("editor/codeCompletion_threshold", QVariant (3)); +extern gui_pref ed_code_completion_threshold; // Code formatting -const gui_pref -ed_code_folding ("editor/code_folding", QVariant (true)); +extern gui_pref ed_code_folding; -const gui_pref -ed_auto_indent ("editor/auto_indent", QVariant (true)); +extern gui_pref ed_auto_indent; -const gui_pref -ed_tab_indents_line ("editor/tab_indents_line", QVariant (false)); +extern gui_pref ed_tab_indents_line; -const gui_pref -ed_backspace_unindents_line ("editor/backspace_unindents_line", - QVariant (false)); +extern gui_pref ed_backspace_unindents_line; -const gui_pref -ed_show_indent_guides ("editor/show_indent_guides", QVariant (false)); +extern gui_pref ed_show_indent_guides; -const gui_pref -ed_indent_uses_tabs ("editor/indent_uses_tabs", QVariant (false)); +extern gui_pref ed_indent_uses_tabs; -const gui_pref -ed_indent_width ("editor/indent_width", QVariant (2)); +extern gui_pref ed_indent_width; -const gui_pref -ed_tab_width ("editor/tab_width", QVariant (2)); +extern gui_pref ed_tab_width; -const gui_pref -ed_auto_endif ("editor/auto_endif", QVariant (1)); +extern gui_pref ed_auto_endif; // Long line handling -const gui_pref -ed_long_line_column ("editor/long_line_column", QVariant (80)); +extern gui_pref ed_long_line_column; -const gui_pref -ed_long_line_marker ("editor/long_line_marker", QVariant (true)); +extern gui_pref ed_long_line_marker; -const gui_pref -ed_long_line_marker_line ("editor/long_line_marker_line", QVariant (true)); +extern gui_pref ed_long_line_marker_line; -const gui_pref -ed_long_line_marker_background ("editor/long_line_marker_background", - QVariant (false)); +extern gui_pref ed_long_line_marker_background; + +extern gui_pref ed_wrap_lines; -const gui_pref -ed_wrap_lines ("editor/wrap_lines", QVariant (false)); +extern gui_pref ed_break_lines; -const gui_pref -ed_break_lines ("editor/break_lines", QVariant (false)); - -const gui_pref -ed_break_lines_comments ("editor/break_lines_comments", QVariant (false)); +extern gui_pref ed_break_lines_comments; // Other -const gui_pref -ed_highlight_all_occurrences ("editor/highlight_all_occurrences", - QVariant (true)); +extern gui_pref ed_highlight_all_occurrences; -const gui_pref -ed_show_Line_numbers ("editor/showLineNumbers", QVariant (true)); +extern gui_pref ed_show_Line_numbers; + +extern gui_pref ed_line_numbers_size; -const gui_pref -ed_line_numbers_size ("editor/line_numbers_size", QVariant ( 0)); +extern gui_pref ed_show_edit_status_bar; -const gui_pref -ed_show_edit_status_bar ("editor/show_edit_status_bar", QVariant (true)); +extern gui_pref ed_highlight_current_line; -const gui_pref -ed_highlight_current_line ("editor/highlightCurrentLine", QVariant (true)); +extern gui_pref ed_highlight_current_line_color; -const gui_pref -ed_highlight_current_line_color ("editor/highlightCurrentLineColor", - QVariant (settings_color_no_change)); +extern gui_pref ed_show_white_space; -const gui_pref -ed_show_white_space ("editor/show_white_space", QVariant (false)); +extern gui_pref ed_show_white_space_indent; -const gui_pref -ed_show_white_space_indent ("editor/show_white_space_indent", QVariant (false)); +extern gui_pref ed_show_line_numbers; -const gui_pref -ed_show_line_numbers ("editor/showLineNumbers", QVariant (true)); - -const gui_pref -ed_show_eol_chars ("editor/show_eol_chars", QVariant (false)); +extern gui_pref ed_show_eol_chars; -const gui_pref -ed_show_toolbar ("editor/show_toolbar", QVariant (true)); +extern gui_pref ed_show_toolbar; -const gui_pref -ed_show_hscroll_bar ("editor/show_hscroll_bar", QVariant (true)); +extern gui_pref ed_show_hscroll_bar; // Octave comment strings -const gui_pref -ed_comment_str_old ("editor/octave_comment_string", QVariant (0)); +extern gui_pref ed_comment_str_old; -const gui_pref -ed_comment_str ("editor/oct_comment_str", QVariant (0)); +extern gui_pref ed_comment_str; -const gui_pref -ed_uncomment_str ("editor/oct_uncomment_str", QVariant (1 + 2 + 4 + 8)); +extern gui_pref ed_uncomment_str; const QString ed_last_comment_str ("editor/oct_last_comment_str"); @@ -192,23 +145,17 @@ // Session data -const gui_pref -ed_restore_session ("editor/restoreSession", QVariant (true)); +extern gui_pref ed_restore_session; -const gui_pref -ed_session_names ("editor/savedSessionTabs", QVariant (QStringList ())); +extern gui_pref ed_session_names; -const gui_pref -ed_session_enc ("editor/saved_session_encodings", QVariant (QStringList ())); +extern gui_pref ed_session_enc; -const gui_pref -ed_session_ind ("editor/saved_session_tab_index", QVariant (QStringList ())); +extern gui_pref ed_session_ind; -const gui_pref -ed_session_lines ("editor/saved_session_lines", QVariant (QStringList ())); +extern gui_pref ed_session_lines; -const gui_pref -ed_session_bookmarks ("editor/saved_session_bookmarks", QVariant (QStringList ())); +extern gui_pref ed_session_bookmarks; // Tabs const QStringList @@ -219,22 +166,17 @@ QT_TRANSLATE_NOOP ("octave::settings_dialog", "Right") }; -const gui_pref -ed_tab_position ("editor/tab_position", QVariant (QTabWidget::North)); +extern gui_pref ed_tab_position; -const gui_pref -ed_tabs_rotated ("editor/tabs_rotated", QVariant (false)); +extern gui_pref ed_tabs_rotated; -const gui_pref -ed_tabs_max_width ("editor/tabs_max_width", QVariant (0)); +extern gui_pref ed_tabs_max_width; // File handling -const gui_pref -ed_force_newline ("editor/force_newline", QVariant (true)); +extern gui_pref ed_force_newline; -const gui_pref -ed_rm_trailing_spaces ("editor/rm_trailing_spaces", QVariant (true)); +extern gui_pref ed_rm_trailing_spaces; #if defined (HAVE_QSCINTILLA) #if defined (Q_OS_WIN32) @@ -246,30 +188,21 @@ const int os_eol_mode = 2; #endif -const gui_pref -ed_default_eol_mode ("editor/default_eol_mode", QVariant (os_eol_mode)); +extern gui_pref ed_default_eol_mode; -const gui_pref -ed_show_dbg_file ("editor/show_dbg_file", QVariant (true)); +extern gui_pref ed_show_dbg_file; -const gui_pref -ed_default_enc ("editor/default_encoding", QVariant ("UTF-8")); +extern gui_pref ed_default_enc; -const gui_pref -ed_create_new_file ("editor/create_new_file", QVariant (false)); +extern gui_pref ed_create_new_file; -const gui_pref -ed_hiding_closes_files ("editor/hiding_closes_files", QVariant (false)); +extern gui_pref ed_hiding_closes_files; + +extern gui_pref ed_always_reload_changed_files; -const gui_pref -ed_always_reload_changed_files ("editor/always_reload_changed_files", - QVariant (false)); +extern gui_pref ed_mru_file_list; -const gui_pref -ed_mru_file_list ("editor/mru_file_list", QVariant ()); - -const gui_pref -ed_mru_file_encodings ("editor/mru_file_encodings", QVariant ()); +extern gui_pref ed_mru_file_encodings; // The find dialog @@ -286,15 +219,12 @@ }; // Dialog position, the default will be calculated from the editor's geometry -const gui_pref -ed_fdlg_pos ("editor/fdgl_pos", QVariant (QPoint (0, 0))); +extern gui_pref ed_fdlg_pos; + +extern gui_pref ed_fdlg_opts; -const gui_pref -ed_fdlg_opts ("editor/fdgl_opts", QVariant (FIND_DLG_WRAP)); +extern gui_pref ed_fdlg_search; -const gui_pref -ed_fdlg_search ("editor/fdgl_search", QVariant ()); -const gui_pref -ed_fdlg_replace ("editor/fdgl_replace", QVariant ()); +extern gui_pref ed_fdlg_replace; #endif diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/gui-preferences-fb.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/gui-preferences-fb.cc Fri May 12 08:03:14 2023 +0200 @@ -0,0 +1,74 @@ +//////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2017-2023 The Octave Project Developers +// +// See the file COPYRIGHT.md in the top-level directory of this +// distribution or . +// +// 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 +// . +// +//////////////////////////////////////////////////////////////////////// + +#if defined (HAVE_CONFIG_H) +# include "config.h" +#endif + +#include "gui-preferences-fb.h" + +// Files dock widget + +gui_pref +fb_column_state ("filesdockwidget/column_state", QVariant ()); + +gui_pref +fb_mru_list ("filesdockwidget/mru_dir_list", QVariant (QStringList ())); + +gui_pref +fb_show_size ("filesdockwidget/showFileSize", QVariant (false)); + +gui_pref +fb_show_type ("filesdockwidget/showFileType", QVariant (false)); + +gui_pref +fb_show_date ("filesdockwidget/showLastModified", QVariant (false)); + +gui_pref +fb_show_hidden ("filesdockwidget/showHiddenFiles", QVariant (false)); + +gui_pref +fb_show_altcol ("filesdockwidget/useAlternatingRowColors", QVariant (true)); + +gui_pref +fb_sort_column ("filesdockwidget/sort_files_by_column", QVariant (0)); + +gui_pref +fb_sort_order ("filesdockwidget/sort_files_by_order", + QVariant (Qt::AscendingOrder)); + +gui_pref +fb_sync_octdir ("filesdockwidget/sync_octave_directory", QVariant (true)); + +gui_pref +fb_restore_last_dir ("filesdockwidget/restore_last_dir", QVariant (false)); + +gui_pref +fb_startup_dir ("filesdockwidget/startup_dir", QVariant (QString ())); + +gui_pref +fb_txt_file_ext ("filesdockwidget/txt_file_extensions", + QVariant ("m;c;cc;cpp;h;txt")); + diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/gui-preferences-fb.h --- a/libgui/src/gui-preferences-fb.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/gui-preferences-fb.h Fri May 12 08:03:14 2023 +0200 @@ -30,45 +30,30 @@ // Files dock widget -const gui_pref -fb_column_state ("filesdockwidget/column_state", QVariant ()); +extern gui_pref fb_column_state; -const gui_pref -fb_mru_list ("filesdockwidget/mru_dir_list", QVariant (QStringList ())); +extern gui_pref fb_mru_list; -const gui_pref -fb_show_size ("filesdockwidget/showFileSize", QVariant (false)); +extern gui_pref fb_show_size; -const gui_pref -fb_show_type ("filesdockwidget/showFileType", QVariant (false)); +extern gui_pref fb_show_type; -const gui_pref -fb_show_date ("filesdockwidget/showLastModified", QVariant (false)); +extern gui_pref fb_show_date; -const gui_pref -fb_show_hidden ("filesdockwidget/showHiddenFiles", QVariant (false)); +extern gui_pref fb_show_hidden; -const gui_pref -fb_show_altcol ("filesdockwidget/useAlternatingRowColors", QVariant (true)); +extern gui_pref fb_show_altcol; -const gui_pref -fb_sort_column ("filesdockwidget/sort_files_by_column", QVariant (0)); +extern gui_pref fb_sort_column; -const gui_pref -fb_sort_order ("filesdockwidget/sort_files_by_order", - QVariant (Qt::AscendingOrder)); +extern gui_pref fb_sort_order; -const gui_pref -fb_sync_octdir ("filesdockwidget/sync_octave_directory", QVariant (true)); +extern gui_pref fb_sync_octdir; -const gui_pref -fb_restore_last_dir ("filesdockwidget/restore_last_dir", QVariant (false)); +extern gui_pref fb_restore_last_dir; -const gui_pref -fb_startup_dir ("filesdockwidget/startup_dir", QVariant (QString ())); +extern gui_pref fb_startup_dir; -const gui_pref -fb_txt_file_ext ("filesdockwidget/txt_file_extensions", - QVariant ("m;c;cc;cpp;h;txt")); +extern gui_pref fb_txt_file_ext; #endif diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/gui-preferences-ff.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/gui-preferences-ff.cc Fri May 12 08:03:14 2023 +0200 @@ -0,0 +1,66 @@ +//////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2017-2023 The Octave Project Developers +// +// See the file COPYRIGHT.md in the top-level directory of this +// distribution or . +// +// 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 +// . +// +//////////////////////////////////////////////////////////////////////// + +#if defined (HAVE_CONFIG_H) +# include "config.h" +#endif + +#include "gui-preferences-ff.h" + +// Find files dialog preferences + +gui_pref +ff_file_name ("findfiles/file_name", QVariant ("*")); + +gui_pref +ff_start_dir ("findfiles/start_dir", QVariant ("")); + +gui_pref +ff_recurse_dirs ("findfiles/recurse_dirs", QVariant (false)); + +gui_pref +ff_include_dirs ("findfiles/include_dirs", QVariant (false)); + +gui_pref +ff_name_case ("findfiles/name_case", QVariant (false)); + +gui_pref +ff_check_text ("findfiles/check_text", QVariant (false)); + +gui_pref +ff_contains_text ("findfiles/contains_text", QVariant ("")); + +gui_pref +ff_content_case ("findfiles/content_case", QVariant (false)); + +gui_pref +ff_column_state ("findfiles/column_state", QVariant ()); + +gui_pref +ff_sort_files_by_column ("findfiles/sort_files_by_column", QVariant (0)); + +gui_pref +ff_sort_files_by_order ("findfiles/sort_files_by_order", + QVariant (Qt::AscendingOrder)); diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/gui-preferences-ff.h --- a/libgui/src/gui-preferences-ff.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/gui-preferences-ff.h Fri May 12 08:03:14 2023 +0200 @@ -30,39 +30,27 @@ // Find files dialog preferences -const gui_pref -ff_file_name ("findfiles/file_name", QVariant ("*")); +extern gui_pref ff_file_name; -const gui_pref -ff_start_dir ("findfiles/start_dir", QVariant ("")); +extern gui_pref ff_start_dir; -const gui_pref -ff_recurse_dirs ("findfiles/recurse_dirs", QVariant (false)); +extern gui_pref ff_recurse_dirs; -const gui_pref -ff_include_dirs ("findfiles/include_dirs", QVariant (false)); +extern gui_pref ff_include_dirs; -const gui_pref -ff_name_case ("findfiles/name_case", QVariant (false)); +extern gui_pref ff_name_case; -const gui_pref -ff_check_text ("findfiles/check_text", QVariant (false)); +extern gui_pref ff_check_text; -const gui_pref -ff_contains_text ("findfiles/contains_text", QVariant ("")); +extern gui_pref ff_contains_text; -const gui_pref -ff_content_case ("findfiles/content_case", QVariant (false)); +extern gui_pref ff_content_case; -const gui_pref -ff_column_state ("findfiles/column_state", QVariant ()); +extern gui_pref ff_column_state; -const gui_pref -ff_sort_files_by_column ("findfiles/sort_files_by_column", QVariant (0)); +extern gui_pref ff_sort_files_by_column; -const gui_pref -ff_sort_files_by_order ("findfiles/sort_files_by_order", - QVariant (Qt::AscendingOrder)); +extern gui_pref ff_sort_files_by_order; #endif diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/gui-preferences-global.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/gui-preferences-global.cc Fri May 12 08:03:14 2023 +0200 @@ -0,0 +1,119 @@ +//////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2017-2023 The Octave Project Developers +// +// See the file COPYRIGHT.md in the top-level directory of this +// distribution or . +// +// 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 +// . +// +//////////////////////////////////////////////////////////////////////// + +#if defined (HAVE_CONFIG_H) +# include "config.h" +#endif + +#include "gui-preferences-global.h" + +// Global preferences + +gui_pref +global_skip_welcome_wizard ("global_skip_welcome_wizard", false); + +gui_pref +global_mono_font ("monospace_font", global_font_family); + +// Style + +gui_pref +global_style ("style", QVariant ("default")); + +// Icon size (in preferences: values -1, 0, 1) + +gui_pref +global_icon_size ("toolbar_icon_size", QVariant (0)); + +gui_pref +global_icon_theme ("use_system_icon_theme", QVariant (true)); + +gui_pref +global_icon_theme_index ("icon_theme", QVariant (ICON_THEME_SYSTEM)); + +gui_pref +global_icon_fallbacks ("icon_fallbacks", QVariant (QStringList ())); + +gui_pref +global_status_bar ("show_status_bar", QVariant (true)); + +#if defined (Q_OS_MAC) +// prevent native file dialogs on MAC by setting the default "false" and +// setting the flag for ignoring the pref to "true" (3rd argument) +gui_pref +global_use_native_dialogs ("use_native_file_dialogs", QVariant (false), true); +#elif defined (Q_OS_WIN32) +gui_pref +global_use_native_dialogs ("use_native_file_dialogs", QVariant (false)); +#else +gui_pref +global_use_native_dialogs ("use_native_file_dialogs", QVariant (true)); +#endif + +gui_pref +global_cursor_blinking ("cursor_blinking", QVariant (true)); + +gui_pref +global_language ("language", QVariant ("SYSTEM")); + +gui_pref +global_ov_startup_dir ("octave_startup_dir", QVariant (QString ())); + +gui_pref +global_restore_ov_dir ("restore_octave_dir", QVariant (false)); + +gui_pref +global_use_custom_editor ("useCustomFileEditor", QVariant (false)); + +#if defined (Q_OS_WIN32) +gui_pref +global_custom_editor ("customFileEditor", QVariant ("notepad++ -n%l %f")); +#else +gui_pref +global_custom_editor ("customFileEditor", QVariant ("emacs +%l %f")); +#endif + +gui_pref +global_prompt_to_exit ("prompt_to_exit", QVariant (false)); + +// Proxy + +gui_pref +global_proxy_host ("proxyHostName", QVariant (QString ())); + +gui_pref +global_use_proxy ("useProxyServer", QVariant (false)); + +gui_pref +global_proxy_type ("proxyType", QVariant (QString ())); + +gui_pref +global_proxy_port ("proxyPort", QVariant (80)); + +gui_pref +global_proxy_user ("proxyUserName", QVariant (QString ())); + +gui_pref +global_proxy_pass ("proxyPassword", QVariant (QString ())); diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/gui-preferences-global.h --- a/libgui/src/gui-preferences-global.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/gui-preferences-global.h Fri May 12 08:03:14 2023 +0200 @@ -26,6 +26,8 @@ #if ! defined (octave_gui_preferences_global_h) #define octave_gui_preferences_global_h 1 +#include + #include "gui-preferences.h" // Constants @@ -34,6 +36,8 @@ // Global preferences +extern gui_pref global_skip_welcome_wizard; + // Get the default monospaced font #if defined (Q_OS_WIN) const QString global_font_family = "Courier"; @@ -43,13 +47,11 @@ const QString global_font_family = "Monospace"; #endif -const gui_pref -global_mono_font ("monospace_font", global_font_family); +extern gui_pref global_mono_font; // Style -const gui_pref -global_style ("style", QVariant ("default")); +extern gui_pref global_style; const QString global_toolbar_style ("QToolBar {" @@ -78,11 +80,9 @@ QStyle::PM_LargeIconSize }; -const gui_pref -global_icon_size ("toolbar_icon_size", QVariant (0)); +extern gui_pref global_icon_size; -const gui_pref -global_icon_theme ("use_system_icon_theme", QVariant (true)); +extern gui_pref global_icon_theme; enum { @@ -100,8 +100,8 @@ ":/icons/cursors/" }; -const gui_pref -global_icon_theme_index ("icon_theme", QVariant (ICON_THEME_SYSTEM)); +extern gui_pref global_icon_theme_index; + const QStringList global_all_icon_themes = { "", @@ -117,9 +117,9 @@ "Tango" }; -const gui_pref -global_status_bar ("show_status_bar", QVariant (true)); +extern gui_pref global_icon_fallbacks; +extern gui_pref global_status_bar; enum { @@ -133,55 +133,44 @@ #if defined (Q_OS_MAC) // prevent native file dialogs on MAC by setting the default "false" and // setting the flag for ignoring the pref to "true" (3rd argument) -const gui_pref -global_use_native_dialogs ("use_native_file_dialogs", QVariant (false), true); +extern gui_pref global_use_native_dialogs; #elif defined (Q_OS_WIN32) -const gui_pref -global_use_native_dialogs ("use_native_file_dialogs", QVariant (false)); +extern gui_pref global_use_native_dialogs; #else -const gui_pref -global_use_native_dialogs ("use_native_file_dialogs", QVariant (true)); +extern gui_pref global_use_native_dialogs; #endif -const gui_pref -global_cursor_blinking ("cursor_blinking", QVariant (true)); +extern gui_pref global_cursor_blinking; -const gui_pref -global_language ("language", QVariant ("SYSTEM")); +extern gui_pref global_language; -const gui_pref -global_ov_startup_dir ("octave_startup_dir", QVariant (QString ())); -const gui_pref -global_restore_ov_dir ("restore_octave_dir", QVariant (false)); +extern gui_pref global_ov_startup_dir; -const gui_pref -global_use_custom_editor ("useCustomFileEditor", QVariant (false)); +extern gui_pref global_restore_ov_dir; + +extern gui_pref global_use_custom_editor; #if defined (Q_OS_WIN32) -const gui_pref -global_custom_editor ("customFileEditor", QVariant ("notepad++ -n%l %f")); +extern gui_pref global_custom_editor; #else -const gui_pref -global_custom_editor ("customFileEditor", QVariant ("emacs +%l %f")); +extern gui_pref global_custom_editor; #endif -const gui_pref -global_prompt_to_exit ("prompt_to_exit", QVariant (false)); +extern gui_pref global_prompt_to_exit; // Proxy -const gui_pref -global_proxy_host ("proxyHostName", QVariant (QString ())); -const gui_pref -global_use_proxy ("useProxyServer", QVariant (false)); -const gui_pref -global_proxy_type ("proxyType", QVariant (QString ())); -const gui_pref -global_proxy_port ("proxyPort", QVariant (80)); -const gui_pref -global_proxy_user ("proxyUserName", QVariant (QString ())); -const gui_pref -global_proxy_pass ("proxyPassword", QVariant (QString ())); +extern gui_pref global_proxy_host; + +extern gui_pref global_use_proxy; + +extern gui_pref global_proxy_type; + +extern gui_pref global_proxy_port; + +extern gui_pref global_proxy_user; + +extern gui_pref global_proxy_pass; const QStringList global_proxy_all_types = { diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/gui-preferences-gp.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/gui-preferences-gp.cc Fri May 12 08:03:14 2023 +0200 @@ -0,0 +1,35 @@ +//////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2017-2023 The Octave Project Developers +// +// See the file COPYRIGHT.md in the top-level directory of this +// distribution or . +// +// 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 +// . +// +//////////////////////////////////////////////////////////////////////// + +#if defined (HAVE_CONFIG_H) +# include "config.h" +#endif + +#include "gui-preferences-gp.h" + +// Graphics utilities + +gui_pref +gp_annotation_geometry ("annotation/geometry", QVariant ()); diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/gui-preferences-gp.h --- a/libgui/src/gui-preferences-gp.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/gui-preferences-gp.h Fri May 12 08:03:14 2023 +0200 @@ -30,7 +30,6 @@ // Graphics utilities -const gui_pref -gp_annotation_geometry ("annotation/geometry", QVariant ()); +extern gui_pref gp_annotation_geometry; #endif diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/gui-preferences-hw.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/gui-preferences-hw.cc Fri May 12 08:03:14 2023 +0200 @@ -0,0 +1,41 @@ +//////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2017-2023 The Octave Project Developers +// +// See the file COPYRIGHT.md in the top-level directory of this +// distribution or . +// +// 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 +// . +// +//////////////////////////////////////////////////////////////////////// + +#if defined (HAVE_CONFIG_H) +# include "config.h" +#endif + +#include "gui-preferences-hw.h" + +// News Reader properties + +gui_pref +hw_filter_active ("history_dock_widget/filter_active", QVariant (false)); + +gui_pref +hw_filter_shown ("history_dock_widget/filter_shown", QVariant (true)); + +gui_pref +hw_mru_list ("history_dock_widget/mru_list", QVariant ()); diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/gui-preferences-hw.h --- a/libgui/src/gui-preferences-hw.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/gui-preferences-hw.h Fri May 12 08:03:14 2023 +0200 @@ -30,13 +30,10 @@ // News Reader properties -const gui_pref -hw_filter_active ("history_dock_widget/filter_active", QVariant (false)); +extern gui_pref hw_filter_active; -const gui_pref -hw_filter_shown ("history_dock_widget/filter_shown", QVariant (true)); +extern gui_pref hw_filter_shown; -const gui_pref -hw_mru_list ("history_dock_widget/mru_list", QVariant ()); +extern gui_pref hw_mru_list; #endif diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/gui-preferences-mw.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/gui-preferences-mw.cc Fri May 12 08:03:14 2023 +0200 @@ -0,0 +1,43 @@ +//////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2018-2023 The Octave Project Developers +// +// See the file COPYRIGHT.md in the top-level directory of this +// distribution or . +// +// 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 +// . +// +//////////////////////////////////////////////////////////////////////// + +#if defined (HAVE_CONFIG_H) +# include "config.h" +#endif + +#include "gui-preferences-mw.h" + +// Main window preferences + +// Geometry wihtout default since default layout is built programmatically +gui_pref +mw_geometry ("MainWindow/geometry", QVariant (QByteArray ())); + +// State wihtout default since default layout is built programmatically +gui_pref +mw_state ("MainWindow/windowState", QVariant (QByteArray ())); + +gui_pref +mw_dir_list ("MainWindow/current_directory_list", QVariant (QStringList ())); diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/gui-preferences-mw.h --- a/libgui/src/gui-preferences-mw.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/gui-preferences-mw.h Fri May 12 08:03:14 2023 +0200 @@ -31,14 +31,11 @@ // Main window preferences // Geometry wihtout default since default layout is built programmatically -const gui_pref -mw_geometry ("MainWindow/geometry", QVariant (QByteArray ())); +extern gui_pref mw_geometry; // State wihtout default since default layout is built programmatically -const gui_pref -mw_state ("MainWindow/windowState", QVariant (QByteArray ())); +extern gui_pref mw_state; -const gui_pref -mw_dir_list ("MainWindow/current_directory_list", QVariant (QStringList ())); +extern gui_pref mw_dir_list; #endif diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/gui-preferences-nr.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/gui-preferences-nr.cc Fri May 12 08:03:14 2023 +0200 @@ -0,0 +1,42 @@ +//////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2017-2023 The Octave Project Developers +// +// See the file COPYRIGHT.md in the top-level directory of this +// distribution or . +// +// 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 +// . +// +//////////////////////////////////////////////////////////////////////// + +#if defined (HAVE_CONFIG_H) +# include "config.h" +#endif + +#include "gui-preferences-nr.h" +#include + +// News Reader properties + +gui_pref +nr_last_time ("news/last_time_checked", QVariant (QDateTime ())); + +gui_pref +nr_last_news ("news/last_news_item", QVariant (0)); + +gui_pref +nr_allow_connection ("news/allow_web_connection", QVariant (false)); diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/gui-preferences-nr.h --- a/libgui/src/gui-preferences-nr.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/gui-preferences-nr.h Fri May 12 08:03:14 2023 +0200 @@ -27,17 +27,13 @@ #define octave_gui_preferences_nr_h 1 #include "gui-preferences.h" -#include // News Reader properties -const gui_pref -nr_last_time ("news/last_time_checked", QVariant (QDateTime ())); +extern gui_pref nr_last_time; -const gui_pref -nr_last_news ("news/last_news_item", QVariant (0)); +extern gui_pref nr_last_news; -const gui_pref -nr_allow_connection ("news/allow_web_connection", QVariant (false)); +extern gui_pref nr_allow_connection; #endif diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/gui-preferences-pd.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/gui-preferences-pd.cc Fri May 12 08:03:14 2023 +0200 @@ -0,0 +1,35 @@ +//////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2017-2023 The Octave Project Developers +// +// See the file COPYRIGHT.md in the top-level directory of this +// distribution or . +// +// 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 +// . +// +//////////////////////////////////////////////////////////////////////// + +#if defined (HAVE_CONFIG_H) +# include "config.h" +#endif + +#include "gui-preferences-pd.h" + +// Path Dialog properties + +gui_pref +pd_geometry ("path_dlg_geometry", QVariant (QByteArray ())); diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/gui-preferences-pd.h --- a/libgui/src/gui-preferences-pd.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/gui-preferences-pd.h Fri May 12 08:03:14 2023 +0200 @@ -30,7 +30,6 @@ // Path Dialog properties -const gui_pref -pd_geometry ("path_dlg_geometry", QVariant (QByteArray ())); +extern gui_pref pd_geometry; #endif diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/gui-preferences-sc.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/gui-preferences-sc.cc Fri May 12 08:03:14 2023 +0200 @@ -0,0 +1,228 @@ +//////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2017-2023 The Octave Project Developers +// +// See the file COPYRIGHT.md in the top-level directory of this +// distribution or . +// +// 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 +// . +// +//////////////////////////////////////////////////////////////////////// + +#if defined (HAVE_CONFIG_H) +# include "config.h" +#endif + +#include +#include + +#include "gui-preferences-sc.h" + +// Note: Trying to shorten the uses of +// +// QCoreApplication::translate (CONTEXT, STRING) +// +// by defining a macro won't work because lupdate won't know to look for +// the macro. + +sc_pref sc_dock_widget_dock (QCoreApplication::translate ("shortcuts", "Undock/Dock Widget"), sc_dock_widget + ":dock", CTRL_ALT | Qt::Key_D); +sc_pref sc_dock_widget_close (QCoreApplication::translate ("shortcuts", "Close Widget"), sc_dock_widget + ":close", CTRL_ALT | Qt::Key_C); + +// Main window menu + +// file +sc_pref sc_main_file_new_file (QCoreApplication::translate ("shortcuts", "New File"), sc_main_file + ":new_file", QKeySequence::New); +sc_pref sc_main_file_new_function (QCoreApplication::translate ("shortcuts", "New Function"), sc_main_file + ":new_function", CTRL_SHIFT | Qt::Key_N); +sc_pref sc_main_file_new_figure (QCoreApplication::translate ("shortcuts", "New Figure"), sc_main_file + ":new_figure", QKeySequence::UnknownKey); +sc_pref sc_main_file_open_file (QCoreApplication::translate ("shortcuts", "Open File"), sc_main_file + ":open_file", QKeySequence::Open); +sc_pref sc_main_file_load_workspace (QCoreApplication::translate ("shortcuts", "Load Workspace"), sc_main_file + ":load_workspace", QKeySequence::UnknownKey); +sc_pref sc_main_file_save_workspace (QCoreApplication::translate ("shortcuts", "Save Workspace As"), sc_main_file + ":save_workspace", QKeySequence::UnknownKey); +sc_pref sc_main_file_exit (QCoreApplication::translate ("shortcuts", "Exit Octave"), sc_main_file + ":exit", QKeySequence::Quit); + +// edit +sc_pref sc_main_edit_copy (QCoreApplication::translate ("shortcuts", "Copy"), sc_main_edit + ":copy", QKeySequence::Copy); +sc_pref sc_main_edit_paste (QCoreApplication::translate ("shortcuts", "Paste"), sc_main_edit + ":paste", QKeySequence::Paste); +sc_pref sc_main_edit_undo (QCoreApplication::translate ("shortcuts", "Undo"), sc_main_edit + ":undo", QKeySequence::Undo); +sc_pref sc_main_edit_select_all (QCoreApplication::translate ("shortcuts", "Select All"), sc_main_edit + ":select_all", QKeySequence::SelectAll); +sc_pref sc_main_edit_clear_clipboard (QCoreApplication::translate ("shortcuts", "Clear Clipboard"), sc_main_edit + ":clear_clipboard", QKeySequence::UnknownKey); +sc_pref sc_main_edit_find_in_files (QCoreApplication::translate ("shortcuts", "Find in Files"), sc_main_edit + ":find_in_files", CTRL_SHIFT | Qt::Key_F); +sc_pref sc_main_edit_clear_command_window (QCoreApplication::translate ("shortcuts", "Clear Command Window"), sc_main_edit + ":clear_command_window", QKeySequence::UnknownKey); +sc_pref sc_main_edit_clear_history (QCoreApplication::translate ("shortcuts", "Clear Command History"), sc_main_edit + ":clear_history", QKeySequence::UnknownKey); +sc_pref sc_main_edit_clear_workspace (QCoreApplication::translate ("shortcuts", "Clear Workspace"), sc_main_edit + ":clear_workspace", QKeySequence::UnknownKey); +sc_pref sc_main_edit_set_path (QCoreApplication::translate ("shortcuts", "Set Path"), sc_main_edit + ":set_path", QKeySequence::UnknownKey); +sc_pref sc_main_edit_preferences (QCoreApplication::translate ("shortcuts", "Preferences"), sc_main_edit + ":preferences", QKeySequence::UnknownKey); + +// debug +sc_pref sc_main_debug_step_over (QCoreApplication::translate ("shortcuts", "Step"), sc_main_debug + ":step_over", PRE | Qt::Key_F10); +sc_pref sc_main_debug_step_into (QCoreApplication::translate ("shortcuts", "Step Into"), sc_main_debug + ":step_into", PRE | Qt::Key_F11); +sc_pref sc_main_debug_step_out (QCoreApplication::translate ("shortcuts", "Step Out"), sc_main_debug + ":step_out", PRE | Qt::ShiftModifier | Qt::Key_F11); +sc_pref sc_main_debug_continue (QCoreApplication::translate ("shortcuts", "Continue"), sc_main_debug + ":continue", PRE | Qt::Key_F5); +sc_pref sc_main_debug_quit (QCoreApplication::translate ("shortcuts", "Quit Debug Mode"), sc_main_debug + ":quit", PRE | Qt::ShiftModifier | Qt::Key_F5); + +// tools +sc_pref sc_main_tools_start_profiler (QCoreApplication::translate ("shortcuts", "Start/Stop Profiler Session"), sc_main_tools + ":start_profiler", CTRL_SHIFT | Qt::Key_P); +sc_pref sc_main_tools_resume_profiler (QCoreApplication::translate ("shortcuts", "Resume Profiler Session"), sc_main_tools + ":resume_profiler", QKeySequence::UnknownKey); +sc_pref sc_main_tools_show_profiler (QCoreApplication::translate ("shortcuts", "Show Profile Data"), sc_main_tools + ":show_profiler", Qt::AltModifier | Qt::ShiftModifier | Qt::Key_P); + + +// window +sc_pref sc_main_window_show_command (QCoreApplication::translate ("shortcuts", "Show Command Window"), sc_main_window + ":show_command", PRE | CTRL_SHIFT | Qt::Key_0); +sc_pref sc_main_window_show_history (QCoreApplication::translate ("shortcuts", "Show Command History"), sc_main_window + ":show_history", PRE | CTRL_SHIFT | Qt::Key_1); +sc_pref sc_main_window_show_file_browser (QCoreApplication::translate ("shortcuts", "Show File Browser"), sc_main_window + ":show_file_browser", PRE | CTRL_SHIFT | Qt::Key_2); +sc_pref sc_main_window_show_workspace (QCoreApplication::translate ("shortcuts", "Show Workspace"), sc_main_window + ":show_workspace", PRE | CTRL_SHIFT | Qt::Key_3); +sc_pref sc_main_window_show_editor (QCoreApplication::translate ("shortcuts", "Show Editor"), sc_main_window + ":show_editor", PRE | CTRL_SHIFT | Qt::Key_4); +sc_pref sc_main_window_show_doc (QCoreApplication::translate ("shortcuts", "Show Documentation"), sc_main_window + ":show_doc", PRE | CTRL_SHIFT | Qt::Key_5); +sc_pref sc_main_window_show_variable_editor (QCoreApplication::translate ("shortcuts", "Show Variable Editor"), sc_main_window + ":show_variable_editor", PRE | CTRL_SHIFT | Qt::Key_6); +sc_pref sc_main_window_command (QCoreApplication::translate ("shortcuts", "Command Window"), sc_main_window + ":command", PRE | CTRL | Qt::Key_0); +sc_pref sc_main_window_history (QCoreApplication::translate ("shortcuts", "Command History"), sc_main_window + ":history", PRE | CTRL | Qt::Key_1); +sc_pref sc_main_window_file_browser (QCoreApplication::translate ("shortcuts", "File Browser"), sc_main_window + ":file_browser", PRE | CTRL | Qt::Key_2); +sc_pref sc_main_window_workspace (QCoreApplication::translate ("shortcuts", "Workspace"), sc_main_window + ":workspace", PRE | CTRL | Qt::Key_3); +sc_pref sc_main_window_editor (QCoreApplication::translate ("shortcuts", "Editor"), sc_main_window + ":editor", PRE | CTRL | Qt::Key_4); +sc_pref sc_main_window_doc (QCoreApplication::translate ("shortcuts", "Documentation"), sc_main_window + ":doc", PRE | CTRL | Qt::Key_5); +sc_pref sc_main_window_variable_editor (QCoreApplication::translate ("shortcuts", "Variable Editor"), sc_main_window + ":variable_editor", PRE | CTRL | Qt::Key_6); +sc_pref sc_main_window_previous_dock (QCoreApplication::translate ("shortcuts", "Previous Widget"), sc_main_window + ":previous_widget", PRE | CTRL_ALT | Qt::Key_P); +sc_pref sc_main_window_reset (QCoreApplication::translate ("shortcuts", "Reset Default Window Layout"), sc_main_window + ":reset", QKeySequence::UnknownKey); + +// help +sc_pref sc_main_help_ondisk_doc (QCoreApplication::translate ("shortcuts", "Show On-disk Documentation"), sc_main_help + ":ondisk_doc", QKeySequence::UnknownKey); +sc_pref sc_main_help_online_doc (QCoreApplication::translate ("shortcuts", "Show Online Documentation"), sc_main_help + ":online_doc", QKeySequence::UnknownKey); +sc_pref sc_main_help_report_bug (QCoreApplication::translate ("shortcuts", "Report Bug"), sc_main_help + ":report_bug", QKeySequence::UnknownKey); +sc_pref sc_main_help_packages (QCoreApplication::translate ("shortcuts", "Octave Packages"), sc_main_help + ":packages", QKeySequence::UnknownKey); +sc_pref sc_main_help_contribute (QCoreApplication::translate ("shortcuts", "Contribute to Octave"), sc_main_help + ":contribute", QKeySequence::UnknownKey); +sc_pref sc_main_help_developer (QCoreApplication::translate ("shortcuts", "Octave Developer Resources"), sc_main_help + ":developer", QKeySequence::UnknownKey); +sc_pref sc_main_help_about (QCoreApplication::translate ("shortcuts", "About Octave"), sc_main_help + ":about", QKeySequence::UnknownKey); + +// news +sc_pref sc_main_news_release_notes (QCoreApplication::translate ("shortcuts", "Release Notes"), sc_main_news + ":release_notes", QKeySequence::UnknownKey); +sc_pref sc_main_news_community_news (QCoreApplication::translate ("shortcuts", "Community News"), sc_main_news + ":community_news", QKeySequence::UnknownKey); + +// Tab handling +// The following shortcuts are moved into a separate tab. The key names +// are not change for preserving compatibility with older versions +sc_pref sc_edit_file_close (QCoreApplication::translate ("shortcuts", "Close Tab"), sc_edit_file_cl, QKeySequence::Close); +sc_pref sc_edit_file_close_all (QCoreApplication::translate ("shortcuts", "Close All Tabs"), sc_edit_file_cl + "_all", QKeySequence::UnknownKey); +sc_pref sc_edit_file_close_other (QCoreApplication::translate ("shortcuts", "Close Other Tabs"), sc_edit_file_cl + "_other", QKeySequence::UnknownKey); +sc_pref sc_edit_tabs_switch_left_tab (QCoreApplication::translate ("shortcuts", "Switch to Left Tab"), sc_edit_tabs + ":switch_left_tab", CTRL | Qt::Key_PageUp); +sc_pref sc_edit_tabs_switch_right_tab (QCoreApplication::translate ("shortcuts", "Switch to Right Tab"), sc_edit_tabs + ":switch_right_tab", CTRL | Qt::Key_PageDown); +sc_pref sc_edit_tabs_move_tab_left (QCoreApplication::translate ("shortcuts", "Move Tab Left"), sc_edit_tabs + ":move_tab_left", Qt::AltModifier | Qt::Key_PageUp); +sc_pref sc_edit_tabs_move_tab_right (QCoreApplication::translate ("shortcuts", "Move Tab Right"), sc_edit_tabs + ":move_tab_right", Qt::AltModifier | Qt::Key_PageDown); + +// Zooming +sc_pref sc_edit_view_zoom_in (QCoreApplication::translate ("shortcuts", "Zoom In"), sc_edit_view_zoom + "_in", QKeySequence::ZoomIn); +sc_pref sc_edit_view_zoom_out (QCoreApplication::translate ("shortcuts", "Zoom Out"), sc_edit_view_zoom + "_out", QKeySequence::ZoomOut); +#if defined (Q_OS_MAC) +sc_pref sc_edit_view_zoom_normal (QCoreApplication::translate ("shortcuts", "Zoom Normal"), sc_edit_view_zoom + "_normal", CTRL | Qt::Key_Underscore); +#else +sc_pref sc_edit_view_zoom_normal (QCoreApplication::translate ("shortcuts", "Zoom Normal"), sc_edit_view_zoom + "_normal", CTRL | Qt::Key_Period); +#endif + +// Actions of the editor + +// file +sc_pref sc_edit_file_edit_function (QCoreApplication::translate ("shortcuts", "Edit Function"), sc_edit_file + ":edit_function", CTRL | Qt::Key_E); +sc_pref sc_edit_file_save (QCoreApplication::translate ("shortcuts", "Save File"), sc_edit_file + ":save", QKeySequence::Save); +sc_pref sc_edit_file_save_as (QCoreApplication::translate ("shortcuts", "Save File As"), sc_edit_file + ":save_as", QKeySequence::SaveAs); +sc_pref sc_edit_file_print (QCoreApplication::translate ("shortcuts", "Print"), sc_edit_file + ":print", QKeySequence::Print); + +// edit +sc_pref sc_edit_edit_redo (QCoreApplication::translate ("shortcuts", "Redo"), sc_edit_edit + ":redo", QKeySequence::Redo); +sc_pref sc_edit_edit_cut (QCoreApplication::translate ("shortcuts", "Cut"), sc_edit_edit + ":cut", QKeySequence::Cut); +sc_pref sc_edit_edit_find_replace (QCoreApplication::translate ("shortcuts", "Find and Replace"), sc_edit_edit_find + "_replace", QKeySequence::Find); +sc_pref sc_edit_edit_find_next (QCoreApplication::translate ("shortcuts", "Find Next"), sc_edit_edit_find + "_next", QKeySequence::FindNext); +sc_pref sc_edit_edit_find_previous (QCoreApplication::translate ("shortcuts", "Find Previous"), sc_edit_edit_find + "_previous", QKeySequence::FindPrevious); +sc_pref sc_edit_edit_delete_start_word (QCoreApplication::translate ("shortcuts", "Delete to Start of Word"), sc_edit_edit + ":delete_start_word", QKeySequence::DeleteStartOfWord); +sc_pref sc_edit_edit_delete_end_word (QCoreApplication::translate ("shortcuts", "Delete to End of Word"), sc_edit_edit + ":delete_end_word", QKeySequence::DeleteEndOfWord); +sc_pref sc_edit_edit_delete_start_line (QCoreApplication::translate ("shortcuts", "Delete to Start of Line"), sc_edit_edit + ":delete_start_line", CTRL_SHIFT | Qt::Key_Backspace); +sc_pref sc_edit_edit_delete_end_line (QCoreApplication::translate ("shortcuts", "Delete to End of Line"), sc_edit_edit + ":delete_end_line", CTRL_SHIFT | Qt::Key_Delete); +sc_pref sc_edit_edit_delete_line (QCoreApplication::translate ("shortcuts", "Delete Line"), sc_edit_edit + ":delete_line", CTRL_SHIFT | Qt::Key_L); +sc_pref sc_edit_edit_copy_line (QCoreApplication::translate ("shortcuts", "Copy Line"), sc_edit_edit + ":copy_line", CTRL_SHIFT | Qt::Key_C); +sc_pref sc_edit_edit_cut_line (QCoreApplication::translate ("shortcuts", "Cut Line"), sc_edit_edit + ":cut_line", CTRL_SHIFT | Qt::Key_X); +sc_pref sc_edit_edit_duplicate_selection (QCoreApplication::translate ("shortcuts", "Duplicate Selection/Line"), sc_edit_edit + ":duplicate_selection", CTRL | Qt::Key_D); +sc_pref sc_edit_edit_transpose_line (QCoreApplication::translate ("shortcuts", "Transpose Line"), sc_edit_edit + ":transpose_line", CTRL | Qt::Key_T); +sc_pref sc_edit_edit_completion_list (QCoreApplication::translate ("shortcuts", "Show Completion List"), sc_edit_edit + ":completion_list", CTRL | Qt::Key_Space); + +sc_pref sc_edit_edit_comment_selection (QCoreApplication::translate ("shortcuts", "Comment Selection"), sc_edit_edit + ":comment_selection", CTRL | Qt::Key_R); +sc_pref sc_edit_edit_uncomment_selection (QCoreApplication::translate ("shortcuts", "Uncomment Selection"), sc_edit_edit + ":uncomment_selection", CTRL_SHIFT | Qt::Key_R); +sc_pref sc_edit_edit_comment_var_selection (QCoreApplication::translate ("shortcuts", "Comment Selection (Choosing String)"), sc_edit_edit + ":comment_var_selection", CTRL_ALT | Qt::Key_R); +sc_pref sc_edit_edit_upper_case (QCoreApplication::translate ("shortcuts", "Uppercase Selection"), sc_edit_edit + ":upper_case", CTRL | Qt::Key_U); +sc_pref sc_edit_edit_lower_case (QCoreApplication::translate ("shortcuts", "Lowercase Selection"), sc_edit_edit + ":lower_case", CTRL_ALT | Qt::Key_U); + +#if defined (Q_OS_MAC) +sc_pref sc_edit_edit_indent_selection (QCoreApplication::translate ("shortcuts", "Indent Selection Rigidly"), sc_edit_edit + ":indent_selection", PRE | Qt::Key_Tab); +sc_pref sc_edit_edit_unindent_selection (QCoreApplication::translate ("shortcuts", "Unindent Selection Rigidly"), sc_edit_edit + ":unindent_selection", PRE | Qt::ShiftModifier | Qt::Key_Tab); +#else +sc_pref sc_edit_edit_indent_selection (QCoreApplication::translate ("shortcuts", "Indent Selection Rigidly"), sc_edit_edit + ":indent_selection", CTRL | Qt::Key_Tab); +sc_pref sc_edit_edit_unindent_selection (QCoreApplication::translate ("shortcuts", "Unindent Selection Rigidly"), sc_edit_edit + ":unindent_selection", CTRL_SHIFT | Qt::Key_Tab); +#endif +sc_pref sc_edit_edit_smart_indent_line_or_selection (QCoreApplication::translate ("shortcuts", "Indent Code"), sc_edit_edit + ":smart_indent_line_or_selection", QKeySequence::UnknownKey); + +sc_pref sc_edit_edit_conv_eol_winows (QCoreApplication::translate ("shortcuts", "Convert Line Endings to Windows"), sc_edit_edit + ":conv_eol_winows", QKeySequence::UnknownKey); +sc_pref sc_edit_edit_conv_eol_unix (QCoreApplication::translate ("shortcuts", "Convert Line Endings to Unix"), sc_edit_edit + ":conv_eol_unix", QKeySequence::UnknownKey); +sc_pref sc_edit_edit_conv_eol_mac (QCoreApplication::translate ("shortcuts", "Convert Line Endings to Mac"), sc_edit_edit + ":conv_eol_mac", QKeySequence::UnknownKey); + +sc_pref sc_edit_edit_goto_line (QCoreApplication::translate ("shortcuts", "Goto Line"), sc_edit_edit + ":goto_line", CTRL | Qt::Key_L); +sc_pref sc_edit_edit_move_to_brace (QCoreApplication::translate ("shortcuts", "Move to Matching Brace"), sc_edit_edit + ":move_to_brace", CTRL | Qt::Key_M); +sc_pref sc_edit_edit_select_to_brace (QCoreApplication::translate ("shortcuts", "Select to Matching Brace"), sc_edit_edit + ":select_to_brace", CTRL_SHIFT | Qt::Key_M); +sc_pref sc_edit_edit_toggle_bookmark (QCoreApplication::translate ("shortcuts", "Toggle Bookmark"), sc_edit_edit + ":toggle_bookmark", PRE | Qt::Key_F7); +sc_pref sc_edit_edit_next_bookmark (QCoreApplication::translate ("shortcuts", "Next Bookmark"), sc_edit_edit + ":next_bookmark", PRE | Qt::Key_F2); +sc_pref sc_edit_edit_previous_bookmark (QCoreApplication::translate ("shortcuts", "Previous Bookmark"), sc_edit_edit + ":previous_bookmark", PRE | Qt::ShiftModifier | Qt::Key_F2); +sc_pref sc_edit_edit_remove_bookmark (QCoreApplication::translate ("shortcuts", "Remove All Bookmark"), sc_edit_edit + ":remove_bookmark", QKeySequence::UnknownKey); + +sc_pref sc_edit_edit_preferences (QCoreApplication::translate ("shortcuts", "Preferences"), sc_edit_edit + ":preferences", QKeySequence::UnknownKey); +sc_pref sc_edit_edit_styles_preferences (QCoreApplication::translate ("shortcuts", "Styles Preferences"), sc_edit_edit + ":styles_preferences", QKeySequence::UnknownKey); + +// view +sc_pref sc_edit_view_show_line_numbers (QCoreApplication::translate ("shortcuts", "Show Line Numbers"), sc_edit_view + ":show_line_numbers", QKeySequence::UnknownKey); +sc_pref sc_edit_view_show_white_spaces (QCoreApplication::translate ("shortcuts", "Show Whitespace Characters"), sc_edit_view + ":show_white_spaces", QKeySequence::UnknownKey); +sc_pref sc_edit_view_show_eol_chars (QCoreApplication::translate ("shortcuts", "Show Line Endings"), sc_edit_view + ":show_eol_chars", QKeySequence::UnknownKey); +sc_pref sc_edit_view_show_ind_guides (QCoreApplication::translate ("shortcuts", "Show Indentation Guides"), sc_edit_view + ":show_ind_guides", QKeySequence::UnknownKey); +sc_pref sc_edit_view_show_long_line (QCoreApplication::translate ("shortcuts", "Show Long Line Marker"), sc_edit_view + ":show_long_line", QKeySequence::UnknownKey); +sc_pref sc_edit_view_show_toolbar (QCoreApplication::translate ("shortcuts", "Show Toolbar"), sc_edit_view + ":show_toolbar", QKeySequence::UnknownKey); +sc_pref sc_edit_view_show_statusbar (QCoreApplication::translate ("shortcuts", "Show Statusbar"), sc_edit_view + ":show_statusbar", QKeySequence::UnknownKey); +sc_pref sc_edit_view_show_hscrollbar (QCoreApplication::translate ("shortcuts", "Show Horizontal Scrollbar"), sc_edit_view + ":show_hscrollbar", QKeySequence::UnknownKey); +sc_pref sc_edit_view_sort_tabs (QCoreApplication::translate ("shortcuts", "Sort Tabs Alphabetically"), sc_edit_view + ":sort_tabs", QKeySequence::UnknownKey); + +// debug +sc_pref sc_edit_debug_toggle_breakpoint (QCoreApplication::translate ("shortcuts", "Toggle Breakpoint"), sc_edit_debug + ":toggle_breakpoint", QKeySequence::UnknownKey); +sc_pref sc_edit_debug_next_breakpoint (QCoreApplication::translate ("shortcuts", "Next Breakpoint"), sc_edit_debug + ":next_breakpoint", QKeySequence::UnknownKey); +sc_pref sc_edit_debug_previous_breakpoint (QCoreApplication::translate ("shortcuts", "Previous Breakpoint"), sc_edit_debug + ":previous_breakpoint", QKeySequence::UnknownKey); +sc_pref sc_edit_debug_remove_breakpoints (QCoreApplication::translate ("shortcuts", "Remove All Breakpoints"), sc_edit_debug + ":remove_breakpoints", QKeySequence::UnknownKey); + +// run +sc_pref sc_edit_run_run_file (QCoreApplication::translate ("shortcuts", "Run File"), sc_edit_run + ":run_file", PRE | Qt::Key_F5); +sc_pref sc_edit_run_run_selection (QCoreApplication::translate ("shortcuts", "Run Selection"), sc_edit_run + ":run_selection", PRE | Qt::Key_F9); + +// help +sc_pref sc_edit_help_help_keyword (QCoreApplication::translate ("shortcuts", "Help on Keyword"), sc_edit_help + ":help_keyword", QKeySequence::HelpContents); +sc_pref sc_edit_help_doc_keyword (QCoreApplication::translate ("shortcuts", "Document on Keyword"), sc_edit_help + ":doc_keyword", Qt::SHIFT | Qt::Key_F1); + + +// Documentation browser +sc_pref sc_doc_go_home (QCoreApplication::translate ("shortcuts", "Go to Homepage"), sc_doc + ":go_home", Qt::AltModifier | Qt::Key_Home); +sc_pref sc_doc_go_back (QCoreApplication::translate ("shortcuts", "Go Back one Page"), sc_doc + ":go_back", QKeySequence::Back); +sc_pref sc_doc_go_next (QCoreApplication::translate ("shortcuts", "Go Forward one Page"), sc_doc + ":go_next", QKeySequence::Forward); +sc_pref sc_doc_bookmark (QCoreApplication::translate ("shortcuts", "Bookmark this Page"), sc_doc + ":bookmark", CTRL | Qt::Key_D); + +QString get_shortcut_section (const QString& key) +{ + QString section; + + if (key.contains (':')) + section = key.section (':', 0, 0, QString::SectionSkipEmpty); + + return section; +} diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/gui-preferences-sc.h --- a/libgui/src/gui-preferences-sc.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/gui-preferences-sc.h Fri May 12 08:03:14 2023 +0200 @@ -55,207 +55,209 @@ const Qt::KeyboardModifiers CTRL_SHIFT = CTRL | Qt::ShiftModifier; const Qt::KeyboardModifiers CTRL_ALT = CTRL | Qt::AltModifier; +const QString sc_group ("shortcuts"); + // Shortcuts not related to specific Menus // Dock widgets const QString sc_dock_widget ("dock_widget"); -const sc_pref sc_dock_widget_dock (sc_dock_widget + ":dock", CTRL_ALT + Qt::Key_D); -const sc_pref sc_dock_widget_close (sc_dock_widget + ":close", CTRL_ALT + Qt::Key_C); +extern sc_pref sc_dock_widget_dock; +extern sc_pref sc_dock_widget_close; // Main window menu // file const QString sc_main_file ("main_file"); -const sc_pref sc_main_file_new_file (sc_main_file + ":new_file", QKeySequence::New); -const sc_pref sc_main_file_new_function (sc_main_file + ":new_function", CTRL_SHIFT + Qt::Key_N); -const sc_pref sc_main_file_new_figure (sc_main_file + ":new_figure", QKeySequence::UnknownKey); -const sc_pref sc_main_file_open_file (sc_main_file + ":open_file", QKeySequence::Open); -const sc_pref sc_main_file_load_workspace (sc_main_file + ":load_workspace", QKeySequence::UnknownKey); -const sc_pref sc_main_file_save_workspace (sc_main_file + ":save_workspace", QKeySequence::UnknownKey); -const sc_pref sc_main_file_exit (sc_main_file + ":exit", QKeySequence::Quit); +extern sc_pref sc_main_file_new_file; +extern sc_pref sc_main_file_new_function; +extern sc_pref sc_main_file_new_figure; +extern sc_pref sc_main_file_open_file; +extern sc_pref sc_main_file_load_workspace; +extern sc_pref sc_main_file_save_workspace; +extern sc_pref sc_main_file_exit; // edit const QString sc_main_edit ("main_edit"); -const sc_pref sc_main_edit_copy (sc_main_edit + ":copy", QKeySequence::Copy); -const sc_pref sc_main_edit_paste (sc_main_edit + ":paste", QKeySequence::Paste); -const sc_pref sc_main_edit_undo (sc_main_edit + ":undo", QKeySequence::Undo); -const sc_pref sc_main_edit_select_all (sc_main_edit + ":select_all", QKeySequence::SelectAll); -const sc_pref sc_main_edit_clear_clipboard (sc_main_edit + ":clear_clipboard", QKeySequence::UnknownKey); -const sc_pref sc_main_edit_find_in_files (sc_main_edit + ":find_in_files", CTRL_SHIFT + Qt::Key_F); -const sc_pref sc_main_edit_clear_command_window (sc_main_edit + ":clear_command_window", QKeySequence::UnknownKey); -const sc_pref sc_main_edit_clear_history (sc_main_edit + ":clear_history", QKeySequence::UnknownKey); -const sc_pref sc_main_edit_clear_workspace (sc_main_edit + ":clear_workspace", QKeySequence::UnknownKey); -const sc_pref sc_main_edit_set_path (sc_main_edit + ":set_path", QKeySequence::UnknownKey); -const sc_pref sc_main_edit_preferences (sc_main_edit + ":preferences", QKeySequence::UnknownKey); +extern sc_pref sc_main_edit_copy; +extern sc_pref sc_main_edit_paste; +extern sc_pref sc_main_edit_undo; +extern sc_pref sc_main_edit_select_all; +extern sc_pref sc_main_edit_clear_clipboard; +extern sc_pref sc_main_edit_find_in_files; +extern sc_pref sc_main_edit_clear_command_window; +extern sc_pref sc_main_edit_clear_history; +extern sc_pref sc_main_edit_clear_workspace; +extern sc_pref sc_main_edit_set_path; +extern sc_pref sc_main_edit_preferences; // debug const QString sc_main_debug ("main_debug"); -const sc_pref sc_main_debug_step_over (sc_main_debug + ":step_over", PRE + Qt::Key_F10); -const sc_pref sc_main_debug_step_into (sc_main_debug + ":step_into", PRE + Qt::Key_F11); -const sc_pref sc_main_debug_step_out (sc_main_debug + ":step_out", PRE + Qt::ShiftModifier + Qt::Key_F11); -const sc_pref sc_main_debug_continue (sc_main_debug + ":continue", PRE + Qt::Key_F5); -const sc_pref sc_main_debug_quit (sc_main_debug + ":quit", PRE + Qt::ShiftModifier + Qt::Key_F5); +extern sc_pref sc_main_debug_step_over; +extern sc_pref sc_main_debug_step_into; +extern sc_pref sc_main_debug_step_out; +extern sc_pref sc_main_debug_continue; +extern sc_pref sc_main_debug_quit; // tools const QString sc_main_tools ("main_tools"); -const sc_pref sc_main_tools_start_profiler (sc_main_tools + ":start_profiler", CTRL_SHIFT + Qt::Key_P); -const sc_pref sc_main_tools_resume_profiler (sc_main_tools + ":resume_profiler", QKeySequence::UnknownKey); -const sc_pref sc_main_tools_show_profiler (sc_main_tools + ":show_profiler", Qt::AltModifier + Qt::ShiftModifier + Qt::Key_P); +extern sc_pref sc_main_tools_start_profiler; +extern sc_pref sc_main_tools_resume_profiler; +extern sc_pref sc_main_tools_show_profiler; // window const QString sc_main_window ("main_window"); -const sc_pref sc_main_window_show_command (sc_main_window + ":show_command", PRE + CTRL_SHIFT + Qt::Key_0); -const sc_pref sc_main_window_show_history (sc_main_window + ":show_history", PRE + CTRL_SHIFT + Qt::Key_1); -const sc_pref sc_main_window_show_file_browser (sc_main_window + ":show_file_browser", PRE + CTRL_SHIFT + Qt::Key_2); -const sc_pref sc_main_window_show_workspace (sc_main_window + ":show_workspace", PRE + CTRL_SHIFT + Qt::Key_3); -const sc_pref sc_main_window_show_editor (sc_main_window + ":show_editor", PRE + CTRL_SHIFT + Qt::Key_4); -const sc_pref sc_main_window_show_doc (sc_main_window + ":show_doc", PRE + CTRL_SHIFT + Qt::Key_5); -const sc_pref sc_main_window_show_variable_editor (sc_main_window + ":show_variable_editor", PRE + CTRL_SHIFT + Qt::Key_6); -const sc_pref sc_main_window_command (sc_main_window + ":command", PRE + CTRL + Qt::Key_0); -const sc_pref sc_main_window_history (sc_main_window + ":history", PRE + CTRL + Qt::Key_1); -const sc_pref sc_main_window_file_browser (sc_main_window + ":file_browser", PRE + CTRL + Qt::Key_2); -const sc_pref sc_main_window_workspace (sc_main_window + ":workspace", PRE + CTRL + Qt::Key_3); -const sc_pref sc_main_window_editor (sc_main_window + ":editor", PRE + CTRL + Qt::Key_4); -const sc_pref sc_main_window_doc (sc_main_window + ":doc", PRE + CTRL + Qt::Key_5); -const sc_pref sc_main_window_variable_editor (sc_main_window + ":variable_editor", PRE + CTRL + Qt::Key_6); -const sc_pref sc_main_window_previous_dock (sc_main_window + ":previous_widget", PRE + CTRL_ALT + Qt::Key_P); -const sc_pref sc_main_window_reset (sc_main_window + ":reset", QKeySequence::UnknownKey); +extern sc_pref sc_main_window_show_command; +extern sc_pref sc_main_window_show_history; +extern sc_pref sc_main_window_show_file_browser; +extern sc_pref sc_main_window_show_workspace; +extern sc_pref sc_main_window_show_editor; +extern sc_pref sc_main_window_show_doc; +extern sc_pref sc_main_window_show_variable_editor; +extern sc_pref sc_main_window_command; +extern sc_pref sc_main_window_history; +extern sc_pref sc_main_window_file_browser; +extern sc_pref sc_main_window_workspace; +extern sc_pref sc_main_window_editor; +extern sc_pref sc_main_window_doc; +extern sc_pref sc_main_window_variable_editor; +extern sc_pref sc_main_window_previous_dock; +extern sc_pref sc_main_window_reset; // help const QString sc_main_help ("main_help"); -const sc_pref sc_main_help_ondisk_doc (sc_main_help + ":ondisk_doc", QKeySequence::UnknownKey); -const sc_pref sc_main_help_online_doc (sc_main_help + ":online_doc", QKeySequence::UnknownKey); -const sc_pref sc_main_help_report_bug (sc_main_help + ":report_bug", QKeySequence::UnknownKey); -const sc_pref sc_main_help_packages (sc_main_help + ":packages", QKeySequence::UnknownKey); -const sc_pref sc_main_help_contribute (sc_main_help + ":contribute", QKeySequence::UnknownKey); -const sc_pref sc_main_help_developer (sc_main_help + ":developer", QKeySequence::UnknownKey); -const sc_pref sc_main_help_about (sc_main_help + ":about", QKeySequence::UnknownKey); +extern sc_pref sc_main_help_ondisk_doc; +extern sc_pref sc_main_help_online_doc; +extern sc_pref sc_main_help_report_bug; +extern sc_pref sc_main_help_packages; +extern sc_pref sc_main_help_contribute; +extern sc_pref sc_main_help_developer; +extern sc_pref sc_main_help_about; // news const QString sc_main_news ("main_news"); -const sc_pref sc_main_news_release_notes (sc_main_news + ":release_notes", QKeySequence::UnknownKey); -const sc_pref sc_main_news_community_news (sc_main_news + ":community_news", QKeySequence::UnknownKey); +extern sc_pref sc_main_news_release_notes; +extern sc_pref sc_main_news_community_news; // Tab handling // The following shortcuts are moved into a separate tab. The key names // are not change for preserving compatibility with older versions const QString sc_edit_file ("editor_file"); const QString sc_edit_file_cl (sc_edit_file + ":close"); -const sc_pref sc_edit_file_close (sc_edit_file_cl, QKeySequence::Close); -const sc_pref sc_edit_file_close_all (sc_edit_file_cl + "_all", QKeySequence::UnknownKey); -const sc_pref sc_edit_file_close_other (sc_edit_file_cl + "_other", QKeySequence::UnknownKey); +extern sc_pref sc_edit_file_close; +extern sc_pref sc_edit_file_close_all; +extern sc_pref sc_edit_file_close_other; const QString sc_edit_tabs ("editor_tabs"); -const sc_pref sc_edit_tabs_switch_left_tab (sc_edit_tabs + ":switch_left_tab", CTRL + Qt::Key_PageUp); -const sc_pref sc_edit_tabs_switch_right_tab (sc_edit_tabs + ":switch_right_tab", CTRL + Qt::Key_PageDown); -const sc_pref sc_edit_tabs_move_tab_left (sc_edit_tabs + ":move_tab_left", Qt::AltModifier + Qt::Key_PageUp); -const sc_pref sc_edit_tabs_move_tab_right (sc_edit_tabs + ":move_tab_right", Qt::AltModifier + Qt::Key_PageDown); +extern sc_pref sc_edit_tabs_switch_left_tab; +extern sc_pref sc_edit_tabs_switch_right_tab; +extern sc_pref sc_edit_tabs_move_tab_left; +extern sc_pref sc_edit_tabs_move_tab_right; // Zooming const QString sc_edit_zoom ("editor_zoom"); // only a group name in the pref dialog const QString sc_edit_view ("editor_view"); const QString sc_edit_view_zoom (sc_edit_view + ":zoom"); -const sc_pref sc_edit_view_zoom_in (sc_edit_view_zoom + "_in", QKeySequence::ZoomIn); -const sc_pref sc_edit_view_zoom_out (sc_edit_view_zoom + "_out", QKeySequence::ZoomOut); +extern sc_pref sc_edit_view_zoom_in; +extern sc_pref sc_edit_view_zoom_out; #if defined (Q_OS_MAC) -const sc_pref sc_edit_view_zoom_normal (sc_edit_view_zoom + "_normal", CTRL + Qt::Key_Underscore); +extern sc_pref sc_edit_view_zoom_normal; #else -const sc_pref sc_edit_view_zoom_normal (sc_edit_view_zoom + "_normal", CTRL + Qt::Key_Period); +extern sc_pref sc_edit_view_zoom_normal; #endif // Actions of the editor // file -const sc_pref sc_edit_file_edit_function (sc_edit_file + ":edit_function", CTRL + Qt::Key_E); -const sc_pref sc_edit_file_save (sc_edit_file + ":save", QKeySequence::Save); -const sc_pref sc_edit_file_save_as (sc_edit_file + ":save_as", QKeySequence::SaveAs); -const sc_pref sc_edit_file_print (sc_edit_file + ":print", QKeySequence::Print); +extern sc_pref sc_edit_file_edit_function; +extern sc_pref sc_edit_file_save; +extern sc_pref sc_edit_file_save_as; +extern sc_pref sc_edit_file_print; // edit const QString sc_edit_find ("editor_find"); // only a group name in the pref dialog const QString sc_edit_edit ("editor_edit"); const QString sc_edit_edit_find (sc_edit_edit + ":find"); -const sc_pref sc_edit_edit_redo (sc_edit_edit + ":redo", QKeySequence::Redo); -const sc_pref sc_edit_edit_cut (sc_edit_edit + ":cut", QKeySequence::Cut); -const sc_pref sc_edit_edit_find_replace (sc_edit_edit_find + "_replace", QKeySequence::Find); -const sc_pref sc_edit_edit_find_next (sc_edit_edit_find + "_next", QKeySequence::FindNext); -const sc_pref sc_edit_edit_find_previous (sc_edit_edit_find + "_previous", QKeySequence::FindPrevious); -const sc_pref sc_edit_edit_delete_start_word (sc_edit_edit + ":delete_start_word", QKeySequence::DeleteStartOfWord); -const sc_pref sc_edit_edit_delete_end_word (sc_edit_edit + ":delete_end_word", QKeySequence::DeleteEndOfWord); -const sc_pref sc_edit_edit_delete_start_line (sc_edit_edit + ":delete_start_line", CTRL_SHIFT + Qt::Key_Backspace); -const sc_pref sc_edit_edit_delete_end_line (sc_edit_edit + ":delete_end_line", CTRL_SHIFT + Qt::Key_Delete); -const sc_pref sc_edit_edit_delete_line (sc_edit_edit + ":delete_line", CTRL_SHIFT + Qt::Key_L); -const sc_pref sc_edit_edit_copy_line (sc_edit_edit + ":copy_line", CTRL_SHIFT + Qt::Key_C); -const sc_pref sc_edit_edit_cut_line (sc_edit_edit + ":cut_line", CTRL_SHIFT + Qt::Key_X); -const sc_pref sc_edit_edit_duplicate_selection (sc_edit_edit + ":duplicate_selection", CTRL + Qt::Key_D); -const sc_pref sc_edit_edit_transpose_line (sc_edit_edit + ":transpose_line", CTRL + Qt::Key_T); -const sc_pref sc_edit_edit_completion_list (sc_edit_edit + ":completion_list", CTRL + Qt::Key_Space); +extern sc_pref sc_edit_edit_redo; +extern sc_pref sc_edit_edit_cut; +extern sc_pref sc_edit_edit_find_replace; +extern sc_pref sc_edit_edit_find_next; +extern sc_pref sc_edit_edit_find_previous; +extern sc_pref sc_edit_edit_delete_start_word; +extern sc_pref sc_edit_edit_delete_end_word; +extern sc_pref sc_edit_edit_delete_start_line; +extern sc_pref sc_edit_edit_delete_end_line; +extern sc_pref sc_edit_edit_delete_line; +extern sc_pref sc_edit_edit_copy_line; +extern sc_pref sc_edit_edit_cut_line; +extern sc_pref sc_edit_edit_duplicate_selection; +extern sc_pref sc_edit_edit_transpose_line; +extern sc_pref sc_edit_edit_completion_list; -const sc_pref sc_edit_edit_comment_selection (sc_edit_edit + ":comment_selection", CTRL + Qt::Key_R); -const sc_pref sc_edit_edit_uncomment_selection (sc_edit_edit + ":uncomment_selection", CTRL_SHIFT + Qt::Key_R); -const sc_pref sc_edit_edit_comment_var_selection (sc_edit_edit + ":comment_var_selection", CTRL_ALT + Qt::Key_R); -const sc_pref sc_edit_edit_upper_case (sc_edit_edit + ":upper_case", CTRL + Qt::Key_U); -const sc_pref sc_edit_edit_lower_case (sc_edit_edit + ":lower_case", CTRL_ALT + Qt::Key_U); +extern sc_pref sc_edit_edit_comment_selection; +extern sc_pref sc_edit_edit_uncomment_selection; +extern sc_pref sc_edit_edit_comment_var_selection; +extern sc_pref sc_edit_edit_upper_case; +extern sc_pref sc_edit_edit_lower_case; #if defined (Q_OS_MAC) -const sc_pref sc_edit_edit_indent_selection (sc_edit_edit + ":indent_selection", PRE + Qt::Key_Tab); -const sc_pref sc_edit_edit_unindent_selection (sc_edit_edit + ":unindent_selection", PRE + Qt::ShiftModifier + Qt::Key_Tab); +extern sc_pref sc_edit_edit_indent_selection; +extern sc_pref sc_edit_edit_unindent_selection; #else -const sc_pref sc_edit_edit_indent_selection (sc_edit_edit + ":indent_selection", CTRL + Qt::Key_Tab); -const sc_pref sc_edit_edit_unindent_selection (sc_edit_edit + ":unindent_selection", CTRL_SHIFT + Qt::Key_Tab); +extern sc_pref sc_edit_edit_indent_selection; +extern sc_pref sc_edit_edit_unindent_selection; #endif -const sc_pref sc_edit_edit_smart_indent_line_or_selection (sc_edit_edit + ":smart_indent_line_or_selection", QKeySequence::UnknownKey); +extern sc_pref sc_edit_edit_smart_indent_line_or_selection; -const sc_pref sc_edit_edit_conv_eol_winows (sc_edit_edit + ":conv_eol_winows", QKeySequence::UnknownKey); -const sc_pref sc_edit_edit_conv_eol_unix (sc_edit_edit + ":conv_eol_unix", QKeySequence::UnknownKey); -const sc_pref sc_edit_edit_conv_eol_mac (sc_edit_edit + ":conv_eol_mac", QKeySequence::UnknownKey); +extern sc_pref sc_edit_edit_conv_eol_winows; +extern sc_pref sc_edit_edit_conv_eol_unix; +extern sc_pref sc_edit_edit_conv_eol_mac; -const sc_pref sc_edit_edit_goto_line (sc_edit_edit + ":goto_line", CTRL + Qt::Key_L); -const sc_pref sc_edit_edit_move_to_brace (sc_edit_edit + ":move_to_brace", CTRL + Qt::Key_M); -const sc_pref sc_edit_edit_select_to_brace (sc_edit_edit + ":select_to_brace", CTRL_SHIFT + Qt::Key_M); -const sc_pref sc_edit_edit_toggle_bookmark (sc_edit_edit + ":toggle_bookmark", PRE + Qt::Key_F7); -const sc_pref sc_edit_edit_next_bookmark (sc_edit_edit + ":next_bookmark", PRE + Qt::Key_F2); -const sc_pref sc_edit_edit_previous_bookmark (sc_edit_edit + ":previous_bookmark", PRE + Qt::SHIFT + Qt::Key_F2); -const sc_pref sc_edit_edit_remove_bookmark (sc_edit_edit + ":remove_bookmark", QKeySequence::UnknownKey); +extern sc_pref sc_edit_edit_goto_line; +extern sc_pref sc_edit_edit_move_to_brace; +extern sc_pref sc_edit_edit_select_to_brace; +extern sc_pref sc_edit_edit_toggle_bookmark; +extern sc_pref sc_edit_edit_next_bookmark; +extern sc_pref sc_edit_edit_previous_bookmark; +extern sc_pref sc_edit_edit_remove_bookmark; -const sc_pref sc_edit_edit_preferences (sc_edit_edit + ":preferences", QKeySequence::UnknownKey); -const sc_pref sc_edit_edit_styles_preferences (sc_edit_edit + ":styles_preferences", QKeySequence::UnknownKey); +extern sc_pref sc_edit_edit_preferences; +extern sc_pref sc_edit_edit_styles_preferences; // view -const sc_pref sc_edit_view_show_line_numbers (sc_edit_view + ":show_line_numbers", QKeySequence::UnknownKey); -const sc_pref sc_edit_view_show_white_spaces (sc_edit_view + ":show_white_spaces", QKeySequence::UnknownKey); -const sc_pref sc_edit_view_show_eol_chars (sc_edit_view + ":show_eol_chars", QKeySequence::UnknownKey); -const sc_pref sc_edit_view_show_ind_guides (sc_edit_view + ":show_ind_guides", QKeySequence::UnknownKey); -const sc_pref sc_edit_view_show_long_line (sc_edit_view + ":show_long_line", QKeySequence::UnknownKey); -const sc_pref sc_edit_view_show_toolbar (sc_edit_view + ":show_toolbar", QKeySequence::UnknownKey); -const sc_pref sc_edit_view_show_statusbar (sc_edit_view + ":show_statusbar", QKeySequence::UnknownKey); -const sc_pref sc_edit_view_show_hscrollbar (sc_edit_view + ":show_hscrollbar", QKeySequence::UnknownKey); -const sc_pref sc_edit_view_sort_tabs (sc_edit_view + ":sort_tabs", QKeySequence::UnknownKey); +extern sc_pref sc_edit_view_show_line_numbers; +extern sc_pref sc_edit_view_show_white_spaces; +extern sc_pref sc_edit_view_show_eol_chars; +extern sc_pref sc_edit_view_show_ind_guides; +extern sc_pref sc_edit_view_show_long_line; +extern sc_pref sc_edit_view_show_toolbar; +extern sc_pref sc_edit_view_show_statusbar; +extern sc_pref sc_edit_view_show_hscrollbar; +extern sc_pref sc_edit_view_sort_tabs; // debug const QString sc_edit_debug ("editor_debug"); -const sc_pref sc_edit_debug_toggle_breakpoint (sc_edit_debug + ":toggle_breakpoint", QKeySequence::UnknownKey); -const sc_pref sc_edit_debug_next_breakpoint (sc_edit_debug + ":next_breakpoint", QKeySequence::UnknownKey); -const sc_pref sc_edit_debug_previous_breakpoint (sc_edit_debug + ":previous_breakpoint", QKeySequence::UnknownKey); -const sc_pref sc_edit_debug_remove_breakpoints (sc_edit_debug + ":remove_breakpoints", QKeySequence::UnknownKey); +extern sc_pref sc_edit_debug_toggle_breakpoint; +extern sc_pref sc_edit_debug_next_breakpoint; +extern sc_pref sc_edit_debug_previous_breakpoint; +extern sc_pref sc_edit_debug_remove_breakpoints; // run const QString sc_edit_run ("editor_run"); -const sc_pref sc_edit_run_run_file (sc_edit_run + ":run_file", PRE + Qt::Key_F5); -const sc_pref sc_edit_run_run_selection (sc_edit_run + ":run_selection", PRE + Qt::Key_F9); +extern sc_pref sc_edit_run_run_file; +extern sc_pref sc_edit_run_run_selection; // help const QString sc_edit_help ("editor_help"); -const sc_pref sc_edit_help_help_keyword (sc_edit_help + ":help_keyword", QKeySequence::HelpContents); -const sc_pref sc_edit_help_doc_keyword (sc_edit_help + ":doc_keyword", Qt::SHIFT + Qt::Key_F1); +extern sc_pref sc_edit_help_help_keyword; +extern sc_pref sc_edit_help_doc_keyword; // Documentation browser const QString sc_doc ("doc_browser"); -const sc_pref sc_doc_go_home (sc_doc + ":go_home", Qt::AltModifier + Qt::Key_Home); -const sc_pref sc_doc_go_back (sc_doc + ":go_back", QKeySequence::Back); -const sc_pref sc_doc_go_next (sc_doc + ":go_next", QKeySequence::Forward); -const sc_pref sc_doc_bookmark (sc_doc + ":bookmark", CTRL + Qt::Key_D); +extern sc_pref sc_doc_go_home; +extern sc_pref sc_doc_go_back; +extern sc_pref sc_doc_go_next; +extern sc_pref sc_doc_bookmark; // Other normal, shortcut related options @@ -268,4 +270,6 @@ const gui_pref sc_prevent_rl_conflicts_menu ("shortcuts/prevent_readline_conflicts_menu", QVariant (false)); +extern QString get_shortcut_section (const QString& key); + #endif diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/gui-preferences-sd.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/gui-preferences-sd.cc Fri May 12 08:03:14 2023 +0200 @@ -0,0 +1,41 @@ +//////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2017-2023 The Octave Project Developers +// +// See the file COPYRIGHT.md in the top-level directory of this +// distribution or . +// +// 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 +// . +// +//////////////////////////////////////////////////////////////////////// + +#if defined (HAVE_CONFIG_H) +# include "config.h" +#endif + +#include "gui-preferences-sd.h" + +// Settings dialog + +gui_pref +sd_geometry ("settings/geometry", QVariant ()); + +gui_pref +sd_last_tab ("settings/last_tab", QVariant (0)); + +gui_pref +sd_last_editor_styles_tab ("settings/last_editor_styles_tab", QVariant (0)); diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/gui-preferences-sd.h --- a/libgui/src/gui-preferences-sd.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/gui-preferences-sd.h Fri May 12 08:03:14 2023 +0200 @@ -30,37 +30,39 @@ // Settings dialog -const gui_pref -sd_geometry ("settings/geometry", QVariant ()); +extern gui_pref sd_geometry; -const gui_pref -sd_last_tab ("settings/last_tab", QVariant (0)); +extern gui_pref sd_last_tab; -const gui_pref -sd_last_editor_styles_tab ("settings/last_editor_styles_tab", QVariant (0)); +extern gui_pref sd_last_editor_styles_tab; // Textstrings for second color schemes -const QString settings_color_modes = QT_TRANSLATE_NOOP ( - "octave::settings_dialog", - "Second color mode (light/dark)"); -const QString settings_color_modes_tooltip = QT_TRANSLATE_NOOP ( - "octave::settings_dialog", - "Switches to another set of colors.\n" - "Useful for defining a dark/light mode.\n" - "Discards non-applied current changes!"); -const QString settings_reload_colors = QT_TRANSLATE_NOOP ( - "octave::settings_dialog", - "&Reload default colors"); -const QString settings_reload_colors_tooltip = QT_TRANSLATE_NOOP ( - "octave::settings_dialog", - "Reloads the default colors,\n" - "depending on currently selected mode."); -const QString settings_reload_styles = QT_TRANSLATE_NOOP ( - "octave::settings_dialog", - "&Reload default styles"); -const QString settings_reload_styles_tooltip = QT_TRANSLATE_NOOP ( - "octave::settings_dialog", - "Reloads the default values of the styles,\n" - "depending on currently selected mode."); +const QString settings_color_modes + = QT_TRANSLATE_NOOP ("octave::settings_dialog", + "Second color mode (light/dark)"); + +const QString settings_color_modes_tooltip + = QT_TRANSLATE_NOOP ("octave::settings_dialog", + "Switches to another set of colors.\n" + "Useful for defining a dark/light mode.\n" + "Discards non-applied current changes!"); + +const QString settings_reload_colors + = QT_TRANSLATE_NOOP ("octave::settings_dialog", + "&Reload default colors"); + +const QString settings_reload_colors_tooltip + = QT_TRANSLATE_NOOP ("octave::settings_dialog", + "Reloads the default colors,\n" + "depending on currently selected mode."); + +const QString settings_reload_styles + = QT_TRANSLATE_NOOP ("octave::settings_dialog", + "&Reload default styles"); + +const QString settings_reload_styles_tooltip + = QT_TRANSLATE_NOOP ("octave::settings_dialog", + "Reloads the default values of the styles,\n" + "depending on currently selected mode."); #endif diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/gui-preferences-ve.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/gui-preferences-ve.cc Fri May 12 08:03:14 2023 +0200 @@ -0,0 +1,69 @@ +//////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2017-2023 The Octave Project Developers +// +// See the file COPYRIGHT.md in the top-level directory of this +// distribution or . +// +// 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 +// . +// +//////////////////////////////////////////////////////////////////////// + +#if defined (HAVE_CONFIG_H) +# include "config.h" +#endif + +#include "gui-preferences-ve.h" + +#include + +// Variable Editor preferences + +gui_pref +ve_use_terminal_font ("variable_editor/use_terminal_font", QVariant (true)); + +gui_pref +ve_font_name ("variable_editor/font_name", QVariant ()); + +gui_pref +ve_font_size ("variable_editor/font_size", QVariant (10)); + +gui_pref +ve_column_width ("variable_editor/column_width", QVariant (100)); + +gui_pref +ve_row_height ("variable_editor/row_height", QVariant (10)); + +gui_pref +ve_alternate_rows ("variable_editor/alternate_rows", QVariant (false)); + +gui_pref +ve_color_mode ("variable_editor/color_mode", QVariant (0)); + +gui_pref ve_colors[2*ve_colors_count] = +{ + {"variable_editor/color_f" + settings_color_modes_ext[0], QVariant (QPalette::WindowText)}, + {"variable_editor/color_b" + settings_color_modes_ext[0], QVariant (QPalette::Base)}, + {"variable_editor/color_s" + settings_color_modes_ext[0], QVariant (QPalette::HighlightedText)}, + {"variable_editor/color_h" + settings_color_modes_ext[0], QVariant (QPalette::Highlight)}, + {"variable_editor/color_a" + settings_color_modes_ext[0], QVariant (QPalette::AlternateBase)}, + {"variable_editor/color_f" + settings_color_modes_ext[1], QVariant ()}, + {"variable_editor/color_b" + settings_color_modes_ext[1], QVariant ()}, + {"variable_editor/color_s" + settings_color_modes_ext[1], QVariant ()}, + {"variable_editor/color_h" + settings_color_modes_ext[1], QVariant ()}, + {"variable_editor/color_a" + settings_color_modes_ext[1], QVariant ()} +}; diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/gui-preferences-ve.h --- a/libgui/src/gui-preferences-ve.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/gui-preferences-ve.h Fri May 12 08:03:14 2023 +0200 @@ -27,48 +27,29 @@ #define octave_gui_preferences_ve_h 1 #include "gui-preferences.h" - -#include +#include "gui-settings.h" // Variable Editor preferences -const gui_pref -ve_use_terminal_font ("variable_editor/use_terminal_font", QVariant (true)); +extern gui_pref ve_use_terminal_font; -const gui_pref -ve_font_name ("variable_editor/font_name", QVariant ()); +extern gui_pref ve_font_name; -const gui_pref -ve_font_size ("variable_editor/font_size", QVariant (10)); +extern gui_pref ve_font_size; -const gui_pref -ve_column_width ("variable_editor/column_width", QVariant (100)); +extern gui_pref ve_column_width; -const gui_pref -ve_row_height ("variable_editor/row_height", QVariant (10)); +extern gui_pref ve_row_height; -const gui_pref -ve_alternate_rows ("variable_editor/alternate_rows", QVariant (false)); +extern gui_pref ve_alternate_rows; -const gui_pref -ve_color_mode ("variable_editor/color_mode", QVariant (0)); +extern gui_pref ve_color_mode; const QString ve_color_chars ("fbsha"); const int ve_colors_count = 5; -const gui_pref ve_colors[2*ve_colors_count] = -{ - {"variable_editor/color_f" + settings_color_modes_ext[0], QVariant (QPalette::WindowText)}, - {"variable_editor/color_b" + settings_color_modes_ext[0], QVariant (QPalette::Base)}, - {"variable_editor/color_s" + settings_color_modes_ext[0], QVariant (QPalette::HighlightedText)}, - {"variable_editor/color_h" + settings_color_modes_ext[0], QVariant (QPalette::Highlight)}, - {"variable_editor/color_a" + settings_color_modes_ext[0], QVariant (QPalette::AlternateBase)}, - {"variable_editor/color_f" + settings_color_modes_ext[1], QVariant ()}, - {"variable_editor/color_b" + settings_color_modes_ext[1], QVariant ()}, - {"variable_editor/color_s" + settings_color_modes_ext[1], QVariant ()}, - {"variable_editor/color_h" + settings_color_modes_ext[1], QVariant ()}, - {"variable_editor/color_a" + settings_color_modes_ext[1], QVariant ()} -}; + +extern gui_pref ve_colors[]; const QStringList ve_color_names = { QT_TRANSLATE_NOOP ("octave::settings_dialog", "Foreground"), diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/gui-preferences-ws.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/gui-preferences-ws.cc Fri May 12 08:03:14 2023 +0200 @@ -0,0 +1,73 @@ +//////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2017-2023 The Octave Project Developers +// +// See the file COPYRIGHT.md in the top-level directory of this +// distribution or . +// +// 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 +// . +// +//////////////////////////////////////////////////////////////////////// + +#if defined (HAVE_CONFIG_H) +# include "config.h" +#endif + +#include "gui-preferences-ws.h" +#include "gui-settings.h" + +// Workspace view + +gui_pref +ws_enable_colors ("workspaceview/enable_colors", QVariant (false)); + +gui_pref +ws_hide_tool_tips ("workspaceview/hide_tools_tips", QVariant (false)); + +gui_pref +ws_filter_active ("workspaceview/filter_active", QVariant (false)); + +gui_pref +ws_filter_shown ("workspaceview/filter_shown", QVariant (true)); + +gui_pref +ws_column_state ("workspaceview/column_state", QVariant ()); + +gui_pref +ws_sort_column ("workspaceview/sort_by_column", QVariant (0)); + +gui_pref +ws_sort_order ("workspaceview/sort_order", QVariant (Qt::AscendingOrder)); + +gui_pref +ws_mru_list ("workspaceview/mru_list", QVariant ()); + +gui_pref +ws_max_filter_history ("workspaceview/max_filter_history", QVariant (10)); + +gui_pref +ws_color_mode ("workspaceview/color_mode", QVariant (0)); + +gui_pref ws_colors[2*ws_colors_count] = +{ + {"workspaceview/color_a" + settings_color_modes_ext[0], QVariant (QPalette::Highlight)}, + {"workspaceview/color_g" + settings_color_modes_ext[0], QVariant (QPalette::Midlight)}, + {"workspaceview/color_p" + settings_color_modes_ext[0], QVariant (QPalette::Dark)}, + {"workspaceview/color_a" + settings_color_modes_ext[1], QVariant ()}, + {"workspaceview/color_g" + settings_color_modes_ext[1], QVariant ()}, + {"workspaceview/color_p" + settings_color_modes_ext[1], QVariant ()} +}; diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/gui-preferences-ws.h --- a/libgui/src/gui-preferences-ws.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/gui-preferences-ws.h Fri May 12 08:03:14 2023 +0200 @@ -27,33 +27,24 @@ #define octave_gui_preferences_ws_h 1 #include "gui-preferences.h" -#include "gui-settings.h" // Workspace view -const gui_pref -ws_enable_colors ("workspaceview/enable_colors", QVariant (false)); +extern gui_pref ws_enable_colors; -const gui_pref -ws_hide_tool_tips ("workspaceview/hide_tools_tips", QVariant (false)); +extern gui_pref ws_hide_tool_tips; -const gui_pref -ws_filter_active ("workspaceview/filter_active", QVariant (false)); +extern gui_pref ws_filter_active; -const gui_pref -ws_filter_shown ("workspaceview/filter_shown", QVariant (true)); +extern gui_pref ws_filter_shown; -const gui_pref -ws_column_state ("workspaceview/column_state", QVariant ()); +extern gui_pref ws_column_state; -const gui_pref -ws_sort_column ("workspaceview/sort_by_column", QVariant (0)); +extern gui_pref ws_sort_column; -const gui_pref -ws_sort_order ("workspaceview/sort_order", QVariant (Qt::AscendingOrder)); +extern gui_pref ws_sort_order; -const gui_pref -ws_mru_list ("workspaceview/mru_list", QVariant ()); +extern gui_pref ws_mru_list; const QStringList ws_columns_shown = { QT_TRANSLATE_NOOP ("octave::workspace_view", "Class"), @@ -69,22 +60,13 @@ "workspaceview/show_attribute" }; -const gui_pref -ws_max_filter_history ("workspaceview/max_filter_history", QVariant (10)); +extern gui_pref ws_max_filter_history; -const gui_pref -ws_color_mode ("workspaceview/color_mode", QVariant (0)); +extern gui_pref ws_color_mode; const int ws_colors_count = 3; -const gui_pref ws_colors[2*ws_colors_count] = -{ - {"workspaceview/color_a" + settings_color_modes_ext[0], QVariant (QPalette::Highlight)}, - {"workspaceview/color_g" + settings_color_modes_ext[0], QVariant (QPalette::Midlight)}, - {"workspaceview/color_p" + settings_color_modes_ext[0], QVariant (QPalette::Dark)}, - {"workspaceview/color_a" + settings_color_modes_ext[1], QVariant ()}, - {"workspaceview/color_g" + settings_color_modes_ext[1], QVariant ()}, - {"workspaceview/color_p" + settings_color_modes_ext[1], QVariant ()} -}; + +extern gui_pref ws_colors[]; const QString ws_class_chars ("agp"); diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/gui-preferences.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/gui-preferences.cc Fri May 12 08:03:14 2023 +0200 @@ -0,0 +1,173 @@ +//////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2017-2023 The Octave Project Developers +// +// See the file COPYRIGHT.md in the top-level directory of this +// distribution or . +// +// 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 +// . +// +//////////////////////////////////////////////////////////////////////// + +#if defined (HAVE_CONFIG_H) +# include "config.h" +#endif + +#include "gui-preferences-sc.h" +#include "gui-preferences.h" + +gui_pref::gui_pref (const QString& settings_key, const QVariant& def, + bool ignore) + : m_settings_key (settings_key), m_def (def), m_ignore (ignore) +{ + all_gui_preferences::insert (settings_key, *this); +} + +all_gui_preferences *all_gui_preferences::s_instance = nullptr; + +void all_gui_preferences::insert (const QString& settings_key, + const gui_pref& pref) +{ + ensure_instance (); + + s_instance->do_insert (settings_key, pref); +} + +const gui_pref all_gui_preferences::value (const QString& settings_key) +{ + ensure_instance (); + + return s_instance->do_value (settings_key); +} + +QStringList all_gui_preferences::keys () +{ + ensure_instance (); + + return s_instance->do_keys (); +} + +void all_gui_preferences::do_insert (const QString& settings_key, + const gui_pref& pref) +{ + m_hash.insert (settings_key, pref); +} + +const gui_pref +all_gui_preferences::do_value (const QString& settings_key) const +{ + return m_hash.value (settings_key); +} + +QStringList all_gui_preferences::do_keys () const +{ + return m_hash.keys (); +} + +void all_gui_preferences::ensure_instance () +{ + if (! s_instance) + s_instance = new all_gui_preferences (); +} + +sc_pref::sc_pref (const QString& description, const QString& settings_key, + Qt::Key def) + : m_description (description), m_settings_key (settings_key), m_def (def), + m_def_std (QKeySequence::UnknownKey) +{ + all_shortcut_preferences::insert (settings_key, *this); +} + +sc_pref::sc_pref (const QString& description, const QString& settings_key, + unsigned int def) + : m_description (description), m_settings_key (settings_key), m_def (def), + m_def_std (QKeySequence::UnknownKey) +{ + all_shortcut_preferences::insert (settings_key, *this); +} + +sc_pref::sc_pref (const QString& description, const QString& settings_key, + QKeySequence::StandardKey def_std) + : m_description (description), m_settings_key (settings_key), m_def (0), + m_def_std (def_std) +{ + all_shortcut_preferences::insert (settings_key, *this); +} + +QKeySequence sc_pref::def_value () const +{ + QKeySequence key_seq = QKeySequence (); + + if (m_def) + key_seq = QKeySequence (m_def); + else if (m_def_std != QKeySequence::UnknownKey) + key_seq = QKeySequence (m_def_std); + + return key_seq; +} + +QString sc_pref::def_text () const +{ + return def_value ().toString (); +} + +all_shortcut_preferences *all_shortcut_preferences::s_instance = nullptr; + +void all_shortcut_preferences::insert (const QString& settings_key, + const sc_pref& scpref) +{ + ensure_instance (); + + s_instance->do_insert (settings_key, scpref); +} + +const sc_pref all_shortcut_preferences::value (const QString& settings_key) +{ + ensure_instance (); + + return s_instance->do_value (settings_key); +} + +QStringList all_shortcut_preferences::keys () +{ + ensure_instance (); + + return s_instance->do_keys (); +} + +void all_shortcut_preferences::do_insert (const QString& settings_key, + const sc_pref& scpref) +{ + m_hash.insert (settings_key, scpref); +} + +const sc_pref +all_shortcut_preferences::do_value (const QString& settings_key) const +{ + return m_hash.value (settings_key); +} + +QStringList all_shortcut_preferences::do_keys () const +{ + return m_hash.keys (); +} + +void all_shortcut_preferences::ensure_instance () +{ + if (! s_instance) + s_instance = new all_shortcut_preferences (); +} diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/gui-preferences.h --- a/libgui/src/gui-preferences.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/gui-preferences.h Fri May 12 08:03:14 2023 +0200 @@ -26,66 +26,187 @@ #if ! defined (octave_gui_preferences_h) #define octave_gui_preferences_h 1 +#include "octave-config.h" + #include #include #include -#include #include +// FIXME: Would it be possible/make sense to merge gui_pref and sc_pref +// into a single class or to at least have them derived from a common +// base class so we could have one global hash table that contains all +// of them? + // Structure for the definition of pairs: key and default value -struct gui_pref +class gui_pref { - gui_pref (const QString& key_arg, const QVariant& def_arg, - const bool ignore_arg = false) - : key (key_arg), def (def_arg), ignore (ignore_arg) - { } +public: + + // Default constructed gui_pref objects are invalid, but we need this + // to create QHash objects that contain gui_pref objects. No invalid + // gui_pref objects should acutally be used. + + gui_pref () = default; + + gui_pref (const QString& settings_key, const QVariant& def, + bool ignore = false); + + gui_pref (const gui_pref&) = default; + + gui_pref& operator = (const gui_pref&) = default; - // No copying! + ~gui_pref () = default; + + QString settings_key () const { return m_settings_key; } + QVariant def () const { return m_def; } + bool ignore () const { return m_ignore; } + +private: + + // The settings key name. + QString m_settings_key; + + // The default value. + QVariant m_def; + + // TRUE means always take the default. + bool m_ignore; +}; - gui_pref (const gui_pref&) = delete; +// FIXME: Is there a better/more modern way to manage this data than to +// have this style of singleton class? + +// Allow lookup of gui_pref objects when we don't know the name at +// compile time. - gui_pref& operator = (const gui_pref&) = delete; +class all_gui_preferences +{ +public: + + all_gui_preferences () = default; + + OCTAVE_DISABLE_COPY_MOVE (all_gui_preferences) + + ~all_gui_preferences () = default; + + static void insert (const QString& settings_key, const gui_pref& pref); - ~gui_pref (void) = default; + static const gui_pref value (const QString& settings_key); + + static QStringList keys (); + +private: + + // Map from shortcut identifier (settings key) to gui_pref object. + QHash m_hash; - const QString key; // the key name - const QVariant def; // the default value - const bool ignore; // when true, ignore, i.e. always take default + void do_insert (const QString& settings_key, const gui_pref& pref); + + const gui_pref do_value (const QString& settings_key) const; + + QStringList do_keys () const; + + static void ensure_instance (); + + // Map from shortcut identifier (settings key) to sc_pref object. + static all_gui_preferences *s_instance; }; // The version for shortcuts, where the default value is stored as a // combination of Qt:Keys (resutling in an unsigend int, when added) // or as one of the predefined standard key sequences. -const QString sc_group ("shortcuts/"); // group name is handled separately - -struct sc_pref +class sc_pref { - sc_pref (const QString& key_arg, Qt::Key def_arg) - : key (key_arg), def (static_cast (def_arg)), - def_std (QKeySequence::UnknownKey) - { } +public: + + // Default constructed sc_pref objects are invalid, but we need this + // to create QHash objects that contain sc_pref objects. No invalid + // sc_pref objects should acutally be used. + + sc_pref () = default; + + sc_pref (const QString& description, const QString& settings_key, + Qt::Key def); + + sc_pref (const QString& description_arg, const QString& settings_key, + unsigned int def); + + sc_pref (const QString& description_arg, const QString& settings_key, + QKeySequence::StandardKey def_std); + + sc_pref (const sc_pref&) = default; + + sc_pref& operator = (const sc_pref&) = default; - sc_pref (const QString& key_arg, unsigned int def_arg) - : key (key_arg), def (def_arg), def_std (QKeySequence::UnknownKey) - { } + ~sc_pref () = default; + + QString description () const { return m_description; } + + QString settings_key () const { return m_settings_key; } + + unsigned int def () const { return m_def; } + + QKeySequence::StandardKey def_std () const { return m_def_std; } + + QKeySequence def_value () const; + + QString def_text () const; + +private: + + // Description of the shortcut. + QString m_description; + + // The settings key name. + QString m_settings_key; - sc_pref (const QString& key_arg, QKeySequence::StandardKey def_std_arg) - : key (key_arg), def (0), def_std (def_std_arg) - { } + // The default as key. + unsigned int m_def; + + // The default as standard key. + QKeySequence::StandardKey m_def_std; +}; + +// FIXME: Is there a better/more modern way to manage this data than to +// have this style of singleton class? - // No copying! +// Allow lookup of sc_pref objects when we don't know the name at +// compile time. - sc_pref (const sc_pref&) = delete; +class all_shortcut_preferences +{ +public: + + all_shortcut_preferences () = default; + + OCTAVE_DISABLE_COPY_MOVE (all_shortcut_preferences) - sc_pref& operator = (const sc_pref&) = delete; + ~all_shortcut_preferences () = default; + + static void insert (const QString& settings_key, const sc_pref& scpref); - ~sc_pref (void) = default; + static const sc_pref value (const QString& settings_key); + + static QStringList keys (); + +private: - const QString key; // the key name - const unsigned int def; // the default as key - const QKeySequence::StandardKey def_std; // the default as standard key + // Map from shortcut identifier (settings key) to sc_pref object. + QHash m_hash; + + void do_insert (const QString& settings_key, const sc_pref& scpref); + + const sc_pref do_value (const QString& settings_key) const; + + QStringList do_keys () const; + + static void ensure_instance (); + + // Map from shortcut identifier (settings key) to sc_pref object. + static all_shortcut_preferences *s_instance; }; #endif diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/gui-settings.cc --- a/libgui/src/gui-settings.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/gui-settings.cc Fri May 12 08:03:14 2023 +0200 @@ -27,13 +27,97 @@ # include "config.h" #endif +#include +#include +#include + +#include + +#include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include +#include +#include +#include +#include +#include "gui-preferences-cs.h" +#include "gui-preferences-ed.h" +#include "gui-preferences-sc.h" +#include "gui-preferences-global.h" #include "gui-settings.h" +#include "localcharset-wrapper.h" +#include "oct-env.h" +#include "oct-string.h" + +#include "defaults.h" + OCTAVE_BEGIN_NAMESPACE(octave) +QString gui_settings::file_name () const +{ + return fileName (); +} + +QString gui_settings::directory_name () const +{ + QFileInfo sfile (fileName ()); + + return sfile.absolutePath (); +} + +bool gui_settings::bool_value (const gui_pref& pref) const +{ + return value (pref).toBool (); +} + +QByteArray gui_settings::byte_array_value (const gui_pref& pref) const +{ + return value (pref).toByteArray (); +} + +QColor gui_settings::color_value (const gui_pref& pref) const +{ + return value (pref).value (); +} + +QDateTime gui_settings::date_time_value (const gui_pref& pref) const +{ + return value (pref).toDateTime (); +} + +int gui_settings::int_value (const gui_pref& pref) const +{ + return value (pref).toInt (); +} + +QString gui_settings::string_value (const gui_pref& pref) const +{ + return value (pref).toString (); +} + +QStringList gui_settings::string_list_value (const gui_pref& pref) const +{ + return value (pref).toStringList (); +} + +uint gui_settings::uint_value (const gui_pref& pref) const +{ + return value (pref).toUInt (); +} + QColor gui_settings::get_color_value (const QVariant& def, int mode) const { QColor default_color; @@ -47,15 +131,19 @@ // The default colors are given as color roles for // the application's palette default_color = QApplication::palette ().color - (static_cast (def.toInt ())); - // FIXME: use value instead of static cast after - // dropping support of Qt 5.4 + (static_cast (def.toInt ())); + // FIXME: use value instead of static cast after + // dropping support of Qt 5.4 } if ((mode == 1) && (default_color != settings_color_no_change)) { // In second mode, determine the default color from the first mode +#if HAVE_QCOLOR_FLOAT_TYPE + float h, s, l, a; +#else qreal h, s, l, a; +#endif default_color.getHslF (&h, &s, &l, &a); qreal l_new = 1.0-l*0.85; if (l < 0.3) @@ -68,9 +156,9 @@ QColor gui_settings::color_value (const gui_pref& pref, int mode) const { - QColor default_color = get_color_value (pref.def, mode); + QColor default_color = get_color_value (pref.def (), mode); - return value (pref.key + settings_color_modes_ext[mode], + return value (pref.settings_key () + settings_color_modes_ext[mode], QVariant (default_color)).value (); } @@ -81,31 +169,606 @@ if (m > 1) m = 1; - setValue (pref.key + settings_color_modes_ext[m], QVariant (color)); + setValue (pref.settings_key () + settings_color_modes_ext[m], + QVariant (color)); } -QString gui_settings::sc_value (const sc_pref& pref) const +QString gui_settings::sc_value (const sc_pref& scpref) const { - QKeySequence key_seq = sc_def_value (pref); + QKeySequence key_seq = sc_def_value (scpref); // Get the value from the settings where the key sequences are stored // as strings - return value (sc_group + pref.key, key_seq.toString ()).toString (); + return value (sc_group + "/" + scpref.settings_key (), + key_seq.toString ()).toString (); +} + +QKeySequence gui_settings::sc_def_value (const sc_pref& scpref) const +{ + return scpref.def_value (); +} + +void gui_settings::set_shortcut (QAction *action, const sc_pref& scpref, + bool enable) +{ + if (! enable) + { + // Disable => remove existing shortcut from the action + action->setShortcut (QKeySequence ()); + return; + } + + QString shortcut = sc_value (scpref); + + if (! shortcut.isEmpty ()) + action->setShortcut (QKeySequence (shortcut)); + else + qDebug () << "Key: " << scpref.settings_key () + << " not found in settings"; +} + +void gui_settings::shortcut (QShortcut *sc, const sc_pref& scpref) +{ + QString shortcut = sc_value (scpref); + + if (! shortcut.isEmpty ()) + sc->setKey (QKeySequence (shortcut)); + else + qDebug () << "Key: " << scpref.settings_key () + << " not found in settings"; +} + +void gui_settings::config_icon_theme () +{ + int theme_index; + + if (contains (global_icon_theme_index.settings_key ())) + theme_index = int_value (global_icon_theme_index); + else + { + // New pref does not exist. Use old if required. Add new and + // remove deprecated key. + + if (bool_value (global_icon_theme)) + theme_index = ICON_THEME_SYSTEM; + else + theme_index = ICON_THEME_OCTAVE; + + setValue (global_icon_theme_index.settings_key (), theme_index); + remove (global_icon_theme.settings_key ()); + } + + QIcon::setThemeName (global_all_icon_themes.at (theme_index)); + + QStringList icon_fallbacks; + + // Set the required fallback search paths. + + switch (theme_index) + { + case ICON_THEME_SYSTEM: + icon_fallbacks << global_icon_paths.at (ICON_THEME_OCTAVE); + icon_fallbacks << global_icon_paths.at (ICON_THEME_TANGO); + break; + case ICON_THEME_TANGO: + icon_fallbacks << global_icon_paths.at (ICON_THEME_OCTAVE); + break; + case ICON_THEME_OCTAVE: + icon_fallbacks << global_icon_paths.at (ICON_THEME_TANGO); + break; + } + + icon_fallbacks << global_icon_paths.at (ICON_THEME_CURSORS); + + setValue (global_icon_fallbacks.settings_key (), icon_fallbacks); +} + +QIcon gui_settings::icon (const QString& icon_name, bool octave_only, + const QString& icon_alt_name) +{ + if (octave_only) + return QIcon (global_icon_paths.at (ICON_THEME_OCTAVE) + icon_name + ".png"); + + if (QIcon::hasThemeIcon (icon_name)) + return QIcon (QIcon::fromTheme (icon_name)); + else if ((! icon_alt_name.isEmpty ()) && QIcon::hasThemeIcon (icon_alt_name)) + return QIcon (QIcon::fromTheme (icon_alt_name)); + + QStringList icon_fallbacks + = value (global_icon_fallbacks.settings_key ()).toStringList (); + + for (int i = 0; i < icon_fallbacks.length (); i++ ) + { + QString icon_file (icon_fallbacks.at (i) + icon_name + ".png"); + if (QFile (icon_file).exists ()) + return QIcon (icon_file); + } + + //QIcon::setThemeName (current_theme); + return QIcon (); +} + +QString gui_settings::get_default_font_family () +{ + // Get all available fixed width fonts from the Qt font database. + + QFontDatabase font_database; + QStringList fonts; + + for (QString font : font_database.families ()) + { + if (font_database.isFixedPitch (font)) + fonts << font; + } + + QString default_family; + +#if defined (Q_OS_MAC) + // Use hard coded default on macOS, since selection of fixed width + // default font is unreliable (see bug #59128). + // Test for macOS default fixed width font + if (fonts.contains (global_mono_font.def ().toString ())) + default_family = global_mono_font.def ().toString (); +#endif + + // If default font is still empty (on all other platforms or + // if macOS default font is not available): use QFontDatabase + if (default_family.isEmpty ()) + { + // Get the system's default monospaced font + QFont fixed_font = QFontDatabase::systemFont (QFontDatabase::FixedFont); + default_family = fixed_font.defaultFamily (); + + // Since this might be unreliable, test all available fixed width fonts + if (! fonts.contains (default_family)) + { + // Font returned by QFontDatabase is not in fixed fonts list. + // Fallback: take first from this list + default_family = fonts[0]; + } + } + + // Test env variable which has preference + std::string env_default_family = sys::env::getenv ("OCTAVE_DEFAULT_FONT"); + if (! env_default_family.empty ()) + default_family = QString::fromStdString (env_default_family); + + return default_family; +} + +QStringList gui_settings::get_default_font () +{ + QString default_family = get_default_font_family (); + + // determine the fefault font size of the system + // FIXME: QApplication::font () does not return the monospace font, + // but the size should be probably near to the monospace font + QFont font = QApplication::font (); + + int font_size = font.pointSize (); + if (font_size == -1) + font_size = static_cast (std::floor(font.pointSizeF ())); + + // check for valid font size, otherwise take default 10 + QString default_font_size = "10"; + if (font_size > 0) + default_font_size = QString::number (font_size); + + std::string env_default_font_size + = sys::env::getenv ("OCTAVE_DEFAULT_FONT_SIZE"); + + if (! env_default_font_size.empty ()) + default_font_size = QString::fromStdString (env_default_font_size); + + QStringList result; + result << default_family; + result << default_font_size; + return result; +} + +QString gui_settings::get_gui_translation_dir () +{ + // get environment variable for the locale dir (e.g. from run-octave) + std::string dldir = sys::env::getenv ("OCTAVE_LOCALE_DIR"); + if (dldir.empty ()) + dldir = config::oct_locale_dir (); // env-var empty, load the default location + return QString::fromStdString (dldir); +} + +void gui_settings::config_translators (QTranslator *qt_tr, + QTranslator *qsci_tr, + QTranslator *gui_tr) +{ + bool loaded; + + QString qt_trans_dir + = QLibraryInfo::location (QLibraryInfo::TranslationsPath); + + QString language = "SYSTEM"; // take system language per default + + // FIXME: can we somehow ensure that the settings object will always + // be initialize and valid? + + // get the locale from the settings if already available + language = string_value (global_language); + + // load the translations depending on the settings + if (language == "SYSTEM") + { + // get the system locale and pass it to the translators for loading + // the suitable translation files + QLocale sys_locale = QLocale::system (); + + qt_tr->load (sys_locale, "qt", "_", qt_trans_dir); + qsci_tr->load (sys_locale, "qscintilla", "_", qt_trans_dir); + gui_tr->load (sys_locale, "", "", get_gui_translation_dir ()); + } + else + { + // load the translation files depending on the given locale name + loaded = qt_tr->load ("qt_" + language, qt_trans_dir); + if (! loaded) // try lower case + qt_tr->load ("qt_" + language.toLower (), qt_trans_dir); + + loaded = qsci_tr->load ("qscintilla_" + language, qt_trans_dir); + if (! loaded) // try lower case + qsci_tr->load ("qscintilla_" + language.toLower (), qt_trans_dir); + + gui_tr->load (language, get_gui_translation_dir ()); + } + +} + +#if defined (HAVE_QSCINTILLA) +int gui_settings::get_valid_lexer_styles (QsciLexer *lexer, int *styles) +{ + int max_style = 0; + int actual_style = 0; + while (actual_style < ed_max_style_number && max_style < ed_max_lexer_styles) + { + if ((lexer->description (actual_style)) != "") // valid style + styles[max_style++] = actual_style; + actual_style++; + } + return max_style; +} +#endif + +/*! + * Copys the attributes bold, italic and underline from QFont + * @p attr to the font @p base and returns the result without + * changing @p base, + * @param attr QFont with the desired attributes + * @param base QFont with desired family and size + */ +static QFont copy_font_attributes (const QFont& attr, const QFont& base) +{ + QFont dest (base); + + dest.setBold (attr.bold ()); + dest.setItalic (attr.italic ()); + dest.setUnderline (attr.underline ()); + + return dest; } -QKeySequence gui_settings::sc_def_value (const sc_pref& pref) const +#if defined (HAVE_QSCINTILLA) +void gui_settings::read_lexer_settings (QsciLexer *lexer, int mode, int def) +{ + // Test whether the settings for lexer is already contained in the + // given gui settings file. If yes, load them, if not copy them from the + // default settings file. + // This is useful when a new language support is implemented and the + // existing settings file is used (which is of course the common case). + int m = mode; + if (m > 1) + m = 1; + + QString group ("Scintilla" + settings_color_modes_ext[m]); + + beginGroup (group); + beginGroup (lexer->language ()); + + QStringList lexer_keys = allKeys (); + + endGroup (); + endGroup (); + + if (def == settings_reload_default_colors_flag || lexer_keys.count () == 0) + { + // We have to reload the default values or no Lexer keys found: + // If mode == 0, take all settings except font from default lexer + // If Mode == 1, take all settings except font from default lexer + // and convert the color by inverting the lightness + + // Get the default font + QStringList def_font = get_default_font (); + QFont df (def_font[0], def_font[1].toInt ()); + QFont dfa = copy_font_attributes (lexer->defaultFont (), df); + lexer->setDefaultFont (dfa); + + QColor c, p; + + int styles[ed_max_lexer_styles]; // array for saving valid styles + int max_style = get_valid_lexer_styles (lexer, styles); + + for (int i = 0; i < max_style; i++) + { + c = get_color_value (QVariant (lexer->color (styles[i])), m); + lexer->setColor (c, styles[i]); + p = get_color_value (QVariant (lexer->paper (styles[i])), m); + lexer->setPaper (p, styles[i]); + dfa = copy_font_attributes (lexer->font (styles[i]), df); + lexer->setFont (dfa, styles[i]); + } + // Set defaults last for not changing the defaults of the styles + lexer->setDefaultColor (lexer->color (styles[0])); + lexer->setDefaultPaper (lexer->paper (styles[0])); + + // Write settings if not just reload the default values + if (def != settings_reload_default_colors_flag) + { + const std::string group_str = group.toStdString (); + lexer->writeSettings (*this, group_str.c_str ()); + sync (); + } + } + else + { + // Found lexer keys, read the settings + const std::string group_str = group.toStdString (); + lexer->readSettings (*this, group_str.c_str ()); + } +} +#endif + +bool gui_settings::update_settings_key (const QString& old_key, + const QString& new_key) { - QKeySequence key_seq = QKeySequence (); + if (contains (old_key)) + { + QVariant preference = value (old_key); + setValue (new_key, preference); + remove (old_key); + return true; + } + + return false; +} + +void gui_settings::update_network_settings () +{ + QNetworkProxy proxy; + + // Assume no proxy and empty proxy data + QNetworkProxy::ProxyType proxy_type = QNetworkProxy::NoProxy; + QString scheme; + QString host; + int port = 0; + QString user; + QString pass; + QUrl proxy_url = QUrl (); + + if (bool_value (global_use_proxy)) + { + // Use a proxy, collect all required information + QString proxy_type_string = string_value (global_proxy_type); + + // The proxy type for the Qt proxy settings + if (proxy_type_string == "Socks5Proxy") + proxy_type = QNetworkProxy::Socks5Proxy; + else if (proxy_type_string == "HttpProxy") + proxy_type = QNetworkProxy::HttpProxy; + + // The proxy data from the settings + if (proxy_type_string == "HttpProxy" + || proxy_type_string == "Socks5Proxy") + { + host = string_value (global_proxy_host); + port = int_value (global_proxy_port); + user = string_value (global_proxy_user); + pass = string_value (global_proxy_pass); + if (proxy_type_string == "HttpProxy") + scheme = "http"; + else if (proxy_type_string == "Socks5Proxy") + scheme = "socks5"; + + QUrl env_var_url = QUrl (); + proxy_url.setScheme (scheme); + proxy_url.setHost (host); + proxy_url.setPort (port); + if (! user.isEmpty ()) + proxy_url.setUserName (user); + if (! pass.isEmpty ()) + proxy_url.setPassword (pass); + } + + // The proxy data from environment variables + if (proxy_type_string == global_proxy_all_types.at (2)) + { + const std::array env_vars = + { + "ALL_PROXY", "all_proxy", + "HTTP_PROXY", "http_proxy", + "HTTPS_PROXY", "https_proxy" + }; + + unsigned int count = 0; + while (! proxy_url.isValid () && count < env_vars.size ()) + { + proxy_url = QUrl (QString::fromStdString + (sys::env::getenv (env_vars[count]))); + count++; + } + + if (proxy_url.isValid ()) + { + // Found an entry, get the data from the string + scheme = proxy_url.scheme (); + + if (scheme.contains ("socks", Qt::CaseInsensitive)) + proxy_type = QNetworkProxy::Socks5Proxy; + else + proxy_type = QNetworkProxy::HttpProxy; - // Check, which of the elements for the default value in the sc_pref - // structure has a valid value and take this as default. If both - // elements are not valid, leave the key sequence empty - if (pref.def) - key_seq = QKeySequence (pref.def); - else if (pref.def_std != QKeySequence::UnknownKey) - key_seq = QKeySequence (pref.def_std); + host = proxy_url.host (); + port = proxy_url.port (); + user = proxy_url.userName (); + pass = proxy_url.password (); + } + } + } + + // Set proxy for Qt framework + proxy.setType (proxy_type); + proxy.setHostName (host); + proxy.setPort (port); + proxy.setUser (user); + proxy.setPassword (pass); + + QNetworkProxy::setApplicationProxy (proxy); + + // Set proxy for curl library if not based on environment variables + std::string proxy_url_str = proxy_url.toString().toStdString (); + sys::env::putenv ("http_proxy", proxy_url_str); + sys::env::putenv ("HTTP_PROXY", proxy_url_str); + sys::env::putenv ("https_proxy", proxy_url_str); + sys::env::putenv ("HTTPS_PROXY", proxy_url_str); +} + +// initialize a given combo box with available text encodings +void gui_settings::combo_encoding (QComboBox *combo, const QString& current) +{ + std::vector encoding_list {string::get_encoding_list ()}; + + // prepend SYSTEM + std::string locale_charset {octave_locale_charset_wrapper ()}; + std::transform (locale_charset.begin (), locale_charset.end (), + locale_charset.begin (), ::toupper); + locale_charset = "SYSTEM (" + locale_charset + ")"; + encoding_list.insert (encoding_list.begin (), locale_charset); + + // get the value from the settings file if no current encoding is given + QString enc {current}; + + // Check for valid codec for the default. If this fails, "SYSTEM" (i.e. + // locale_charset) will be chosen. + // FIXME: The default is "SYSTEM" on all platforms. So can this fallback + // logic be removed completely? + bool default_exists = false; + bool show_system = false; + if (ed_default_enc.def ().toString ().startsWith ("SYSTEM")) + show_system = true; + else if (std::find (encoding_list.begin (), encoding_list.end (), + ed_default_enc.def ().toString ().toStdString ()) + != encoding_list.end ()) + default_exists = true; + + QString default_enc = QString::fromStdString (locale_charset); + + if (enc.isEmpty ()) + { + enc = string_value (ed_default_enc); + + if (enc.isEmpty ()) // still empty? + { + if (default_exists) + enc = ed_default_enc.def ().toString (); + else + enc = default_enc; + } + } + + // fill the combo box + for (const auto& c : encoding_list) + combo->addItem (QString::fromStdString (c)); + + // prepend current encoding if not in list + if (combo->findText (enc, Qt::MatchExactly) < 0) + combo->insertItem (0, enc); - return key_seq; + // prepend the default item + combo->insertSeparator (0); + if (show_system || ! default_exists) + combo->insertItem (0, default_enc); + else + combo->insertItem (0, ed_default_enc.def ().toString ()); + + // select the current encoding + combo->setCurrentIndex (combo->findText (enc, Qt::MatchExactly)); + + combo->setMaxVisibleItems (12); +} + +void gui_settings::reload () +{ + // Declare some empty options, which may be set at first startup for + // writing them into the newly created settings file + QString custom_editor; + QStringList def_font; + + // Check whether the settings file does not yet exist + if (! QFile::exists (file_name ())) + { + // Get the default font (for terminal) + def_font = get_default_font (); + + // Get a custom editor defined as env variable + std::string env_default_editor + = sys::env::getenv ("OCTAVE_DEFAULT_EDITOR"); + + if (! env_default_editor.empty ()) + custom_editor = QString::fromStdString (env_default_editor); + } + + check (); + + // Write some settings that were dynamically determined at first startup + + // Custom editor + if (! custom_editor.isEmpty ()) + setValue (global_custom_editor.settings_key (), custom_editor); + + // Default monospace font for the terminal + if (def_font.count () > 1) + { + setValue (cs_font.settings_key (), def_font[0]); + setValue (cs_font_size.settings_key (), def_font[1].toInt ()); + } + + // Write the default monospace font into the settings for later use by + // console and editor as fallbacks of their font preferences. + setValue (global_mono_font.settings_key (), get_default_font_family ()); +} + +void gui_settings::check () +{ + if (status () == QSettings::NoError) + { + // Test usability (force file to be really created) + setValue ("dummy", 0); + sync (); + } + + if (! (QFile::exists (file_name ()) + && isWritable () + && status () == QSettings::NoError)) + { + QString msg + = QString (QT_TR_NOOP ("Error %1 creating the settings file\n%2\n" + "Make sure you have read and write permissions to\n%3\n\n" + "Octave GUI must be closed now.")); + + QMessageBox::critical (nullptr, + QString (QT_TR_NOOP ("Octave Critical Error")), + msg.arg (status ()) + .arg (file_name ()) + .arg (directory_name ())); + + exit (1); + } + else + remove ("dummy"); // Remove test entry } OCTAVE_END_NAMESPACE(octave) diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/gui-settings.h --- a/libgui/src/gui-settings.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/gui-settings.h Fri May 12 08:03:14 2023 +0200 @@ -28,7 +28,19 @@ #include "octave-config.h" +#include #include +#include +#if defined (HAVE_QSCINTILLA) +# include +#endif + +class QByteArray; +class QComboBox; +class QDateTime; +class QIcon; +class QShortcut; +class QTranslator; #include "gui-preferences.h" @@ -40,6 +52,13 @@ public: + // Location, name, and format of settings file determined by + // settings in qt_application class construtor. + + gui_settings (QObject *parent = nullptr) + : QSettings (parent) + { } + gui_settings (const QString& file_name, QSettings::Format format, QObject *parent = nullptr) : QSettings (file_name, format, parent) @@ -52,43 +71,68 @@ : QSettings (format, scope, organization, application, parent) { } - // No copying! + OCTAVE_DISABLE_COPY_MOVE (gui_settings) - gui_settings (const gui_settings&) = delete; + ~gui_settings () = default; - gui_settings& operator = (const gui_settings&) = delete; + QString file_name () const; - ~gui_settings (void) = default; + QString directory_name () const; using QSettings::value; QVariant value (const gui_pref& pref) const { - if (pref.ignore) - return pref.def; // ignore the current pref and always use default + if (pref.ignore ()) + return pref.def (); // ignore the current pref and always use default + + return value (pref.settings_key (), pref.def ()); + } + + // Convenience functions to (slightly) reduce clutter by allowing us + // to write + // + // settings.bool_value (gui_pref_name) + // + // instead of + // + // settings.value (gui_pref_name).toBool () - return value (pref.key, pref.def); - } + bool bool_value (const gui_pref& pref) const; + + QByteArray byte_array_value (const gui_pref& pref) const; + + QColor color_value (const gui_pref& pref) const; + + QDateTime date_time_value (const gui_pref& pref) const; + + int int_value (const gui_pref& pref) const; + + QString string_value (const gui_pref& pref) const; + + QStringList string_list_value (const gui_pref& pref) const; + + uint uint_value (const gui_pref& pref) const; /*! Reading a color from the given QVaraitn @p def taking different color modes into account. The default value for a second color mode @p mode=1 is deterimined from the standard default value @p mode=0 by inverting the lightness - \f{eqnarray*}{ - H_1 &=& H_0\\ - S_1 &=& S_0\\ - L_1 &=& 1.0 - 0.85 L_0 L_0 > 0.3 - L_1 &=& 1.0 - 0.70 L_0 L_0 < 0.3 - \f} + \f{eqnarray*}{ + H_1 &=& H_0\\ + S_1 &=& S_0\\ + L_1 &=& 1.0 - 0.85 L_0 L_0 > 0.3 + L_1 &=& 1.0 - 0.70 L_0 L_0 < 0.3 + \f} @param def Color default value given by a QVariant of QColor - or QPalette::ColorRole + or QPalette::ColorRole @param mode Color mode (currently 0 or 1, default is 0) @return Color as QColor */ - QColor get_color_value (const QVariant& def, int mode = 0) const; + QColor get_color_value (const QVariant& def, int mode) const; /*! Reading a color from the gui_settings taking possible color modes @@ -97,12 +141,12 @@ the lightness (see get_color_value()) @param pref gui preference (key string, default value); the default - value can be given by QColor or QPalette::ColorRole + value can be given by QColor or QPalette::ColorRole @param mode Color mode (currently 0 or 1, default is 0) @return Color as QColor */ - QColor color_value (const gui_pref& pref, int mode = 0) const; + QColor color_value (const gui_pref& pref, int mode) const; /*! Writing a color to the gui_settings taking possible color modes @@ -115,12 +159,57 @@ */ void set_color_value (const gui_pref& pref, const QColor& color, - int mode = 0); + int mode); QString sc_value (const sc_pref& pref) const; QKeySequence sc_def_value (const sc_pref& pref) const; + void set_shortcut (QAction *action, const sc_pref& scpref, + bool enable = true); + + void shortcut (QShortcut *sc, const sc_pref& scpref); + + // config_icon_theme, icon, get_default_font_family, + // get_default_font, and possibly reload and check could be global + // functions instead of member functions. But at least for the icon + // function, defining it as a member function means that we can + // create a single gui_settings object and access multiple icon + // objects rather than having to create a separate settings object + // each time that an icon is needed. OTOH, creating the base + // QSettings object is supposed to be fast, so that may not matter. + // Hmm. + + void config_icon_theme (); + + QIcon icon (const QString& icon_name, bool octave_only = false, + const QString& icon_alt_name = QString ()); + + QString get_default_font_family (); + + QStringList get_default_font (); + + QString get_gui_translation_dir (); + + void config_translators (QTranslator *qt_tr, QTranslator *qsci_tr, + QTranslator *gui_tr); + +#if defined (HAVE_QSCINTILLA) + int get_valid_lexer_styles (QsciLexer *lexer, int *styles); + void read_lexer_settings (QsciLexer *lexer, int mode = 0, int def = 0); +#endif + + bool update_settings_key (const QString& new_key, const QString& old_key); + + void update_network_settings (); + + void combo_encoding (QComboBox *combo, const QString& current = QString ()); + + void reload (); + +private: + + void check (); }; OCTAVE_END_NAMESPACE(octave) @@ -134,3 +223,4 @@ const int settings_reload_default_colors_flag = -1; #endif + diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/gui-utils.cc --- a/libgui/src/gui-utils.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/gui-utils.cc Fri May 12 08:03:14 2023 +0200 @@ -39,7 +39,11 @@ interpolate_color (const QColor& col1, const QColor& col2, double fs, double fv) { +#if HAVE_QCOLOR_FLOAT_TYPE + float h1, s1, v1, h2, s2, v2; +#else qreal h1, s1, v1, h2, s2, v2; +#endif col1.getHsvF (&h1, &s1, &v1); col2.getHsvF (&h2, &s2, &v2); @@ -117,8 +121,9 @@ // And compute again the intersection with the screen if this resizing // led to corners outside the screen - actual_geometry = actual_screen_geom.intersected ( - QRect (QPoint (isx1,isy1), QPoint (isx2,isy2))); + actual_geometry + = actual_screen_geom.intersected (QRect (QPoint (isx1, isy1), + QPoint (isx2, isy2))); } OCTAVE_END_NAMESPACE(octave) diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/history-dock-widget.cc --- a/libgui/src/history-dock-widget.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/history-dock-widget.cc Fri May 12 08:03:14 2023 +0200 @@ -38,8 +38,8 @@ #include "gui-preferences-cs.h" #include "gui-preferences-global.h" #include "gui-preferences-hw.h" +#include "gui-settings.h" #include "history-dock-widget.h" -#include "octave-qobject.h" #include "cmd-hist.h" @@ -47,8 +47,8 @@ OCTAVE_BEGIN_NAMESPACE(octave) -history_dock_widget::history_dock_widget (QWidget *p, base_qobject& oct_qobj) -: octave_dock_widget ("HistoryDockWidget", p, oct_qobj) +history_dock_widget::history_dock_widget (QWidget *p) + : octave_dock_widget ("HistoryDockWidget", p) { setStatusTip (tr ("Browse and search the command history.")); @@ -80,33 +80,29 @@ m_history_list_view->scrollToBottom (); } -void history_dock_widget::clear_history (void) +void history_dock_widget::clear_history () { m_history_model->setStringList (QStringList ()); } -void history_dock_widget::save_settings (void) +void history_dock_widget::save_settings () { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); + gui_settings settings; - if (! settings) - return; - - settings->setValue (hw_filter_active.key, m_filter_checkbox->isChecked ()); - settings->setValue (hw_filter_shown.key, m_filter_shown); + settings.setValue (hw_filter_active.settings_key (), m_filter_checkbox->isChecked ()); + settings.setValue (hw_filter_shown.settings_key (), m_filter_shown); QStringList mru; for (int i = 0; i < m_filter->count (); i++) mru.append (m_filter->itemText (i)); - settings->setValue (hw_mru_list.key, mru); + settings.setValue (hw_mru_list.settings_key (), mru); - settings->sync (); + settings.sync (); octave_dock_widget::save_settings (); } -void history_dock_widget::update_filter_history (void) +void history_dock_widget::update_filter_history () { QString text = m_filter->currentText (); // get current text int index = m_filter->findText (text); // and its actual index @@ -153,13 +149,13 @@ if (index.isValid () && index.column () == 0) { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); + gui_settings settings; - menu.addAction (rmgr.icon ("edit-copy"), tr ("Copy"), this, + menu.addAction (settings.icon ("edit-copy"), tr ("Copy"), this, &history_dock_widget::handle_contextmenu_copy); menu.addAction (tr ("Evaluate"), this, &history_dock_widget::handle_contextmenu_evaluate); - menu.addAction (rmgr.icon ("document-new"), tr ("Create script"), this, + menu.addAction (settings.icon ("document-new"), tr ("Create script"), this, &history_dock_widget::handle_contextmenu_create_script); } if (m_filter_shown) @@ -183,13 +179,13 @@ QItemSelectionModel *selectionModel = m_history_list_view->selectionModel (); QModelIndexList rows = selectionModel->selectedRows (); bool prev_valid_row = false; - for (auto it = rows.begin (); it != rows.end (); it++) + for (const auto& it : rows) { - if ((*it).isValid ()) + if (it.isValid ()) { if (prev_valid_row) text += '\n'; - text += (*it).data ().toString (); + text += it.data ().toString (); prev_valid_row = true; } } @@ -200,11 +196,9 @@ { QItemSelectionModel *selectionModel = m_history_list_view->selectionModel (); QModelIndexList rows = selectionModel->selectedRows (); - for (auto it = rows.begin () ; it != rows.end (); it++) - { - if ((*it).isValid ()) - emit command_double_clicked ((*it).data ().toString ()); - } + for (const auto& it : rows) + if (it.isValid ()) + emit command_double_clicked (it.data ().toString ()); } void history_dock_widget::handle_contextmenu_create_script (bool) @@ -214,13 +208,13 @@ QModelIndexList rows = selectionModel->selectedRows (); bool prev_valid_row = false; - for (auto it = rows.begin (); it != rows.end (); it++) + for (const auto& it : rows) { - if ((*it).isValid ()) + if (it.isValid ()) { if (prev_valid_row) text += '\n'; - text += (*it).data ().toString (); + text += it.data ().toString (); prev_valid_row = true; } } @@ -229,7 +223,7 @@ emit command_create_script (text); } -void history_dock_widget::handle_contextmenu_filter (void) +void history_dock_widget::handle_contextmenu_filter () { m_filter_shown = ! m_filter_shown; m_filter_widget->setVisible (m_filter_shown); @@ -237,7 +231,7 @@ set_filter_focus (m_filter_shown && m_filter_checkbox->isChecked ()) ; } -void history_dock_widget::copyClipboard (void) +void history_dock_widget::copyClipboard () { if (m_history_list_view->hasFocus ()) handle_contextmenu_copy (true); @@ -249,7 +243,7 @@ } } -void history_dock_widget::pasteClipboard (void) +void history_dock_widget::pasteClipboard () { if (m_filter->lineEdit ()->hasFocus ()) { @@ -260,7 +254,7 @@ } } -void history_dock_widget::selectAll (void) +void history_dock_widget::selectAll () { if (m_filter->lineEdit ()->hasFocus ()) m_filter->lineEdit ()->selectAll (); @@ -280,7 +274,7 @@ } } -void history_dock_widget::construct (void) +void history_dock_widget::construct () { m_history_model = new QStringListModel (); m_sort_filter_proxy_model.setSourceModel (m_history_model); @@ -318,29 +312,27 @@ filter_layout->addWidget (filter_label); filter_layout->addWidget (m_filter_checkbox); filter_layout->addWidget (m_filter); - filter_layout->setMargin(0); + filter_layout->setContentsMargins (0, 0, 0, 0); m_filter_widget->setLayout (filter_layout); QVBoxLayout *hist_layout = new QVBoxLayout (); hist_layout->addWidget (m_filter_widget); hist_layout->addWidget (m_history_list_view); - hist_layout->setMargin (2); + hist_layout->setContentsMargins (2, 2, 2, 2); hist_layout->setSpacing (0); widget ()->setLayout (hist_layout); // Init state of the filter - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - m_filter_shown - = settings->value (hw_filter_shown).toBool (); + gui_settings settings; + + m_filter_shown = settings.bool_value (hw_filter_shown); m_filter_widget->setVisible (m_filter_shown); - m_filter->addItems (settings->value (hw_mru_list).toStringList ()); + m_filter->addItems (settings.string_list_value (hw_mru_list)); - bool filter_state - = settings->value (hw_filter_active).toBool (); + bool filter_state = settings.bool_value (hw_filter_active); m_filter_checkbox->setChecked (filter_state); filter_activate (filter_state); @@ -359,15 +351,17 @@ m_history_list_view->setTextElideMode (Qt::ElideRight); } -void history_dock_widget::notice_settings (const gui_settings *settings) +void history_dock_widget::notice_settings () { + gui_settings settings; + QFont font = QFont (); font.setStyleHint (QFont::TypeWriter); - QString default_font = settings->value (global_mono_font).toString (); + QString default_font = settings.string_value (global_mono_font); - font.setFamily (settings->value (cs_font.key, default_font).toString ()); - font.setPointSize (settings->value (cs_font_size).toInt ()); + font.setFamily (settings.value (cs_font.settings_key (), default_font).toString ()); + font.setPointSize (settings.int_value (cs_font_size)); m_history_list_view->setFont (font); } diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/history-dock-widget.h --- a/libgui/src/history-dock-widget.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/history-dock-widget.h Fri May 12 08:03:14 2023 +0200 @@ -37,17 +37,15 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; - class history_dock_widget : public octave_dock_widget { Q_OBJECT public: - history_dock_widget (QWidget *parent, base_qobject& oct_qobj); + history_dock_widget (QWidget *parent); - ~history_dock_widget (void) = default; + ~history_dock_widget () = default; signals: @@ -65,13 +63,13 @@ void set_history (const QStringList& hist); void append_history (const QString& hist_entry); - void clear_history (void); - void save_settings (void); - void notice_settings (const gui_settings *); + void clear_history (); + void save_settings (); + void notice_settings (); private slots: - void update_filter_history (void); + void update_filter_history (); void filter_activate (bool enable); void ctxMenu (const QPoint& pos); @@ -79,17 +77,17 @@ void handle_contextmenu_copy (bool flag); void handle_contextmenu_evaluate (bool flag); void handle_contextmenu_create_script (bool flag); - void handle_contextmenu_filter (void); + void handle_contextmenu_filter (); - void copyClipboard (void); - void pasteClipboard (void); - void selectAll (void); + void copyClipboard (); + void pasteClipboard (); + void selectAll (); virtual void handle_visibility (bool visible); private: - void construct (void); + void construct (); void set_filter_focus (bool focus); QListView *m_history_list_view; diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/interpreter-qobject.cc --- a/libgui/src/interpreter-qobject.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/interpreter-qobject.cc Fri May 12 08:03:14 2023 +0200 @@ -39,10 +39,10 @@ OCTAVE_BEGIN_NAMESPACE(octave) interpreter_qobject::interpreter_qobject (base_qobject& oct_qobj) -: QObject (), m_octave_qobj (oct_qobj), m_interpreter (nullptr) + : QObject (), m_octave_qobj (oct_qobj), m_interpreter (nullptr) { } -void interpreter_qobject::execute (void) +void interpreter_qobject::execute () { // The Octave application context owns the interpreter. @@ -67,10 +67,8 @@ if (app_context.start_gui_p () && ! m_octave_qobj.experimental_terminal_widget ()) { - input_system& input_sys = interp.get_input_system (); - - input_sys.PS1 (">> "); - input_sys.PS2 (""); + interp.PS1 (">> "); + interp.PS2 (""); } if (interp.initialized ()) @@ -82,7 +80,7 @@ emit ready (); - graphics_init (interp, m_octave_qobj); + graphics_init (interp); // Start executing commands in the command window. @@ -130,7 +128,7 @@ evmgr.post_event (meth); } -void interpreter_qobject::interrupt (void) +void interpreter_qobject::interrupt () { if (! m_interpreter) return; @@ -141,7 +139,7 @@ m_interpreter->interrupt (); } -void interpreter_qobject::pause (void) +void interpreter_qobject::pause () { // FIXME: Should we make this action work with the old terminal // widget? @@ -158,7 +156,7 @@ } } -void interpreter_qobject::stop (void) +void interpreter_qobject::stop () { // FIXME: Should we make this action work with the old terminal // widget? @@ -175,7 +173,7 @@ } } -void interpreter_qobject::resume (void) +void interpreter_qobject::resume () { // FIXME: Should we make this action work with the old terminal // widget? @@ -195,7 +193,7 @@ } } -qt_interpreter_events *interpreter_qobject::qt_link (void) +qt_interpreter_events *interpreter_qobject::qt_link () { return m_octave_qobj.qt_link (); } diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/interpreter-qobject.h --- a/libgui/src/interpreter-qobject.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/interpreter-qobject.h Fri May 12 08:03:14 2023 +0200 @@ -44,25 +44,25 @@ interpreter_qobject (base_qobject& oct_qobj); - ~interpreter_qobject (void) = default; + ~interpreter_qobject () = default; - qt_interpreter_events * qt_link (void); + qt_interpreter_events * qt_link (); void interpreter_event (const fcn_callback& fcn); void interpreter_event (const meth_callback& meth); - void interrupt (void); + void interrupt (); // Note: PAUSE, STOP, and RESUME are currently only used by the new // experimental terminal widget. - void pause (void); - void stop (void); - void resume (void); + void pause (); + void stop (); + void resume (); signals: - void ready (void); + void ready (); void shutdown_finished (int); @@ -88,7 +88,7 @@ //! Initialize and execute the octave interpreter. - void execute (void); + void execute (); private: diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/led-indicator.cc --- a/libgui/src/led-indicator.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/led-indicator.cc Fri May 12 08:03:14 2023 +0200 @@ -67,11 +67,10 @@ { QColor col_light = interpolate_color (col, QColor (Qt::white), 0.25, 0.9); - const QString style = QString ( - "border-radius: %1; background-color: " - "qlineargradient(spread:pad, x1:0.2, y1:0.2, x2:1, y2:1, stop:0 " - "%2, stop:1 %3);" - ).arg (width ()/2).arg (col_light.name ()).arg (col.name ()); + const QString style + = QString ("border-radius: %1; background-color: " + "qlineargradient(spread:pad, x1:0.2, y1:0.2, x2:1, y2:1, stop:0 " + "%2, stop:1 %3);").arg (width ()/2).arg (col_light.name ()).arg (col.name ()); return style; } diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/m-editor/file-editor-interface.h --- a/libgui/src/m-editor/file-editor-interface.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/m-editor/file-editor-interface.h Fri May 12 08:03:14 2023 +0200 @@ -30,33 +30,30 @@ #include #include -#include "gui-settings.h" #include "octave-dock-widget.h" OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; - class file_editor_interface : public octave_dock_widget { Q_OBJECT public: - file_editor_interface (QWidget *p, base_qobject& oct_qobj) - : octave_dock_widget ("FileEditor", p, oct_qobj) + file_editor_interface (QWidget *p) + : octave_dock_widget ("FileEditor", p) { } - virtual ~file_editor_interface (void) = default; + virtual ~file_editor_interface () = default; - virtual QMenu * get_mru_menu (void) = 0; - virtual QMenu * debug_menu (void) = 0; - virtual QToolBar * toolbar (void) = 0; - virtual QMenuBar * menubar (void) = 0; + virtual QMenu * get_mru_menu () = 0; + virtual QMenu * debug_menu () = 0; + virtual QToolBar * toolbar () = 0; + virtual QMenuBar * menubar () = 0; virtual void insert_global_actions (QList) = 0; - virtual void handle_enter_debug_mode (void) = 0; - virtual void handle_exit_debug_mode (void) = 0; + virtual void handle_enter_debug_mode () = 0; + virtual void handle_exit_debug_mode () = 0; virtual void handle_insert_debugger_pointer_request (const QString& file, int line) = 0; @@ -70,11 +67,11 @@ virtual void handle_edit_file_request (const QString& file) = 0; - virtual bool check_closing (void) = 0; + virtual bool check_closing () = 0; virtual void empty_script (bool, bool) = 0; - virtual void restore_session (gui_settings *) = 0; + virtual void restore_session () = 0; virtual void enable_menu_shortcuts (bool enable) = 0; diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/m-editor/file-editor-tab.cc --- a/libgui/src/m-editor/file-editor-tab.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/m-editor/file-editor-tab.cc Fri May 12 08:03:14 2023 +0200 @@ -44,13 +44,15 @@ #include #include #include +#include #include #include +#include #include #include -#include #include #include + #if defined (HAVE_QSCI_QSCILEXEROCTAVE_H) # define HAVE_LEXER_OCTAVE 1 # include @@ -71,14 +73,14 @@ #include "gui-preferences-cs.h" #include "gui-preferences-ed.h" #include "gui-preferences-global.h" +#include "gui-settings.h" #include "gui-utils.h" #include "marker.h" -#include "octave-qobject.h" -#include "octave-qtutils.h" #include "octave-txt-lexer.h" #include "cmd-edit.h" #include "file-ops.h" +#include "iconv-wrappers.h" #include "localcharset-wrapper.h" #include "uniconv-wrappers.h" @@ -104,9 +106,7 @@ // Make parent null for the file editor tab so that warning WindowModal // messages don't affect grandparents. -file_editor_tab::file_editor_tab (base_qobject& oct_qobj, - const QString& directory_arg) -: m_octave_qobj (oct_qobj) +file_editor_tab::file_editor_tab (const QString& directory_arg) { m_lexer_apis = nullptr; m_is_octave_file = true; @@ -118,7 +118,7 @@ m_file_name = ""; m_file_system_watcher.setObjectName ("_qt_autotest_force_engine_poller"); - m_edit_area = new octave_qscintilla (this, m_octave_qobj); + m_edit_area = new octave_qscintilla (this); m_line = 0; m_col = 0; @@ -199,7 +199,7 @@ marker::unsure_debugger_position); connect (m_edit_area, SIGNAL (marginClicked (int, int, - Qt::KeyboardModifiers)), + Qt::KeyboardModifiers)), this, SLOT (handle_margin_clicked (int, int, Qt::KeyboardModifiers))); @@ -225,7 +225,7 @@ QVBoxLayout *edit_area_layout = new QVBoxLayout (); edit_area_layout->addWidget (m_edit_area); edit_area_layout->addWidget (m_status_bar); - edit_area_layout->setMargin (0); + edit_area_layout->setContentsMargins (0, 0, 0, 0); edit_area_layout->setSpacing (0); setLayout (edit_area_layout); @@ -266,19 +266,18 @@ connect (this, &file_editor_tab::do_save_file_signal, this, &file_editor_tab::do_save_file); - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - if (settings) - notice_settings (settings, true); + notice_settings (true); + + gui_settings settings; // encoding, not updated with the settings - m_encoding = settings->value (ed_default_enc.key, "UTF-8").toString (); + m_encoding = settings.value (ed_default_enc.settings_key (), "UTF-8").toString (); m_enc_indicator->setText (m_encoding); // no changes in encoding yet m_new_encoding = m_encoding; } -file_editor_tab::~file_editor_tab (void) +file_editor_tab::~file_editor_tab () { // Tell all connected markers to self-destruct. emit remove_all_breakpoints_signal (); @@ -330,38 +329,42 @@ void file_editor_tab::handle_context_menu_edit (const QString& word_at_cursor) { - // Search for a subfunction in actual file (this is done first because - // Octave finds this function before others with the same name in the - // search path. - QRegExp rxfun1 ("^[\t ]*function[^=]+=[\t ]*" - + word_at_cursor + "[\t ]*\\([^\\)]*\\)[\t ]*$"); - QRegExp rxfun2 ("^[\t ]*function[\t ]+" - + word_at_cursor + "[\t ]*\\([^\\)]*\\)[\t ]*$"); - QRegExp rxfun3 ("^[\t ]*function[\t ]+" - + word_at_cursor + "[\t ]*$"); - QRegExp rxfun4 ("^[\t ]*function[^=]+=[\t ]*" - + word_at_cursor + "[\t ]*$"); - - int pos_fct = -1; + // Search for a function with that name in the current file + // This is done first because local functions and subfunctions have priority + // over other functions with the same name in the load path. + QRegularExpression rxfun1 {"^[\t ]*function[^=]+=[\t ]*" + + word_at_cursor + "[\t ]*\\([^\\)]*\\)[\t ]*$"}; + QRegularExpression rxfun2 {"^[\t ]*function[\t ]+" + + word_at_cursor + "[\t ]*\\([^\\)]*\\)[\t ]*$"}; + QRegularExpression rxfun3 {"^[\t ]*function[\t ]+" + + word_at_cursor + "[\t ]*$"}; + QRegularExpression rxfun4 {"^[\t ]*function[^=]+=[\t ]*" + + word_at_cursor + "[\t ]*$"}; + + QRegularExpressionMatch match; QStringList lines = m_edit_area->text ().split ("\n"); int line; for (line = 0; line < lines.count (); line++) { - if ((pos_fct = rxfun1.indexIn (lines.at (line))) != -1) + match = rxfun1.match (lines.at (line)); + if (match.hasMatch ()) break; - if ((pos_fct = rxfun2.indexIn (lines.at (line))) != -1) + match = rxfun2.match (lines.at (line)); + if (match.hasMatch ()) break; - if ((pos_fct = rxfun3.indexIn (lines.at (line))) != -1) + match = rxfun3.match (lines.at (line)); + if (match.hasMatch ()) break; - if ((pos_fct = rxfun4.indexIn (lines.at (line))) != -1) + match = rxfun4.match (lines.at (line)); + if (match.hasMatch ()) break; } - if (pos_fct > -1) + if (match.hasMatch ()) { // reg expr. found: it is an internal function - m_edit_area->setCursorPosition (line, pos_fct); + m_edit_area->setCursorPosition (line, match.capturedStart ()); m_edit_area->SendScintilla (2232, line); // SCI_ENSUREVISIBLE // SCI_VISIBLEFROMDOCLINE int vis_line = m_edit_area->SendScintilla (2220, line); @@ -440,67 +443,67 @@ emit interpreter_event ([=] (interpreter& interp) - { - // INTERPRETER THREAD - - // We are intentionally skipping any side effects that may - // occur in the evaluation of NEW_COND if THIS_FETAB is no - // longer valid. - - if (this_fetab.isNull ()) - return; - - error_system& es = interp.get_error_system (); - - unwind_protect frame; - - // Prevent an error in the evaluation here from sending us - // into the debugger. - - es.interpreter_try (frame); - - bool eval_error = false; - std::string msg; - - try - { - tree_evaluator& tw = interp.get_evaluator (); - bp_table& bptab = tw.get_bp_table (); - - bptab.condition_valid (new_cond.toStdString ()); - - // The condition seems OK, so set the conditional - // breakpoint. - - emit request_add_breakpoint (line, new_cond); - } - catch (const execution_exception& ee) - { - interp.recover_from_exception (); - - msg = ee.message (); - eval_error = true; - } - catch (const interrupt_exception&) - { - interp.recover_from_exception (); - - msg = "evaluation interrupted"; - eval_error = true; - } - - if (eval_error) - { - // Try again with a prompt that indicates the last - // attempt was an error. - - QString new_prompt = (tr ("ERROR: ") - + QString::fromStdString (msg) - + "\n\ndbstop if"); - - emit dbstop_if (new_prompt, line, ""); - } - }); + { + // INTERPRETER THREAD + + // We are intentionally skipping any side effects that may + // occur in the evaluation of NEW_COND if THIS_FETAB is no + // longer valid. + + if (this_fetab.isNull ()) + return; + + error_system& es = interp.get_error_system (); + + unwind_protect frame; + + // Prevent an error in the evaluation here from sending us + // into the debugger. + + es.interpreter_try (frame); + + bool eval_error = false; + std::string msg; + + try + { + tree_evaluator& tw = interp.get_evaluator (); + bp_table& bptab = tw.get_bp_table (); + + bptab.condition_valid (new_cond.toStdString ()); + + // The condition seems OK, so set the conditional + // breakpoint. + + emit request_add_breakpoint (line, new_cond); + } + catch (const execution_exception& ee) + { + interp.recover_from_exception (); + + msg = ee.message (); + eval_error = true; + } + catch (const interrupt_exception&) + { + interp.recover_from_exception (); + + msg = "evaluation interrupted"; + eval_error = true; + } + + if (eval_error) + { + // Try again with a prompt that indicates the last + // attempt was an error. + + QString new_prompt = (tr ("ERROR: ") + + QString::fromStdString (msg) + + "\n\ndbstop if"); + + emit dbstop_if (new_prompt, line, ""); + } + }); } } @@ -562,7 +565,7 @@ // not match what Octave core is interpreting in the // file on disk. This function gives the user the option // to save before creating the breakpoint. -bool file_editor_tab::unchanged_or_saved (void) +bool file_editor_tab::unchanged_or_saved () { bool retval = true; if (m_edit_area->isModified () || ! valid_file_name ()) @@ -611,7 +614,7 @@ } } -void file_editor_tab::update_lexer (void) +void file_editor_tab::update_lexer () { // Create a new lexer QsciLexer *lexer = nullptr; @@ -726,8 +729,7 @@ { QsciLexer *lexer = m_edit_area->lexer (); - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); + gui_settings settings; if (m_lexer_apis) { @@ -756,9 +758,9 @@ // get settings which infos are used for octave bool octave_builtins - = settings->value (ed_code_completion_octave_builtins).toBool (); + = settings.bool_value (ed_code_completion_octave_builtins); bool octave_functions - = settings->value (ed_code_completion_octave_functions).toBool (); + = settings.bool_value (ed_code_completion_octave_functions); QCoreApplication::setApplicationName (tmp_app_name); // Restore name @@ -832,59 +834,59 @@ { // The interpreter_event callback function below emits a // signal. Because we don't control when that happens, - // use a guarded pointer so that the callback can abort if - // this object is no longer valid. + // use a guarded pointer so that the callback can abort + // if this object is no longer valid. QPointer this_fetab (this); emit interpreter_event ([=] (interpreter& interp) - { - // INTERPRETER THREAD - - // We can skip the entire callback function because it - // does not make any changes to the interpreter - // state. - - if (this_fetab.isNull ()) - return; - - QStringList api_entries; - - octave_value_list tmp = Fiskeyword (); - const Cell ctmp = tmp(0).cell_value (); - for (octave_idx_type i = 0; i < ctmp.numel (); i++) - { - std::string kw = ctmp(i).string_value (); - api_entries.append (QString::fromStdString (kw)); - } - - if (octave_builtins) - { - symbol_table& symtab = interp.get_symbol_table (); - - string_vector bfl = symtab.built_in_function_names (); - - for (octave_idx_type i = 0; i < bfl.numel (); i++) - api_entries.append (QString::fromStdString (bfl[i])); - } - - if (octave_functions) - { - load_path& lp = interp.get_load_path (); - - string_vector ffl = lp.fcn_names (); - string_vector afl = interp.autoloaded_functions (); - - for (octave_idx_type i = 0; i < ffl.numel (); i++) - api_entries.append (QString::fromStdString (ffl[i])); - - for (octave_idx_type i = 0; i < afl.numel (); i++) - api_entries.append (QString::fromStdString (afl[i])); - } - - emit request_add_octave_apis (api_entries); - }); + { + // INTERPRETER THREAD + + // We can skip the entire callback function because + // it does not make any changes to the interpreter + // state. + + if (this_fetab.isNull ()) + return; + + QStringList api_entries; + + octave_value_list tmp = Fiskeyword (); + const Cell ctmp = tmp(0).cell_value (); + for (octave_idx_type i = 0; i < ctmp.numel (); i++) + { + std::string kw = ctmp(i).string_value (); + api_entries.append (QString::fromStdString (kw)); + } + + if (octave_builtins) + { + symbol_table& symtab = interp.get_symbol_table (); + + string_vector bfl = symtab.built_in_function_names (); + + for (octave_idx_type i = 0; i < bfl.numel (); i++) + api_entries.append (QString::fromStdString (bfl[i])); + } + + if (octave_functions) + { + load_path& lp = interp.get_load_path (); + + string_vector ffl = lp.fcn_names (); + string_vector afl = interp.autoloaded_functions (); + + for (octave_idx_type i = 0; i < ffl.numel (); i++) + api_entries.append (QString::fromStdString (ffl[i])); + + for (octave_idx_type i = 0; i < afl.numel (); i++) + api_entries.append (QString::fromStdString (afl[i])); + } + + emit request_add_octave_apis (api_entries); + }); } else { @@ -895,7 +897,7 @@ QString keyword = QString (lexer->keywords (i)); QStringList keyword_list - = keyword.split (QRegExp (R"(\s+)")); + = keyword.split (QRegularExpression {R"(\s+)"}); for (int j = 0; j < keyword_list.size (); j++) m_lexer_apis->add (keyword_list.at (j)); @@ -909,8 +911,8 @@ if (update_apis_only) return; // We are done here - int mode = settings->value (ed_color_mode).toInt (); - rmgr.read_lexer_settings (lexer, settings, mode); + int mode = settings.int_value (ed_color_mode); + settings.read_lexer_settings (lexer, mode); m_edit_area->setCaretForegroundColor (lexer->color (0)); m_edit_area->setIndentationGuidesForegroundColor (lexer->color (0)); @@ -934,11 +936,11 @@ m_edit_area->setFoldMarginColors (bgm, fgm); QColor current_line_bg - = settings->color_value (ed_highlight_current_line_color, mode); + = settings.color_value (ed_highlight_current_line_color, mode); if (current_line_bg == settings_color_no_change) - bgm = interpolate_color (bg, fg, 0.5, 0.1); // It is the "auto" color - else - bgm = current_line_bg; // Specific color given + bgm = interpolate_color (bg, fg, 0.5, 0.1); // It is the "auto" color + else + bgm = current_line_bg; // Specific color given m_edit_area->setCaretLineBackgroundColor (bgm); @@ -949,7 +951,7 @@ // fix line number width with respect to the font size of the lexer and // set the line numbers font depending on the lexer's font - if (settings->value (ed_show_line_numbers).toBool ()) + if (settings.bool_value (ed_show_line_numbers)) { // Line numbers width auto_margin_width (); @@ -958,7 +960,7 @@ QFont line_numbers_font = lexer->defaultFont (); int font_size = line_numbers_font.pointSize (); font_size = font_size - + settings->value (ed_line_numbers_size).toInt (); + + settings.int_value (ed_line_numbers_size); if (font_size < 4) font_size = 4; line_numbers_font.setPointSize (font_size); @@ -978,7 +980,7 @@ emit api_entries_added (); } -void file_editor_tab::handle_api_entries_added (void) +void file_editor_tab::handle_api_entries_added () { // disconnect slot for saving prepared info if already connected disconnect (m_lexer_apis, &QsciAPIs::apiPreparationFinished, @@ -995,7 +997,7 @@ m_lexer_apis->prepare (); // prepare apis info } -void file_editor_tab::save_apis_info (void) +void file_editor_tab::save_apis_info () { m_lexer_apis->savePrepared (m_prep_apis_file); } @@ -1161,7 +1163,7 @@ // Wrap. Should use the last line of the file, not 1<<15 if (prevline == -1) prevline = m_edit_area->markerFindPrevious (m_edit_area->lines (), - (1 << marker::bookmark)); + (1 << marker::bookmark)); m_edit_area->setCursorPosition (prevline, 0); } @@ -1208,14 +1210,14 @@ { emit interpreter_event ([=] (interpreter& interp) - { - // INTERPRETER THREAD - - tree_evaluator& tw = interp.get_evaluator (); - bp_table& bptab = tw.get_bp_table (); - - bptab.remove_breakpoint_from_file (m_file_name.toStdString (), line); - }); + { + // INTERPRETER THREAD + + tree_evaluator& tw = interp.get_evaluator (); + bp_table& bptab = tw.get_bp_table (); + + bptab.remove_breakpoint_from_file (m_file_name.toStdString (), line); + }); } void file_editor_tab::toggle_breakpoint (const QWidget *ID) @@ -1286,15 +1288,15 @@ emit interpreter_event ([=] (interpreter& interp) - { - // INTERPRETER THREAD - - tree_evaluator& tw = interp.get_evaluator (); - bp_table& bptab = tw.get_bp_table (); - - bptab.remove_all_breakpoints_from_file (m_file_name.toStdString (), - true); - }); + { + // INTERPRETER THREAD + + tree_evaluator& tw = interp.get_evaluator (); + bp_table& bptab = tw.get_bp_table (); + + bptab.remove_all_breakpoints_from_file (m_file_name.toStdString (), + true); + }); } void file_editor_tab::scintilla_command (const QWidget *ID, @@ -1395,27 +1397,28 @@ emit interpreter_event ([=] (interpreter& interp) - { - // INTERPRETER THREAD - - // If THIS_FETAB is no longer valid, we still want to set the - // breakpoint in the interpreter but we can't emit the signal - // associated with THIS_FETAB. - - // FIXME: note duplication with the code in - // handle_context_menu_break_condition. - - tree_evaluator& tw = interp.get_evaluator (); - bp_table& bptab = tw.get_bp_table (); - - int lineno = bptab.add_breakpoint_in_file (m_file_name.toStdString (), - line, cond.toStdString ()); - if (this_fetab.isNull ()) - return; - - if (lineno) - emit maybe_remove_next (lineno); - }); + { + // INTERPRETER THREAD + + // If THIS_FETAB is no longer valid, we still want to set the + // breakpoint in the interpreter but we can't emit the signal + // associated with THIS_FETAB. + + // FIXME: note duplication with the code in + // handle_context_menu_break_condition. + + tree_evaluator& tw = interp.get_evaluator (); + bp_table& bptab = tw.get_bp_table (); + + int lineno = bptab.add_breakpoint_in_file (m_file_name.toStdString (), + line, cond.toStdString ()); + + if (this_fetab.isNull ()) + return; + + if (lineno) + emit maybe_remove_next (lineno); + }); } void file_editor_tab::handle_remove_next (int remove_line) @@ -1533,7 +1536,7 @@ m_edit_area->endUndoAction (); } -void file_editor_tab::do_smart_indent_line_or_selected_text (void) +void file_editor_tab::do_smart_indent_line_or_selected_text () { m_edit_area->beginUndoAction (); @@ -1562,7 +1565,7 @@ void file_editor_tab::do_comment_selected_text (bool comment, bool input_str) { - QRegExp rxc; + QRegularExpression rxc; QString ws = "^(?:[ \\t]*)"; QStringList comment_str = m_edit_area->comment_string (comment); QString used_comment_str = comment_str.at (0); @@ -1572,20 +1575,19 @@ if (input_str) { bool ok; - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); + gui_settings settings; used_comment_str = QInputDialog::getText (this, tr ("Comment selected text"), tr ("Comment string to use:\n"), QLineEdit::Normal, - settings->value (ed_last_comment_str, comment_str.at (0)).toString (), + settings.value (ed_last_comment_str, comment_str.at (0)).toString (), &ok); if ((! ok) || used_comment_str.isEmpty ()) return; // No input, do nothing else - settings->setValue (ed_last_comment_str, used_comment_str); // Store last + settings.setValue (ed_last_comment_str, used_comment_str); // Store last } } else @@ -1620,7 +1622,7 @@ regexp = regexp + QString ("|"); regexp = regexp + comment_str_sorted.at (i); } - rxc = QRegExp (ws + "(" + regexp + ")"); + rxc = QRegularExpression {ws + "(" + regexp + ")"}; } // Do the commenting/uncommenting @@ -1632,7 +1634,7 @@ int lineFrom, lineTo, colFrom, colTo; int change_col_from = 1; int change_col_to = 1; - bool removed; + bool removed = false; m_edit_area->getSelection (&lineFrom, &colFrom, &lineTo, &colTo); @@ -1648,11 +1650,13 @@ else { QString line (m_edit_area->text (i)); - if ((removed = line.contains (rxc))) + QRegularExpressionMatch match = rxc.match (line); + + if (match.hasMatch ()) { - len = rxc.matchedLength (); // complete length - QString matched_text = rxc.capturedTexts ().at (0); - lenc = matched_text.remove (QRegExp (ws)).length (); // only comment string + len = match.capturedLength (); // complete length + QString matched_text = match.captured (0); + lenc = matched_text.remove (QRegularExpression {ws}).length (); // only comment string m_edit_area->setSelection (i, len-lenc, i, len); m_edit_area->removeSelectedText (); } @@ -1694,11 +1698,12 @@ else { QString line (m_edit_area->text (cpline)); - if (line.contains (rxc)) + QRegularExpressionMatch match = rxc.match (line); + if (match.hasMatch ()) { - len = rxc.matchedLength (); // complete length - QString matched_text = rxc.capturedTexts ().at (0); - lenc = matched_text.remove (QRegExp (ws)).length (); // only comment string + len = match.capturedLength (); // complete length + QString matched_text = match.captured (0); + lenc = matched_text.remove (QRegularExpression {ws}).length (); // only comment string m_edit_area->setSelection (cpline, len-lenc, cpline, len); m_edit_area->removeSelectedText (); } @@ -1753,8 +1758,8 @@ // editor tab can't be made parent because it may be deleted depending // upon the response. Instead, change the m_edit_area to read only. QMessageBox::StandardButtons buttons = QMessageBox::Save | - QMessageBox::Discard | - QMessageBox::Cancel; + QMessageBox::Discard | + QMessageBox::Cancel; // For now, just a warning message about closing a tab that has been // modified seems sufficient. Exit-condition-specific messages could @@ -1802,7 +1807,7 @@ m_edit_area->setModified (modified); } -void file_editor_tab::recover_from_exit (void) +void file_editor_tab::recover_from_exit () { // reset the possibly still existing read only state m_edit_area->setReadOnly (false); @@ -1814,7 +1819,7 @@ check_restore_breakpoints (); } -void file_editor_tab::check_restore_breakpoints (void) +void file_editor_tab::check_restore_breakpoints () { if (! m_bp_lines.isEmpty ()) { @@ -1861,10 +1866,10 @@ QByteArray text_data = file.readAll (); // remove newline at end of file if we add one again when saving - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - - if (settings->value (ed_force_newline).toBool ()) + + gui_settings settings; + + if (settings.bool_value (ed_force_newline)) { const QByteArray eol_lf = QByteArray (1, 0x0a); const QByteArray eol_cr = QByteArray (1, 0x0d); @@ -1876,28 +1881,57 @@ text_data.chop (1); } - // decode - QTextCodec::ConverterState st; - QTextCodec *codec = QTextCodec::codecForName (m_encoding.toLatin1 ()); - if (codec == nullptr) - codec = QTextCodec::codecForLocale (); - - const QString text = codec->toUnicode(text_data.constData(), - text_data.size(), &st); - - // Decoding with invalid characters? - if (st.invalidChars > 0) + // expected file encoding + std::string encoding = m_encoding.toStdString (); + if (encoding.compare (0, 6, "SYSTEM") == 0) + encoding = octave_locale_charset_wrapper (); + + // check if the selected encoding can be used to decode the file + + const char *src = text_data.constData (); + std::size_t srclen = text_data.length (); + + std::size_t length; + uint16_t *u16_str; + + // try to convert encoding in strict mode + u16_str = octave_u16_conv_from_encoding_strict (encoding.c_str (), + src, srclen, &length); + + // check for invalid characters in input file + if (! u16_str) { // Set read only m_edit_area->setReadOnly (true); + // convert encoding allowing replacements + u16_str = octave_u16_conv_from_encoding (encoding.c_str (), + src, srclen, &length); + + if (! u16_str) + { + // FIXME: Can this ever happen? + + // non-modal error message box + QMessageBox *msgBox + = new QMessageBox (QMessageBox::Critical, + tr ("Octave Editor"), + tr ("Unable to read file '%1'\n" + "with selected encoding '%2': %3") + .arg (file_to_load).arg (m_encoding) + .arg (std::strerror (errno)), + QMessageBox::Ok, nullptr); + show_dialog (msgBox, false); + return QString (); + } + // Message box for user decision QString msg = tr ("There were problems reading the file\n" "%1\n" "with the selected encoding %2.\n\n" "Modifying and saving the file might " "cause data loss!") - .arg (file_to_load).arg (m_encoding); + .arg (file_to_load).arg (m_encoding); QMessageBox *msg_box = new QMessageBox (); msg_box->setIcon (QMessageBox::Warning); msg_box->setText (msg); @@ -1914,13 +1948,18 @@ msg_box->show (); } + unwind_action free_u16_str ([=] () { ::free (u16_str); }); + + QString text + = QString::fromUtf16 (reinterpret_cast (u16_str), length); + m_edit_area->setText (text); m_edit_area->setEolMode (detect_eol_mode ()); QApplication::restoreOverrideCursor (); - m_copy_available = false; // no selection yet available - m_edit_area->setModified (false); // loaded file is not modified yet + m_copy_available = false; // no selection yet available + m_edit_area->setModified (false); // loaded file is not modified yet set_file_name (file_to_load); update_eol_indicator (); @@ -1953,8 +1992,8 @@ "This does not change the default encoding.\n")); QComboBox *enc_combo = new QComboBox (); - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - rmgr.combo_encoding (enc_combo); + gui_settings settings; + settings.combo_encoding (enc_combo); m_new_encoding = enc_combo->currentText (); connect (enc_combo, &QComboBox::currentTextChanged, this, &file_editor_tab::handle_current_enc_changed); @@ -1992,7 +2031,7 @@ m_new_encoding = enc; } -QsciScintilla::EolMode file_editor_tab::detect_eol_mode (void) +QsciScintilla::EolMode file_editor_tab::detect_eol_mode () { QByteArray text = m_edit_area->text ().toLatin1 (); @@ -2005,10 +2044,10 @@ int count_lf = text.count (eol_lf) - count_crlf; // isolated lf int count_cr = text.count (eol_cr) - count_crlf; // isolated cr - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); + gui_settings settings; + QsciScintilla::EolMode eol_mode - = static_cast (settings->value (ed_default_eol_mode).toInt ()); + = static_cast (settings.int_value (ed_default_eol_mode)); int count_max = 0; @@ -2030,7 +2069,7 @@ return eol_mode; } -void file_editor_tab::update_eol_indicator (void) +void file_editor_tab::update_eol_indicator () { switch (m_edit_area->eolMode ()) { @@ -2061,23 +2100,23 @@ emit interpreter_event ([=] (interpreter& interp) - { - // INTERPRETER THREAD - - // We can skip the entire callback function because it does not - // make any changes to the interpreter state. - - if (this_fetab.isNull ()) - return; - - octave_value_list argout = Fdbstatus (interp, ovl (), 1); - - connect (this, &file_editor_tab::update_breakpoints_signal, - this, &file_editor_tab::update_breakpoints_handler, - Qt::QueuedConnection); - - emit update_breakpoints_signal (argout); - }); + { + // INTERPRETER THREAD + + // We can skip the entire callback function because it does not + // make any changes to the interpreter state. + + if (this_fetab.isNull ()) + return; + + octave_value_list argout = Fdbstatus (interp, ovl (), 1); + + connect (this, &file_editor_tab::update_breakpoints_signal, + this, &file_editor_tab::update_breakpoints_handler, + Qt::QueuedConnection); + + emit update_breakpoints_signal (argout); + }); } void file_editor_tab::update_breakpoints_handler (const octave_value_list& argout) @@ -2101,12 +2140,11 @@ { update_window_title (false); // window title (no modification) - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); + gui_settings settings; // set the eol mode from the settings or depending on the OS if the entry is // missing in the settings - m_edit_area->setEolMode (static_cast (settings->value (ed_default_eol_mode).toInt ())); + m_edit_area->setEolMode (static_cast (settings.int_value (ed_default_eol_mode))); update_eol_indicator (); @@ -2137,31 +2175,31 @@ emit interpreter_event ([=] (interpreter& interp) - { - // INTERPRETER THREAD - - // If THIS_FETAB is no longer valid, we still want to perform - // the actions in the interpreter but we can't emit the signal - // associated with THIS_FETAB. - - tree_evaluator& tw = interp.get_evaluator (); - - tw.dbquit (true); - - command_editor::interrupt (true); - - std::string std_base_name = base_name.toStdString (); - - symbol_table& symtab = interp.get_symbol_table (); - - symtab.clear_user_function (std_base_name); - - if (this_fetab.isNull ()) - return; - - emit do_save_file_signal (file_to_save, remove_on_success, - restore_breakpoints); - }); + { + // INTERPRETER THREAD + + // If THIS_FETAB is no longer valid, we still want to + // perform the actions in the interpreter but we can't emit + // the signal associated with THIS_FETAB. + + tree_evaluator& tw = interp.get_evaluator (); + + tw.dbquit (true); + + command_editor::interrupt (true); + + std::string std_base_name = base_name.toStdString (); + + symbol_table& symtab = interp.get_symbol_table (); + + symtab.clear_user_function (std_base_name); + + if (this_fetab.isNull ()) + return; + + emit do_save_file_signal (file_to_save, remove_on_success, + restore_breakpoints); + }); } } @@ -2179,9 +2217,8 @@ m_encoding = m_new_encoding; // consider a possible new encoding - // set the desired codec (if suitable for contents) - QTextCodec *codec = check_valid_codec (); - if (! codec) + // check if the selected encoding is suitable for the content + if (! check_valid_codec ()) return; // No valid codec // Get a list of breakpoint line numbers, before exiting debug mode @@ -2206,90 +2243,90 @@ emit interpreter_event ([=] (interpreter& interp) - { - // INTERPRETER THREAD - - // We are intentionally skipping any side effects that may - // occur in the callback function if THIS_FETAB is no longer - // valid. If the editor tab has disappeared, there is not - // much point in reloading the function to restore breakpoint - // info in the GUI. - - if (this_fetab.isNull ()) - return; - - // Force reloading of a file after it is saved. - // This is needed to get the right line numbers for - // breakpoints (bug #46632). - - tree_evaluator& tw = interp.get_evaluator (); - - symbol_table& symtab = interp.get_symbol_table (); - - std::string std_base_name = base_name.toStdString (); - - if (tw.in_debug_repl ()) - { - octave_value sym; - try - { - sym = symtab.find_user_function (std_base_name); - } - catch (const execution_exception&) - { - interp.recover_from_exception (); - - // Ignore syntax error. It was in the old file on disk; - // the user may have fixed it already. - } - - // Return early if this file is not loaded in the symbol table - if (! sym.is_defined () || ! sym.is_user_code ()) - { - emit do_save_file_signal (file_to_save, remove_on_success, - restore_breakpoints); - return; - } - - octave_user_code *fcn = sym.user_code_value (); - - std::string full_name = file_to_save.toStdString (); - - if (sys::canonicalize_file_name (full_name) - != sys::canonicalize_file_name (fcn->fcn_file_name ())) - { - emit do_save_file_signal (file_to_save, remove_on_success, - restore_breakpoints); - return; - } - - // If this file is loaded, check that we aren't currently - // running it. - // FIXME: is there a better way to get this info? - - octave_idx_type curr_frame = -1; - - octave_map stk = tw.backtrace (curr_frame, false); - - Cell names = stk.contents ("name"); - - for (octave_idx_type i = names.numel () - 1; i >= 0; i--) - { - if (names(i).string_value () == std_base_name) - { - emit confirm_dbquit_and_save_signal - (file_to_save, base_name, remove_on_success, - restore_breakpoints); - return; - } - } - } - - symtab.clear_user_function (std_base_name); - - emit do_save_file_signal (file_to_save, remove_on_success, - restore_breakpoints); - }); + { + // INTERPRETER THREAD + + // We are intentionally skipping any side effects that may + // occur in the callback function if THIS_FETAB is no + // longer valid. If the editor tab has disappeared, there + // is not much point in reloading the function to restore + // breakpoint info in the GUI. + + if (this_fetab.isNull ()) + return; + + // Force reloading of a file after it is saved. + // This is needed to get the right line numbers for + // breakpoints (bug #46632). + + tree_evaluator& tw = interp.get_evaluator (); + + symbol_table& symtab = interp.get_symbol_table (); + + std::string std_base_name = base_name.toStdString (); + + if (tw.in_debug_repl ()) + { + octave_value sym; + try + { + sym = symtab.find_user_function (std_base_name); + } + catch (const execution_exception&) + { + interp.recover_from_exception (); + + // Ignore syntax error. It was in the old file on disk; + // the user may have fixed it already. + } + + // Return early if this file is not loaded in the symbol table + if (! sym.is_defined () || ! sym.is_user_code ()) + { + emit do_save_file_signal (file_to_save, remove_on_success, + restore_breakpoints); + return; + } + + octave_user_code *fcn = sym.user_code_value (); + + std::string full_name = file_to_save.toStdString (); + + if (sys::canonicalize_file_name (full_name) + != sys::canonicalize_file_name (fcn->fcn_file_name ())) + { + emit do_save_file_signal (file_to_save, remove_on_success, + restore_breakpoints); + return; + } + + // If this file is loaded, check that we aren't currently + // running it. + // FIXME: is there a better way to get this info? + + octave_idx_type curr_frame = -1; + + octave_map stk = tw.backtrace (curr_frame, false); + + Cell names = stk.contents ("name"); + + for (octave_idx_type i = names.numel () - 1; i >= 0; i--) + { + if (names(i).string_value () == std_base_name) + { + emit confirm_dbquit_and_save_signal + (file_to_save, base_name, remove_on_success, + restore_breakpoints); + return; + } + } + } + + symtab.clear_user_function (std_base_name); + + emit do_save_file_signal (file_to_save, remove_on_success, + restore_breakpoints); + }); } else emit do_save_file_signal (saveFileName, remove_on_success, @@ -2308,10 +2345,10 @@ m_file_system_watcher.removePath (file_to_save); // Remove trailing white spaces if desired - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - - if (settings->value (ed_rm_trailing_spaces).toBool ()) + + gui_settings settings; + + if (settings.bool_value (ed_rm_trailing_spaces)) { // Replace trailing spaces, make sure edit area is writable, // which is not the case when saving at exit or when closing @@ -2343,27 +2380,72 @@ return; } - // save the contents into the file - - // write the file - QTextStream out (&file); - - // set the desired codec (if suitable for contents) - QTextCodec *codec = check_valid_codec (); - if (! codec) - return; // No valid codec - - // Save the file - out.setCodec (codec); + // target encoding + std::string encoding = m_encoding.toStdString (); + if (encoding.compare (0, 6, "SYSTEM") == 0) + encoding = octave_locale_charset_wrapper (); + + // check if selected encoding is suitable for contents + if (! check_valid_codec ()) + { + // begin watching file again if it was being watched previously + if (trackedFiles.contains (file_to_save)) + m_file_system_watcher.addPath (file_to_save); + + return; // no valid codec + } + + // save contents of editor in file QApplication::setOverrideCursor (Qt::WaitCursor); - out << m_edit_area->text (); - if (settings->value (ed_force_newline).toBool () - && m_edit_area->text ().length ()) - out << m_edit_area->eol_string (); // Add newline if desired - - out.flush (); + if (encoding == "utf-8" || encoding == "UTF-8") + { + // use Qt encoding conversion for UTF-8 + QTextStream out (&file); + +#if HAVE_QTEXTSTREAM_SETENCODING + out.setEncoding (QStringConverter::Utf8); +#else + out.setCodec ("UTF-8"); +#endif + + out << m_edit_area->text (); + + // add newline if desired + if (settings.bool_value (ed_force_newline) + && m_edit_area->text ().length ()) + out << m_edit_area->eol_string (); + + out.flush (); + } + else + { + // use iconv/gnulib for all other output encodings + QDataStream out (&file); + + // get natively UTF-16 encoded content of the QString as STL type + std::u16string u16_string = m_edit_area->text ().toStdU16String (); + + // convert to output encoding + std::string native_string + = string::u16_to_encoding ("file editor", u16_string, encoding); + + // save file + out.writeRawData (native_string.c_str (), native_string.size ()); + + // add newline if desired + if (settings.bool_value (ed_force_newline) + && m_edit_area->text ().length ()) + { + std::u16string u16_newline + = m_edit_area->eol_string ().toStdU16String (); + std::string newline + = string::u16_to_encoding ("file editor", u16_newline, encoding); + out.writeRawData (newline.c_str (), newline.size ()); + } + } + QApplication::restoreOverrideCursor (); // Finish writing by committing the changes to disk, @@ -2403,8 +2485,8 @@ tr ("Octave Editor"), tr ("The changes could not be saved to the file\n" "%1") - .arg (file.fileName ()) - ); + .arg (file.fileName ()) + ); } } @@ -2464,9 +2546,10 @@ fileDialog->setOption (QFileDialog::HideNameFilterDetails, false); // FIXME: Remove, if for all common KDE versions (bug #54607) is resolved. - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - if (! settings->value (global_use_native_dialogs).toBool ()) + + gui_settings settings; + + if (! settings.bool_value (global_use_native_dialogs)) { // Qt file dialogs fileDialog->setOption(QFileDialog::DontUseNativeDialog); @@ -2509,13 +2592,14 @@ QFileDialog *file_dialog = qobject_cast (sender ()); - QRegExp rx ("\\*\\.([^ ^\\)]*)[ \\)]"); // regexp for suffix in filter - int index = rx.indexIn (filter, 0); // get first suffix in filter - - if (index > -1) - file_dialog->setDefaultSuffix (rx.cap (1)); // found a suffix, set default + // regexp for suffix in filter + QRegularExpression rx {"\\*\\.([^ ^\\)]*)[ \\)]"}; + QRegularExpressionMatch match = rx.match (filter); + + if (match.hasMatch ()) + file_dialog->setDefaultSuffix (match.captured (1)); // found a suffix, set default else - file_dialog->setDefaultSuffix (""); // not found, clear default + file_dialog->setDefaultSuffix (""); // not found, clear default } bool file_editor_tab::check_valid_identifier (QString file_name) @@ -2541,50 +2625,45 @@ return false; } -QTextCodec* file_editor_tab::check_valid_codec () +bool file_editor_tab::check_valid_codec () { - QTextCodec *codec = QTextCodec::codecForName (m_encoding.toLatin1 ()); - - // "SYSTEM" is used as alias for the locale encoding. - if ((! codec) && m_encoding.startsWith("SYSTEM")) - codec = QTextCodec::codecForLocale (); - - if (! codec) - { - QMessageBox::critical (nullptr, - tr ("Octave Editor"), - tr ("The current encoding %1\n" - "can not be applied.\n\n" - "Please select another one!").arg (m_encoding)); - - return nullptr; - } - QString editor_text = m_edit_area->text (); - bool can_encode = codec->canEncode (editor_text); - - // We cannot rely on QTextCodec::canEncode because it uses the - // ConverterState of convertFromUnicode which isn't updated by some - // implementations. - if (can_encode) + + // target encoding + std::string encoding = m_encoding.toStdString (); + if (encoding.compare (0, 6, "SYSTEM") == 0) + encoding = octave_locale_charset_wrapper (); + + if (encoding == "UTF-8" || encoding == "utf-8") + return true; + + // check if encoding is valid + void *codec = octave_iconv_open_wrapper (encoding.c_str (), "utf-8"); + if (codec == reinterpret_cast (-1)) { - QVector u32_str = editor_text.toUcs4 (); - const uint32_t *src = reinterpret_cast - (u32_str.data ()); - - std::size_t length; - const std::string encoding = m_encoding.toStdString (); - char *res_str = - octave_u32_conv_to_encoding_strict (encoding.c_str (), src, - u32_str.size (), &length); - if (! res_str) - { - if (errno == EILSEQ) - can_encode = false; - } - else - ::free (static_cast (res_str)); + if (errno == EINVAL) + return false; } + else + octave_iconv_close_wrapper (codec); + + // check if all characters in the editor can be encoded in the target encoding + bool can_encode = true; + std::u16string u16_str = editor_text.toStdU16String (); + const uint16_t *src = reinterpret_cast + (u16_str.c_str ()); + + std::size_t length; + char *res_str = + octave_u16_conv_to_encoding_strict (encoding.c_str (), src, + u16_str.size (), &length); + if (! res_str) + { + if (errno == EILSEQ) + can_encode = false; + } + else + ::free (static_cast (res_str)); if (! can_encode) { @@ -2599,12 +2678,10 @@ QMessageBox::Cancel); if (pressed_button == QMessageBox::Ignore) - return codec; - else - return nullptr; + can_encode = true; } - return codec; + return can_encode; } void file_editor_tab::handle_save_file_as_answer (const QString& save_file_name) @@ -2628,10 +2705,10 @@ if (file_dialog->testOption (QFileDialog::DontConfirmOverwrite) && file.exists ()) { int ans = QMessageBox::question (file_dialog, - tr ("Octave Editor"), - tr ("%1\n already exists\n" - "Do you want to overwrite it?").arg (saveFileName), - QMessageBox::Yes | QMessageBox::No); + tr ("Octave Editor"), + tr ("%1\n already exists\n" + "Do you want to overwrite it?").arg (saveFileName), + QMessageBox::Yes | QMessageBox::No); if (ans != QMessageBox::Yes) { // Try again, if edit area is read only, remove on success @@ -2666,7 +2743,7 @@ emit editor_check_conflict_save (saveFileName, true); } -void file_editor_tab::handle_save_file_as_answer_cancel (void) +void file_editor_tab::handle_save_file_as_answer_cancel () { // User canceled, allow editing again. m_edit_area->setReadOnly (false); @@ -2767,16 +2844,15 @@ } } -void file_editor_tab::notice_settings (const gui_settings *settings, bool init) +void file_editor_tab::notice_settings (bool init) { - if (! settings) - return; + gui_settings settings; if (! init) update_lexer_settings (); // code folding - if (settings->value (ed_code_folding).toBool ()) + if (settings.bool_value (ed_code_folding)) { m_edit_area->setMarginType (3, QsciScintilla::SymbolMargin); m_edit_area->setFolding (QsciScintilla::BoxedTreeFoldStyle, 3); @@ -2787,20 +2863,18 @@ } // status bar - if (settings->value (ed_show_edit_status_bar).toBool ()) + if (settings.bool_value (ed_show_edit_status_bar)) m_status_bar->show (); else m_status_bar->hide (); //highlight current line color m_edit_area->setCaretLineVisible - (settings->value (ed_highlight_current_line).toBool ()); + (settings.bool_value (ed_highlight_current_line)); // auto completion - bool match_keywords = settings->value - (ed_code_completion_keywords).toBool (); - bool match_document = settings->value - (ed_code_completion_document).toBool (); + bool match_keywords = settings.bool_value (ed_code_completion_keywords); + bool match_document = settings.bool_value (ed_code_completion_document); QsciScintilla::AutoCompletionSource source = QsciScintilla::AcsNone; if (match_keywords) @@ -2813,30 +2887,30 @@ m_edit_area->setAutoCompletionSource (source); m_edit_area->setAutoCompletionReplaceWord - (settings->value (ed_code_completion_replace).toBool ()); + (settings.bool_value (ed_code_completion_replace)); m_edit_area->setAutoCompletionCaseSensitivity - (settings->value (ed_code_completion_case).toBool ()); - - if (settings->value (ed_code_completion).toBool ()) + (settings.bool_value (ed_code_completion_case)); + + if (settings.bool_value (ed_code_completion)) m_edit_area->setAutoCompletionThreshold - (settings->value (ed_code_completion_threshold).toInt ()); + (settings.int_value (ed_code_completion_threshold)); else m_edit_area->setAutoCompletionThreshold (-1); - if (settings->value (ed_show_white_space).toBool ()) - if (settings->value (ed_show_white_space_indent).toBool ()) + if (settings.bool_value (ed_show_white_space)) + if (settings.bool_value (ed_show_white_space_indent)) m_edit_area->setWhitespaceVisibility (QsciScintilla::WsVisibleAfterIndent); else m_edit_area->setWhitespaceVisibility (QsciScintilla::WsVisible); else m_edit_area->setWhitespaceVisibility (QsciScintilla::WsInvisible); - m_edit_area->setEolVisibility (settings->value (ed_show_eol_chars).toBool ()); + m_edit_area->setEolVisibility (settings.bool_value (ed_show_eol_chars)); m_save_as_desired_eol = static_cast - (settings->value (ed_default_eol_mode).toInt ()); - - if (settings->value (ed_show_line_numbers).toBool ()) + (settings.int_value (ed_default_eol_mode)); + + if (settings.bool_value (ed_show_line_numbers)) { m_edit_area->setMarginLineNumbers (2, true); auto_margin_width (); @@ -2849,47 +2923,46 @@ disconnect (m_edit_area, SIGNAL (linesChanged ()), nullptr, nullptr); } - m_smart_indent = settings->value (ed_auto_indent).toBool (); + m_smart_indent = settings.bool_value (ed_auto_indent); m_edit_area->setAutoIndent (m_smart_indent); m_edit_area->setTabIndents - (settings->value (ed_tab_indents_line).toBool ()); + (settings.bool_value (ed_tab_indents_line)); m_edit_area->setBackspaceUnindents - (settings->value (ed_backspace_unindents_line).toBool ()); + (settings.bool_value (ed_backspace_unindents_line)); m_edit_area->setIndentationGuides - (settings->value (ed_show_indent_guides).toBool ()); + (settings.bool_value (ed_show_indent_guides)); m_edit_area->setIndentationsUseTabs - (settings->value (ed_indent_uses_tabs).toBool ()); + (settings.bool_value (ed_indent_uses_tabs)); m_edit_area->setIndentationWidth - (settings->value (ed_indent_width).toInt ()); + (settings.int_value (ed_indent_width)); m_edit_area->setTabWidth - (settings->value (ed_tab_width).toInt ()); + (settings.int_value (ed_tab_width)); m_ind_char_width = 1; if (m_edit_area->indentationsUseTabs ()) m_ind_char_width = m_edit_area->tabWidth (); m_edit_area->SendScintilla (QsciScintillaBase::SCI_SETHSCROLLBAR, - settings->value (ed_show_hscroll_bar).toBool ()); + settings.bool_value (ed_show_hscroll_bar)); m_edit_area->SendScintilla (QsciScintillaBase::SCI_SETSCROLLWIDTH,-1); m_edit_area->SendScintilla (QsciScintillaBase::SCI_SETSCROLLWIDTHTRACKING,true); update_window_title (m_edit_area->isModified ()); - m_auto_endif = settings->value (ed_auto_endif).toInt (); + m_auto_endif = settings.int_value (ed_auto_endif); // long line marker - int line_length = settings->value (ed_long_line_column).toInt (); + int line_length = settings.int_value (ed_long_line_column); m_edit_area->setEdgeColumn (line_length); - if (settings->value (ed_long_line_marker).toBool ()) + if (settings.bool_value (ed_long_line_marker)) { - if (settings->value (ed_long_line_marker_line).toBool ()) + if (settings.bool_value (ed_long_line_marker_line)) m_edit_area->setEdgeMode (QsciScintilla::EdgeLine); else { - if (settings->value (ed_long_line_marker_background) - .toBool ()) + if (settings.bool_value (ed_long_line_marker_background)) m_edit_area->setEdgeMode (QsciScintilla::EdgeBackground); else m_edit_area->setEdgeMode (QsciScintilla::EdgeLine); @@ -2902,36 +2975,36 @@ m_edit_area->setWrapVisualFlags (QsciScintilla::WrapFlagByBorder); m_edit_area->setWrapIndentMode (QsciScintilla::WrapIndentSame); - if (settings->value (ed_wrap_lines).toBool ()) + if (settings.bool_value (ed_wrap_lines)) m_edit_area->setWrapMode (QsciScintilla::WrapWord); else m_edit_area->setWrapMode (QsciScintilla::WrapNone); - if (settings->value (ed_break_lines).toBool ()) + if (settings.bool_value (ed_break_lines)) m_line_break = line_length; else m_line_break = 0; m_line_break_comments = - settings->value (ed_break_lines_comments).toBool (); + settings.bool_value (ed_break_lines_comments); // highlight all occurrences of a word selected by a double click m_highlight_all_occurrences = - settings->value (ed_highlight_all_occurrences).toBool (); + settings.bool_value (ed_highlight_all_occurrences); // reload changed files m_always_reload_changed_files = - settings->value (ed_always_reload_changed_files).toBool (); + settings.bool_value (ed_always_reload_changed_files); // Set cursor blinking depending on the settings. // QScintilla ignores the application global settings, so some special // handling is required bool cursor_blinking; - if (settings->contains (global_cursor_blinking.key)) - cursor_blinking = settings->value (global_cursor_blinking).toBool (); + if (settings.contains (global_cursor_blinking.settings_key ())) + cursor_blinking = settings.bool_value (global_cursor_blinking); else - cursor_blinking = settings->value (cs_cursor_blinking).toBool (); + cursor_blinking = settings.bool_value (cs_cursor_blinking); if (cursor_blinking) m_edit_area->SendScintilla (QsciScintillaBase::SCI_SETCARETPERIOD, 500); @@ -2940,7 +3013,7 @@ } -void file_editor_tab::auto_margin_width (void) +void file_editor_tab::auto_margin_width () { m_edit_area->setMarginWidth (2, "1" + QString::number (m_edit_area->lines ())); } @@ -2950,7 +3023,7 @@ // the tab really was closed (for canceling exiting octave). // When emitting a signal, only the return value from the last slot // goes back to the sender -bool file_editor_tab::conditional_close (void) +bool file_editor_tab::conditional_close () { return close (); } @@ -3094,7 +3167,7 @@ int editor_linenr = -1; marker *bp = nullptr; - // If comes back indicating a non-zero breakpoint marker, + // If comes back indicating a nonzero breakpoint marker, // reuse it if possible emit find_translated_line_number (line, editor_linenr, bp); if (bp != nullptr) @@ -3163,7 +3236,7 @@ } } -void file_editor_tab::handle_lines_changed (void) +void file_editor_tab::handle_lines_changed () { // the related signal is emitted before cursor-move-signal! m_lines_changed = true; @@ -3185,8 +3258,8 @@ // Lines changed? Take care of indentation! bool do_smart_indent = m_lines_changed && m_is_octave_file - && (line == m_line+1) && (col < m_col) - && (m_smart_indent || m_auto_endif); + && (line == m_line+1) && (col < m_col) + && (m_smart_indent || m_auto_endif); m_lines_changed = false; // Update line and column indicator in the status bar @@ -3321,7 +3394,7 @@ #if defined (HAVE_QSCI_VERSION_2_6_0) , true #endif - ); + ); // loop over all occurrences and set the related indicator int oline, ocol; @@ -3350,28 +3423,33 @@ } } -QString file_editor_tab::get_function_name (void) +QString file_editor_tab::get_function_name () { - QRegExp rxfun1 ("^[\t ]*function[^=]+=([^\\(]+)\\([^\\)]*\\)[\t ]*$"); - QRegExp rxfun2 ("^[\t ]*function[\t ]+([^\\(]+)\\([^\\)]*\\)[\t ]*$"); - QRegExp rxfun3 ("^[\t ]*function[^=]+=[\t ]*([^\\s]+)[\t ]*$"); - QRegExp rxfun4 ("^[\t ]*function[\t ]+([^\\s]+)[\t ]*$"); - QRegExp rxfun5 ("^[\t ]*classdef[\t ]+([^\\s]+)[\t ]*$"); + QRegularExpression rxfun1 {"^[\t ]*function[^=]+=([^\\(]+)\\([^\\)]*\\)[\t ]*$"}; + QRegularExpression rxfun2 {"^[\t ]*function[\t ]+([^\\(]+)\\([^\\)]*\\)[\t ]*$"}; + QRegularExpression rxfun3 {"^[\t ]*function[^=]+=[\t ]*([^\\s]+)[\t ]*$"}; + QRegularExpression rxfun4 {"^[\t ]*function[\t ]+([^\\s]+)[\t ]*$"}; + QRegularExpression rxfun5 {"^[\t ]*classdef[\t ]+([^\\s]+)[\t ]*$"}; QStringList lines = m_edit_area->text ().split ("\n"); for (int i = 0; i < lines.count (); i++) { - if (rxfun1.indexIn (lines.at (i)) != -1) - return rxfun1.cap (1).remove (QRegExp ("[ \t]*")); - else if (rxfun2.indexIn (lines.at (i)) != -1) - return rxfun2.cap (1).remove (QRegExp ("[ \t]*")); - else if (rxfun3.indexIn (lines.at (i)) != -1) - return rxfun3.cap (1).remove (QRegExp ("[ \t]*")); - else if (rxfun4.indexIn (lines.at (i)) != -1) - return rxfun4.cap (1).remove (QRegExp ("[ \t]*")); - else if (rxfun5.indexIn (lines.at (i)) != -1) - return rxfun5.cap (1).remove (QRegExp ("[ \t]*")); + QRegularExpressionMatch match = rxfun1.match (lines.at (i)); + if (match.hasMatch ()) + return match.captured (1).remove (QRegularExpression {"[ \t]*"}); + match = rxfun2.match (lines.at (i)); + if (match.hasMatch ()) + return match.captured (1).remove (QRegularExpression {"[ \t]*"}); + match = rxfun3.match (lines.at (i)); + if (match.hasMatch ()) + return match.captured (1).remove (QRegularExpression {"[ \t]*"}); + match = rxfun4.match (lines.at (i)); + if (match.hasMatch ()) + return match.captured (1).remove (QRegularExpression {"[ \t]*"}); + match = rxfun5.match (lines.at (i)); + if (match.hasMatch ()) + return match.captured (1).remove (QRegularExpression {"[ \t]*"}); } return QString (); diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/m-editor/file-editor-tab.h --- a/libgui/src/m-editor/file-editor-tab.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/m-editor/file-editor-tab.h Fri May 12 08:03:14 2023 +0200 @@ -36,7 +36,6 @@ #include #include -#include "gui-settings.h" #include "marker.h" #include "octave-qscintilla.h" #include "qt-interpreter-events.h" @@ -45,7 +44,6 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; class file_editor; class file_editor_tab : public QWidget @@ -54,25 +52,25 @@ public: - file_editor_tab (base_qobject& oct_qobj, const QString& directory = ""); + file_editor_tab (const QString& directory = ""); - ~file_editor_tab (void); + ~file_editor_tab (); - octave_qscintilla * qsci_edit_area (void) { return m_edit_area; } + octave_qscintilla * qsci_edit_area () { return m_edit_area; } // Will initiate close if associated with the identifier tag. - bool conditional_close (void); + bool conditional_close (); void update_breakpoints (); void set_file_name (const QString& fileName); void enable_file_watcher (bool do_enable); - QString file_name (void) const { return m_file_name; } - QString encoding (void) const { return m_encoding; } + QString file_name () const { return m_file_name; } + QString encoding () const { return m_encoding; } signals: - void tab_ready_to_close (void); + void tab_ready_to_close (); void file_name_changed (const QString& fileName, const QString& toolTip, bool modified); @@ -80,7 +78,7 @@ bool is_modified); void set_focus_editor_signal (QWidget *); void edit_area_changed (octave_qscintilla *edit_area); - void tab_remove_request (void); + void tab_remove_request (); void mru_add_file (const QString& file_name, const QString& encoding); void editor_check_conflict_save (const QString& saveFileName, bool remove_on_success); @@ -89,22 +87,22 @@ void edit_mfile_request (const QString&, const QString&, const QString&, int); - void autoc_closed (void); + void autoc_closed (); void update_breakpoints_signal (const octave_value_list& args); void remove_breakpoint_via_debugger_linenr (int debugger_linenr); void request_remove_breakpoint_via_editor_linenr (int editor_linenr); - void remove_all_breakpoints_signal (void); + void remove_all_breakpoints_signal (); void find_translated_line_number (int original_linenr, int& translated_linenr, marker*&); void find_linenr_just_before (int linenr, int& original_linenr, int& editor_linenr); void report_marker_linenr (QIntList& lines, QStringList& conditions); void remove_position_via_debugger_linenr (int debugger_linenr); - void remove_all_positions (void); + void remove_all_positions (); - void debug_quit_signal (void); + void debug_quit_signal (); void interpreter_event (const fcn_callback& fcn); void interpreter_event (const meth_callback& meth); @@ -114,7 +112,7 @@ void dbstop_if (const QString& prompt, int line, const QString& cond); void request_add_breakpoint (int line, const QString& cond); void request_add_octave_apis (const QStringList&); - void api_entries_added (void); + void api_entries_added (); void do_save_file_signal (const QString& file_to_save, bool remove_on_success, bool restore_breakpoints); @@ -138,7 +136,7 @@ Qt::KeyboardModifiers state); // Tells the editor tab to react on changed settings. - void notice_settings (const gui_settings *settings, bool init = false); + void notice_settings (bool init = false); // Change to a different editor tab by identifier tag. void change_editor_state (const QWidget *ID); @@ -188,7 +186,7 @@ void do_breakpoint_marker (bool insert, const QWidget *ID, int line = -1, const QString& cond = ""); - void recover_from_exit (void); + void recover_from_exit (); void set_modified (bool modified = true); void set_encoding (const QString& new_encoding); @@ -223,28 +221,28 @@ // When user closes QFileDialog box. void handle_save_file_as_answer (const QString& fileName); void handle_save_file_as_answer_close (const QString& fileName); - void handle_save_file_as_answer_cancel (void); + void handle_save_file_as_answer_cancel (); void handle_save_as_filter_selected (const QString& filter); // When user changes encoding after decoding errors were found void handle_current_enc_changed (const QString& enc); // When apis preparation has finished and is ready to save - void save_apis_info (void); + void save_apis_info (); // When the numer of lines changes -> adapt width of margin - void auto_margin_width (void); + void auto_margin_width (); void handle_cursor_moved (int line, int col); void handle_char_added (int character); void handle_double_click (int p, int l, int modifier); - void handle_lines_changed (void); + void handle_lines_changed (); void handle_remove_next (int remove_line); void handle_dbstop_if (const QString& prompt, int line, const QString& cond); void handle_add_octave_apis (const QStringList& api_entries); - void handle_api_entries_added (void); + void handle_api_entries_added (); void do_save_file (const QString& file_to_save, bool remove_on_success, bool restore_breakpoints); @@ -260,8 +258,6 @@ private: - base_qobject& m_octave_qobj; - void add_breakpoint_event (int line, const QString& cond); bool valid_file_name (const QString& file = QString ()); @@ -269,31 +265,31 @@ bool restore_breakpoints = true); void save_file_as (bool remove_on_success = false); bool check_valid_identifier (QString file_name); - QTextCodec * check_valid_codec (void); + bool check_valid_codec (); - bool unchanged_or_saved (void); + bool unchanged_or_saved (); - void update_lexer (void); + void update_lexer (); void show_dialog (QDialog *dlg, bool modal); public: int check_file_modified (bool remove = false); - QString get_all_bookmarks (void); + QString get_all_bookmarks (); private: void do_comment_selected_text (bool comment, bool input_str = false); void do_indent_selected_text (bool indent); - void do_smart_indent_line_or_selected_text (void); + void do_smart_indent_line_or_selected_text (); - void check_restore_breakpoints (void); + void check_restore_breakpoints (); void center_current_line (bool always=true); - QString get_function_name (void); + QString get_function_name (); - QsciScintilla::EolMode detect_eol_mode (void); - void update_eol_indicator (void); + QsciScintilla::EolMode detect_eol_mode (); + void update_eol_indicator (); octave_qscintilla *m_edit_area; diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/m-editor/file-editor.cc --- a/libgui/src/m-editor/file-editor.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/m-editor/file-editor.cc Fri May 12 08:03:14 2023 +0200 @@ -50,11 +50,10 @@ #include "gui-preferences-ed.h" #include "gui-preferences-sc.h" #include "gui-preferences-global.h" +#include "gui-settings.h" #include "main-window.h" -#include "octave-qobject.h" -#include "octave-qtutils.h" -#include "shortcut-manager.h" - + +#include "lo-sysdep.h" #include "oct-env.h" #include "event-manager.h" @@ -68,7 +67,7 @@ // Functions of the the reimplemented tab widget file_editor_tab_widget::file_editor_tab_widget (QWidget *p, file_editor *fe) -: QTabWidget (p) + : QTabWidget (p) { tab_bar *bar = new tab_bar (this); @@ -82,13 +81,13 @@ setMovable (true); } -tab_bar *file_editor_tab_widget::get_tab_bar (void) const +tab_bar *file_editor_tab_widget::get_tab_bar () const { return qobject_cast (tabBar ()); } std::list -file_editor_tab_widget::tab_list (void) const +file_editor_tab_widget::tab_list () const { std::list retval; for (int i = 0; i < count (); i++) @@ -98,8 +97,8 @@ // File editor -file_editor::file_editor (QWidget *p, base_qobject& oct_qobj) - : file_editor_interface (p, oct_qobj) +file_editor::file_editor (QWidget *p) + : file_editor_interface (p) { // Set current editing directory before construction because loaded // files will change ced accordingly. @@ -178,12 +177,12 @@ m_edit_menu->insertAction (m_find_action, m_find_files_action); } -void file_editor::handle_enter_debug_mode (void) +void file_editor::handle_enter_debug_mode () { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - QString sc_run = settings->sc_value (sc_edit_run_run_file); - QString sc_cont = settings->sc_value (sc_main_debug_continue); + gui_settings settings; + + QString sc_run = settings.sc_value (sc_edit_run_run_file); + QString sc_cont = settings.sc_value (sc_main_debug_continue); if (sc_run == sc_cont) m_run_action->setShortcut (QKeySequence ()); // prevent ambiguous shortcuts @@ -193,16 +192,16 @@ emit enter_debug_mode_signal (); } -void file_editor::handle_exit_debug_mode (void) +void file_editor::handle_exit_debug_mode () { - shortcut_manager& scmgr = m_octave_qobj.get_shortcut_manager (); - scmgr.set_shortcut (m_run_action, sc_edit_run_run_file); + gui_settings settings; + settings.set_shortcut (m_run_action, sc_edit_run_run_file); m_run_action->setToolTip (tr ("Save File and Run")); // update tool tip emit exit_debug_mode_signal (); } -void file_editor::check_actions (void) +void file_editor::check_actions () { // Do not include shared actions not only related to the editor bool have_tabs = m_tab_widget->count () > 0; @@ -264,10 +263,10 @@ return; // not yet ready but got visibility changed signals } - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - if (settings->value (global_use_custom_editor.key, - global_use_custom_editor.def).toBool ()) + gui_settings settings; + + if (settings.value (global_use_custom_editor.settings_key (), + global_use_custom_editor.def ()).toBool ()) return; // do not open an empty script in the external editor bool real_visible; @@ -317,27 +316,29 @@ request_new_file (""); } -void file_editor::restore_session (gui_settings *settings) +void file_editor::restore_session () { + gui_settings settings; + //restore previous session - if (! settings->value (ed_restore_session).toBool ()) + if (! settings.bool_value (ed_restore_session)) return; // get the data from the settings file QStringList sessionFileNames - = settings->value (ed_session_names).toStringList (); + = settings.string_list_value (ed_session_names); QStringList session_encodings - = settings->value (ed_session_enc).toStringList (); + = settings.string_list_value (ed_session_enc); QStringList session_index - = settings->value (ed_session_ind).toStringList (); + = settings.string_list_value (ed_session_ind); QStringList session_lines - = settings->value (ed_session_lines).toStringList (); + = settings.string_list_value (ed_session_lines); QStringList session_bookmarks - = settings->value (ed_session_bookmarks).toStringList (); + = settings.string_list_value (ed_session_bookmarks); // fill a list of the struct and sort it (depending on index) QList s_data; @@ -354,7 +355,7 @@ continue; session_data item = { 0, -1, sessionFileNames.at (n), - QString (), QString (), QString ()}; + QString (), QString (), QString ()}; if (do_lines) item.line = session_lines.at (n).toInt (); if (do_index) @@ -376,7 +377,7 @@ s_data.at (n).bookmarks); } -void file_editor::activate (void) +void file_editor::activate () { if (m_no_focus) return; // No focus for the editor if external open/close request @@ -437,10 +438,9 @@ // Save open files for restoring in next session // (even if last session will not be restored next time) // together with encoding and the tab index -void file_editor::save_session (void) +void file_editor::save_session () { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); + gui_settings settings; QStringList fetFileNames; QStringList fet_encodings; @@ -472,15 +472,16 @@ } } - settings->setValue (ed_session_names.key, fetFileNames); - settings->setValue (ed_session_enc.key, fet_encodings); - settings->setValue (ed_session_ind.key, fet_index); - settings->setValue (ed_session_lines.key, fet_lines); - settings->setValue (ed_session_bookmarks.key, fet_bookmarks); - settings->sync (); + settings.setValue (ed_session_names.settings_key (), fetFileNames); + settings.setValue (ed_session_enc.settings_key (), fet_encodings); + settings.setValue (ed_session_ind.settings_key (), fet_index); + settings.setValue (ed_session_lines.settings_key (), fet_lines); + settings.setValue (ed_session_bookmarks.settings_key (), fet_bookmarks); + + settings.sync (); } -bool file_editor::check_closing (void) +bool file_editor::check_closing () { // When the application or the editor is closing and the user wants to // close all files, in the latter case all editor tabs are checked whether @@ -530,7 +531,7 @@ return true; } -void file_editor::handle_tab_ready_to_close (void) +void file_editor::handle_tab_ready_to_close () { if (m_closing_canceled) return; @@ -689,29 +690,29 @@ emit interpreter_event ([=] (interpreter& interp) - { - // INTERPRETER THREAD - - // If THIS_FE is no longer valid, skip the entire callback - // function. With the way things are implemented now, we can't - // run the contents of a file unless the file editor and the - // corresponding file editor tab are still valid. - - if (this_fe.isNull ()) - return; - - // Act as though this action was entered at the command propmt - // so that the interpreter will check for updated file time - // stamps. - Vlast_prompt_time.stamp (); - - tree_evaluator& tw = interp.get_evaluator (); - - if (tw.in_debug_repl ()) - emit request_dbcont_signal (); - else - emit fetab_run_file (m_tab_widget->currentWidget ()); - }); + { + // INTERPRETER THREAD + + // If THIS_FE is no longer valid, skip the entire callback + // function. With the way things are implemented now, we can't + // run the contents of a file unless the file editor and the + // corresponding file editor tab are still valid. + + if (this_fe.isNull ()) + return; + + // Act as though this action was entered at the command propmt + // so that the interpreter will check for updated file time + // stamps. + Vlast_prompt_time.stamp (); + + tree_evaluator& tw = interp.get_evaluator (); + + if (tw.in_debug_repl ()) + emit request_dbcont_signal (); + else + emit fetab_run_file (m_tab_widget->currentWidget ()); + }); } void file_editor::request_step_into_file () @@ -914,9 +915,9 @@ m_find_dialog->close (); if (isFloating ()) - m_find_dialog = new find_dialog (m_octave_qobj, this, this); + m_find_dialog = new find_dialog (this, this); else - m_find_dialog = new find_dialog (m_octave_qobj, this, parentWidget ()); + m_find_dialog = new find_dialog (this, parentWidget ()); // Add required actions m_find_dialog->addAction (m_find_next_action); @@ -987,7 +988,7 @@ QObject *fileEditorTab = sender (); if (fileEditorTab) { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); + gui_settings settings; for (int i = 0; i < m_tab_widget->count (); i++) { @@ -1000,7 +1001,7 @@ m_current_tab_modified = modified; if (modified) - m_tab_widget->setTabIcon (i, rmgr.icon ("document-save")); + m_tab_widget->setTabIcon (i, settings.icon ("document-save")); else m_tab_widget->setTabIcon (i, QIcon ()); } @@ -1016,7 +1017,7 @@ } void -file_editor::handle_tab_remove_request (void) +file_editor::handle_tab_remove_request () { QObject *fileEditorTab = sender (); if (fileEditorTab) @@ -1268,8 +1269,7 @@ if (m_tmp_closed_files.at (i).new_file_name.isEmpty ()) m_tmp_closed_files.at (i).editor_tab->file_has_changed (QString (), true); else - m_tmp_closed_files.at (i).editor_tab->set_file_name ( - m_tmp_closed_files.at (i).new_file_name); + m_tmp_closed_files.at (i).editor_tab->set_file_name (m_tmp_closed_files.at (i).new_file_name); } else { @@ -1286,9 +1286,11 @@ m_tmp_closed_files.clear (); } -void file_editor::notice_settings (const gui_settings *settings) +void file_editor::notice_settings () { - int size_idx = settings->value (global_icon_size).toInt (); + gui_settings settings; + + int size_idx = settings.int_value (global_icon_size); size_idx = (size_idx > 0) - (size_idx < 0) + 1; // Make valid index from 0 to 2 QStyle *st = style (); @@ -1297,14 +1299,14 @@ // Tab position and rotation QTabWidget::TabPosition pos - = static_cast (settings->value (ed_tab_position).toInt ()); - bool rotated = settings->value (ed_tabs_rotated).toBool (); + = static_cast (settings.int_value (ed_tab_position)); + bool rotated = settings.bool_value (ed_tabs_rotated); m_tab_widget->setTabPosition (pos); if (rotated) m_tab_widget->setTabsClosable (false); // No close buttons - // FIXME: close buttons can not be correctly placed in rotated tabs + // FIXME: close buttons can not be correctly placed in rotated tabs // Get the tab bar and set the rotation int rotation = rotated; @@ -1321,7 +1323,7 @@ height = is; // Calculate possibly limited width and set the elide mode - int chars = settings->value (ed_tabs_max_width).toInt (); + int chars = settings.int_value (ed_tabs_max_width); int width = 9999; if (chars > 0) width = chars * QFontMetrics (m_tab_widget->font ()).averageCharWidth (); @@ -1336,9 +1338,9 @@ } QString style_sheet - = QString ("QTabBar::tab {max-" + height_str + ": %1px;\n" - "max-" + width_str + ": %2px; }") - .arg (height).arg (width); + = QString ("QTabBar::tab {max-" + height_str + ": %1px;\n" + "max-" + width_str + ": %2px; }") + .arg (height).arg (width); #if defined (Q_OS_MAC) // FIXME: This is a workaround for missing tab close buttons on MacOS @@ -1347,13 +1349,13 @@ { QString icon = global_icon_paths.at (ICON_THEME_OCTAVE) + "widget-close.png"; - QString close_button_css_mac ( - "QTabBar::close-button" - " { image: url(" + icon + ");" - " padding: 4px;" - " subcontrol-position: bottom; }\n" - "QTabBar::close-button:hover" - " { background-color: #cccccc; }"); + QString close_button_css_mac + ("QTabBar::close-button" + " { image: url(" + icon + ");" + " padding: 4px;" + " subcontrol-position: bottom; }\n" + "QTabBar::close-button:hover" + " { background-color: #cccccc; }"); style_sheet = style_sheet + close_button_css_mac; } @@ -1362,23 +1364,23 @@ m_tab_widget->setStyleSheet (style_sheet); bool show_it; - show_it = settings->value (ed_show_line_numbers).toBool (); + show_it = settings.bool_value (ed_show_line_numbers); m_show_linenum_action->setChecked (show_it); - show_it = settings->value (ed_show_white_space).toBool (); + show_it = settings.bool_value (ed_show_white_space); m_show_whitespace_action->setChecked (show_it); - show_it = settings->value (ed_show_eol_chars).toBool (); + show_it = settings.bool_value (ed_show_eol_chars); m_show_eol_action->setChecked (show_it); - show_it = settings->value (ed_show_indent_guides).toBool (); + show_it = settings.bool_value (ed_show_indent_guides); m_show_indguide_action->setChecked (show_it); - show_it = settings->value (ed_long_line_marker).toBool (); + show_it = settings.bool_value (ed_long_line_marker); m_show_longline_action->setChecked (show_it); - show_it = settings->value (ed_show_toolbar).toBool (); + show_it = settings.bool_value (ed_show_toolbar); m_show_toolbar_action->setChecked (show_it); m_tool_bar->setVisible (show_it); - show_it = settings->value (ed_show_edit_status_bar).toBool (); + show_it = settings.bool_value (ed_show_edit_status_bar); m_show_statusbar_action->setChecked (show_it); - show_it = settings->value (ed_show_hscroll_bar).toBool (); + show_it = settings.bool_value (ed_show_hscroll_bar); m_show_hscrollbar_action->setChecked (show_it); set_shortcuts (); @@ -1388,99 +1390,98 @@ m_find_dialog->setWindowIcon (windowIcon ()); // Relay signal to file editor tabs. - emit fetab_settings_changed (settings); + emit fetab_settings_changed (); } -void file_editor::set_shortcuts (void) +void file_editor::set_shortcuts () { // Shortcuts also available in the main window, as well as the related // shortcuts, are defined in main_window and added to the editor - shortcut_manager& scmgr = m_octave_qobj.get_shortcut_manager (); + gui_settings settings; // File menu - scmgr.set_shortcut (m_edit_function_action, sc_edit_file_edit_function); - scmgr.set_shortcut (m_save_action, sc_edit_file_save); - scmgr.set_shortcut (m_save_as_action, sc_edit_file_save_as); - scmgr.set_shortcut (m_close_action, sc_edit_file_close); - scmgr.set_shortcut (m_close_all_action, sc_edit_file_close_all); - scmgr.set_shortcut (m_close_others_action, sc_edit_file_close_other); - scmgr.set_shortcut (m_print_action, sc_edit_file_print); + settings.set_shortcut (m_edit_function_action, sc_edit_file_edit_function); + settings.set_shortcut (m_save_action, sc_edit_file_save); + settings.set_shortcut (m_save_as_action, sc_edit_file_save_as); + settings.set_shortcut (m_close_action, sc_edit_file_close); + settings.set_shortcut (m_close_all_action, sc_edit_file_close_all); + settings.set_shortcut (m_close_others_action, sc_edit_file_close_other); + settings.set_shortcut (m_print_action, sc_edit_file_print); // Edit menu - scmgr.set_shortcut (m_redo_action, sc_edit_edit_redo); - scmgr.set_shortcut (m_cut_action, sc_edit_edit_cut); - scmgr.set_shortcut (m_find_action, sc_edit_edit_find_replace); - scmgr.set_shortcut (m_find_next_action, sc_edit_edit_find_next); - scmgr.set_shortcut (m_find_previous_action, sc_edit_edit_find_previous); - - scmgr.set_shortcut (m_delete_start_word_action, sc_edit_edit_delete_start_word); - scmgr.set_shortcut (m_delete_end_word_action, sc_edit_edit_delete_end_word); - scmgr.set_shortcut (m_delete_start_line_action, sc_edit_edit_delete_start_line); - scmgr.set_shortcut (m_delete_end_line_action, sc_edit_edit_delete_end_line); - scmgr.set_shortcut (m_delete_line_action, sc_edit_edit_delete_line); - scmgr.set_shortcut (m_copy_line_action, sc_edit_edit_copy_line); - scmgr.set_shortcut (m_cut_line_action, sc_edit_edit_cut_line); - scmgr.set_shortcut (m_duplicate_selection_action, sc_edit_edit_duplicate_selection); - scmgr.set_shortcut (m_transpose_line_action, sc_edit_edit_transpose_line); - scmgr.set_shortcut (m_comment_selection_action, sc_edit_edit_comment_selection); - scmgr.set_shortcut (m_uncomment_selection_action, sc_edit_edit_uncomment_selection); - scmgr.set_shortcut (m_comment_var_selection_action, sc_edit_edit_comment_var_selection); - - scmgr.set_shortcut (m_upper_case_action, sc_edit_edit_upper_case); - scmgr.set_shortcut (m_lower_case_action, sc_edit_edit_lower_case); - scmgr.set_shortcut (m_indent_selection_action, sc_edit_edit_indent_selection); - scmgr.set_shortcut (m_unindent_selection_action, sc_edit_edit_unindent_selection); - scmgr.set_shortcut (m_smart_indent_line_or_selection_action, sc_edit_edit_smart_indent_line_or_selection); - scmgr.set_shortcut (m_completion_action, sc_edit_edit_completion_list); - scmgr.set_shortcut (m_goto_line_action, sc_edit_edit_goto_line); - scmgr.set_shortcut (m_move_to_matching_brace, sc_edit_edit_move_to_brace); - scmgr.set_shortcut (m_sel_to_matching_brace, sc_edit_edit_select_to_brace); - scmgr.set_shortcut (m_toggle_bookmark_action, sc_edit_edit_toggle_bookmark); - scmgr.set_shortcut (m_next_bookmark_action, sc_edit_edit_next_bookmark); - scmgr.set_shortcut (m_previous_bookmark_action, sc_edit_edit_previous_bookmark); - scmgr.set_shortcut (m_remove_bookmark_action, sc_edit_edit_remove_bookmark); - scmgr.set_shortcut (m_preferences_action, sc_edit_edit_preferences); - scmgr.set_shortcut (m_styles_preferences_action, sc_edit_edit_styles_preferences); - - scmgr.set_shortcut (m_conv_eol_windows_action, sc_edit_edit_conv_eol_winows); - scmgr.set_shortcut (m_conv_eol_unix_action, sc_edit_edit_conv_eol_unix); - scmgr.set_shortcut (m_conv_eol_mac_action, sc_edit_edit_conv_eol_mac); + settings.set_shortcut (m_redo_action, sc_edit_edit_redo); + settings.set_shortcut (m_cut_action, sc_edit_edit_cut); + settings.set_shortcut (m_find_action, sc_edit_edit_find_replace); + settings.set_shortcut (m_find_next_action, sc_edit_edit_find_next); + settings.set_shortcut (m_find_previous_action, sc_edit_edit_find_previous); + + settings.set_shortcut (m_delete_start_word_action, sc_edit_edit_delete_start_word); + settings.set_shortcut (m_delete_end_word_action, sc_edit_edit_delete_end_word); + settings.set_shortcut (m_delete_start_line_action, sc_edit_edit_delete_start_line); + settings.set_shortcut (m_delete_end_line_action, sc_edit_edit_delete_end_line); + settings.set_shortcut (m_delete_line_action, sc_edit_edit_delete_line); + settings.set_shortcut (m_copy_line_action, sc_edit_edit_copy_line); + settings.set_shortcut (m_cut_line_action, sc_edit_edit_cut_line); + settings.set_shortcut (m_duplicate_selection_action, sc_edit_edit_duplicate_selection); + settings.set_shortcut (m_transpose_line_action, sc_edit_edit_transpose_line); + settings.set_shortcut (m_comment_selection_action, sc_edit_edit_comment_selection); + settings.set_shortcut (m_uncomment_selection_action, sc_edit_edit_uncomment_selection); + settings.set_shortcut (m_comment_var_selection_action, sc_edit_edit_comment_var_selection); + + settings.set_shortcut (m_upper_case_action, sc_edit_edit_upper_case); + settings.set_shortcut (m_lower_case_action, sc_edit_edit_lower_case); + settings.set_shortcut (m_indent_selection_action, sc_edit_edit_indent_selection); + settings.set_shortcut (m_unindent_selection_action, sc_edit_edit_unindent_selection); + settings.set_shortcut (m_smart_indent_line_or_selection_action, sc_edit_edit_smart_indent_line_or_selection); + settings.set_shortcut (m_completion_action, sc_edit_edit_completion_list); + settings.set_shortcut (m_goto_line_action, sc_edit_edit_goto_line); + settings.set_shortcut (m_move_to_matching_brace, sc_edit_edit_move_to_brace); + settings.set_shortcut (m_sel_to_matching_brace, sc_edit_edit_select_to_brace); + settings.set_shortcut (m_toggle_bookmark_action, sc_edit_edit_toggle_bookmark); + settings.set_shortcut (m_next_bookmark_action, sc_edit_edit_next_bookmark); + settings.set_shortcut (m_previous_bookmark_action, sc_edit_edit_previous_bookmark); + settings.set_shortcut (m_remove_bookmark_action, sc_edit_edit_remove_bookmark); + settings.set_shortcut (m_preferences_action, sc_edit_edit_preferences); + settings.set_shortcut (m_styles_preferences_action, sc_edit_edit_styles_preferences); + + settings.set_shortcut (m_conv_eol_windows_action, sc_edit_edit_conv_eol_winows); + settings.set_shortcut (m_conv_eol_unix_action, sc_edit_edit_conv_eol_unix); + settings.set_shortcut (m_conv_eol_mac_action, sc_edit_edit_conv_eol_mac); // View menu - scmgr.set_shortcut (m_show_linenum_action, sc_edit_view_show_line_numbers); - scmgr.set_shortcut (m_show_whitespace_action, sc_edit_view_show_white_spaces); - scmgr.set_shortcut (m_show_eol_action, sc_edit_view_show_eol_chars); - scmgr.set_shortcut (m_show_indguide_action, sc_edit_view_show_ind_guides); - scmgr.set_shortcut (m_show_longline_action, sc_edit_view_show_long_line); - scmgr.set_shortcut (m_show_toolbar_action, sc_edit_view_show_toolbar); - scmgr.set_shortcut (m_show_statusbar_action, sc_edit_view_show_statusbar); - scmgr.set_shortcut (m_show_hscrollbar_action, sc_edit_view_show_hscrollbar); - scmgr.set_shortcut (m_zoom_in_action, sc_edit_view_zoom_in); - scmgr.set_shortcut (m_zoom_out_action, sc_edit_view_zoom_out); - scmgr.set_shortcut (m_zoom_normal_action, sc_edit_view_zoom_normal); - scmgr.set_shortcut (m_sort_tabs_action, sc_edit_view_sort_tabs); + settings.set_shortcut (m_show_linenum_action, sc_edit_view_show_line_numbers); + settings.set_shortcut (m_show_whitespace_action, sc_edit_view_show_white_spaces); + settings.set_shortcut (m_show_eol_action, sc_edit_view_show_eol_chars); + settings.set_shortcut (m_show_indguide_action, sc_edit_view_show_ind_guides); + settings.set_shortcut (m_show_longline_action, sc_edit_view_show_long_line); + settings.set_shortcut (m_show_toolbar_action, sc_edit_view_show_toolbar); + settings.set_shortcut (m_show_statusbar_action, sc_edit_view_show_statusbar); + settings.set_shortcut (m_show_hscrollbar_action, sc_edit_view_show_hscrollbar); + settings.set_shortcut (m_zoom_in_action, sc_edit_view_zoom_in); + settings.set_shortcut (m_zoom_out_action, sc_edit_view_zoom_out); + settings.set_shortcut (m_zoom_normal_action, sc_edit_view_zoom_normal); + settings.set_shortcut (m_sort_tabs_action, sc_edit_view_sort_tabs); // Debug menu - scmgr.set_shortcut (m_toggle_breakpoint_action, sc_edit_debug_toggle_breakpoint); - scmgr.set_shortcut (m_next_breakpoint_action, sc_edit_debug_next_breakpoint); - scmgr.set_shortcut (m_previous_breakpoint_action, sc_edit_debug_previous_breakpoint); - scmgr.set_shortcut (m_remove_all_breakpoints_action, sc_edit_debug_remove_breakpoints); + settings.set_shortcut (m_toggle_breakpoint_action, sc_edit_debug_toggle_breakpoint); + settings.set_shortcut (m_next_breakpoint_action, sc_edit_debug_next_breakpoint); + settings.set_shortcut (m_previous_breakpoint_action, sc_edit_debug_previous_breakpoint); + settings.set_shortcut (m_remove_all_breakpoints_action, sc_edit_debug_remove_breakpoints); // Run menu - scmgr.set_shortcut (m_run_action, sc_edit_run_run_file); - scmgr.set_shortcut (m_run_selection_action, sc_edit_run_run_selection); + settings.set_shortcut (m_run_action, sc_edit_run_run_file); + settings.set_shortcut (m_run_selection_action, sc_edit_run_run_selection); // Help menu - scmgr.set_shortcut (m_context_help_action, sc_edit_help_help_keyword); - scmgr.set_shortcut (m_context_doc_action, sc_edit_help_doc_keyword); + settings.set_shortcut (m_context_help_action, sc_edit_help_help_keyword); + settings.set_shortcut (m_context_doc_action, sc_edit_help_doc_keyword); // Tab navigation without menu entries - scmgr.set_shortcut (m_switch_left_tab_action, sc_edit_tabs_switch_left_tab); - scmgr.set_shortcut (m_switch_right_tab_action, sc_edit_tabs_switch_right_tab); - scmgr.set_shortcut (m_move_tab_left_action, sc_edit_tabs_move_tab_left); - scmgr.set_shortcut (m_move_tab_right_action, sc_edit_tabs_move_tab_right); - + settings.set_shortcut (m_switch_left_tab_action, sc_edit_tabs_switch_left_tab); + settings.set_shortcut (m_switch_right_tab_action, sc_edit_tabs_switch_right_tab); + settings.set_shortcut (m_move_tab_left_action, sc_edit_tabs_move_tab_left); + settings.set_shortcut (m_move_tab_right_action, sc_edit_tabs_move_tab_right); } // This slot is a reimplementation of the virtual slot in octave_dock_widget. @@ -1496,9 +1497,8 @@ if (m_closed && visible) { m_closed = false; - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - restore_session (settings); + + restore_session (); } empty_script (false, visible); @@ -1525,28 +1525,28 @@ emit fetab_set_directory (m_ced); // for save dialog } -void file_editor::copyClipboard (void) +void file_editor::copyClipboard () { if (editor_tab_has_focus ()) emit fetab_scintilla_command (m_tab_widget->currentWidget (), QsciScintillaBase::SCI_COPY); } -void file_editor::pasteClipboard (void) +void file_editor::pasteClipboard () { if (editor_tab_has_focus ()) emit fetab_scintilla_command (m_tab_widget->currentWidget (), QsciScintillaBase::SCI_PASTE); } -void file_editor::selectAll (void) +void file_editor::selectAll () { if (editor_tab_has_focus ()) emit fetab_scintilla_command (m_tab_widget->currentWidget (), QsciScintillaBase::SCI_SELECTALL); } -void file_editor::do_undo (void) +void file_editor::do_undo () { if (editor_tab_has_focus ()) emit fetab_scintilla_command (m_tab_widget->currentWidget (), @@ -1562,10 +1562,9 @@ const QString& cond, int index, const QString& bookmarks) { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - - if (settings->value (global_use_custom_editor).toBool ()) + gui_settings settings; + + if (settings.bool_value (global_use_custom_editor)) { // Custom editor if (debug_pointer || breakpoint_marker) @@ -1575,8 +1574,7 @@ return; // Custom editor called } - bool show_dbg_file - = settings->value (ed_show_dbg_file).toBool (); + bool show_dbg_file = settings.bool_value (ed_show_dbg_file); if (openFileName.isEmpty ()) { @@ -1693,7 +1691,7 @@ bool create_file = true; QMessageBox *msgBox; - if (! settings->value (ed_create_new_file).toBool ()) + if (! settings.bool_value (ed_create_new_file)) { msgBox = new QMessageBox (QMessageBox::Question, tr ("Octave Editor"), @@ -1865,9 +1863,9 @@ // handler for the close event void file_editor::closeEvent (QCloseEvent *e) { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - if (settings->value (ed_hiding_closes_files).toBool ()) + gui_settings settings; + + if (settings.bool_value (ed_hiding_closes_files)) { if (check_closing ()) { @@ -1906,7 +1904,7 @@ } } -bool file_editor::is_editor_console_tabbed (void) +bool file_editor::is_editor_console_tabbed () { // FIXME: is there a way to do this job that doesn't require casting // the parent to a main_window object? @@ -1929,7 +1927,7 @@ return false; } -void file_editor::construct (void) +void file_editor::construct () { QWidget *editor_widget = new QWidget (this); @@ -1947,13 +1945,12 @@ m_tab_widget = new file_editor_tab_widget (editor_widget, this); - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - // the mru-list and an empty array of actions - gui_settings *settings = rmgr.get_settings (); - m_mru_files = settings->value (ed_mru_file_list).toStringList (); - m_mru_files_encodings = settings->value (ed_mru_file_encodings) - .toStringList (); + + gui_settings settings; + + m_mru_files = settings.string_list_value (ed_mru_file_list); + m_mru_files_encodings = settings.string_list_value (ed_mru_file_encodings); if (m_mru_files_encodings.count () != m_mru_files.count ()) { @@ -1991,33 +1988,33 @@ m_fileMenu->addSeparator (); m_save_action - = add_action (m_fileMenu, rmgr.icon ("document-save"), + = add_action (m_fileMenu, settings.icon ("document-save"), tr ("&Save File"), SLOT (request_save_file (bool))); m_save_as_action - = add_action (m_fileMenu, rmgr.icon ("document-save-as"), + = add_action (m_fileMenu, settings.icon ("document-save-as"), tr ("Save File &As..."), SLOT (request_save_file_as (bool))); m_fileMenu->addSeparator (); m_close_action - = add_action (m_fileMenu, rmgr.icon ("window-close", false), + = add_action (m_fileMenu, settings.icon ("window-close", false), tr ("&Close"), SLOT (request_close_file (bool))); m_close_all_action - = add_action (m_fileMenu, rmgr.icon ("window-close", false), + = add_action (m_fileMenu, settings.icon ("window-close", false), tr ("Close All"), SLOT (request_close_all_files (bool))); m_close_others_action - = add_action (m_fileMenu, rmgr.icon ("window-close", false), + = add_action (m_fileMenu, settings.icon ("window-close", false), tr ("Close Other Files"), SLOT (request_close_other_files (bool))); m_fileMenu->addSeparator (); m_print_action - = add_action (m_fileMenu, rmgr.icon ("document-print"), + = add_action (m_fileMenu, settings.icon ("document-print"), tr ("Print..."), SLOT (request_print_file (bool))); // edit menu (undo, copy, paste and select all later via main window) @@ -2025,19 +2022,19 @@ m_edit_menu = add_menu (m_menu_bar, tr ("&Edit")); m_redo_action - = add_action (m_edit_menu, rmgr.icon ("edit-redo"), + = add_action (m_edit_menu, settings.icon ("edit-redo"), tr ("&Redo"), SLOT (request_redo (bool))); m_redo_action->setEnabled (false); m_edit_menu->addSeparator (); m_cut_action - = add_action (m_edit_menu, rmgr.icon ("edit-cut"), + = add_action (m_edit_menu, settings.icon ("edit-cut"), tr ("Cu&t"), SLOT (request_cut (bool))); m_cut_action->setEnabled (false); m_find_action - = add_action (m_edit_menu, rmgr.icon ("edit-find-replace"), + = add_action (m_edit_menu, settings.icon ("edit-find-replace"), tr ("&Find and Replace..."), SLOT (request_find (bool))); m_find_next_action @@ -2134,7 +2131,7 @@ m_smart_indent_line_or_selection_action = add_action (m_edit_fmt_menu, tr ("Indent Code"), - SLOT (request_smart_indent_line_or_selected_text (void))); + SLOT (request_smart_indent_line_or_selected_text ())); m_edit_fmt_menu->addSeparator (); @@ -2189,12 +2186,12 @@ m_edit_menu->addSeparator (); m_preferences_action - = add_action (m_edit_menu, rmgr.icon ("preferences-system"), + = add_action (m_edit_menu, settings.icon ("preferences-system"), tr ("&Preferences..."), SLOT (request_preferences (bool))); m_styles_preferences_action - = add_action (m_edit_menu, rmgr.icon ("preferences-system"), + = add_action (m_edit_menu, settings.icon ("preferences-system"), tr ("&Styles Preferences..."), SLOT (request_styles_preferences (bool))); @@ -2249,22 +2246,22 @@ view_menu->addSeparator (); m_zoom_in_action - = add_action (view_menu, rmgr.icon ("view-zoom-in"), tr ("Zoom &In"), + = add_action (view_menu, settings.icon ("view-zoom-in"), tr ("Zoom &In"), SLOT (zoom_in (bool))); m_zoom_out_action - = add_action (view_menu, rmgr.icon ("view-zoom-out"), tr ("Zoom &Out"), - SLOT (zoom_out (bool))); + = add_action (view_menu, settings.icon ("view-zoom-out"), + tr ("Zoom &Out"), SLOT (zoom_out (bool))); m_zoom_normal_action - = add_action (view_menu, rmgr.icon ("view-zoom-original"), tr ("&Normal Size"), - SLOT (zoom_normal (bool))); + = add_action (view_menu, settings.icon ("view-zoom-original"), + tr ("&Normal Size"), SLOT (zoom_normal (bool))); view_menu->addSeparator (); m_sort_tabs_action = add_action (view_menu, tr ("&Sort Tabs Alphabetically"), - SLOT (sort_tabs_alph (void)), + SLOT (sort_tabs_alph ()), m_tab_widget->get_tab_bar ()); m_menu_bar->addMenu (view_menu); @@ -2274,22 +2271,22 @@ m_debug_menu = add_menu (m_menu_bar, tr ("&Debug")); m_toggle_breakpoint_action - = add_action (m_debug_menu, rmgr.icon ("bp-toggle"), + = add_action (m_debug_menu, settings.icon ("bp-toggle"), tr ("Toggle &Breakpoint"), SLOT (request_toggle_breakpoint (bool))); m_next_breakpoint_action - = add_action (m_debug_menu, rmgr.icon ("bp-next"), + = add_action (m_debug_menu, settings.icon ("bp-next"), tr ("&Next Breakpoint"), SLOT (request_next_breakpoint (bool))); m_previous_breakpoint_action - = add_action (m_debug_menu, rmgr.icon ("bp-prev"), + = add_action (m_debug_menu, settings.icon ("bp-prev"), tr ("Pre&vious Breakpoint"), SLOT (request_previous_breakpoint (bool))); m_remove_all_breakpoints_action - = add_action (m_debug_menu, rmgr.icon ("bp-rm-all"), + = add_action (m_debug_menu, settings.icon ("bp-rm-all"), tr ("&Remove All Breakpoints"), SLOT (request_remove_breakpoint (bool))); @@ -2303,7 +2300,7 @@ m_run_action = add_action (_run_menu, - rmgr.icon ("system-run"), + settings.icon ("system-run"), tr ("Save File and Run / Continue"), SLOT (request_run_file (bool))); @@ -2330,19 +2327,19 @@ // tab navigation (no menu, only actions; slots in tab_bar) m_switch_left_tab_action - = add_action (nullptr, "", SLOT (switch_left_tab (void)), + = add_action (nullptr, "", SLOT (switch_left_tab ()), m_tab_widget->get_tab_bar ()); m_switch_right_tab_action - = add_action (nullptr, "", SLOT (switch_right_tab (void)), + = add_action (nullptr, "", SLOT (switch_right_tab ()), m_tab_widget->get_tab_bar ()); m_move_tab_left_action - = add_action (nullptr, "", SLOT (move_tab_left (void)), + = add_action (nullptr, "", SLOT (move_tab_left ()), m_tab_widget->get_tab_bar ()); m_move_tab_right_action - = add_action (nullptr, "", SLOT (move_tab_right (void)), + = add_action (nullptr, "", SLOT (move_tab_right ()), m_tab_widget->get_tab_bar ()); // toolbar @@ -2383,7 +2380,7 @@ vbox_layout->addWidget (m_menu_bar); vbox_layout->addWidget (m_tool_bar); vbox_layout->addWidget (m_tab_widget); - vbox_layout->setMargin (0); + vbox_layout->setContentsMargins (0, 0, 0, 0); vbox_layout->setSpacing (0); editor_widget->setLayout (vbox_layout); setWidget (editor_widget); @@ -2420,7 +2417,7 @@ } // Slot when autocompletion list was cancelled -void file_editor::handle_autoc_cancelled (void) +void file_editor::handle_autoc_cancelled () { // List was cancelled but somehow still active and blocking the // edit area from accepting shortcuts. Only after another keypress @@ -2444,7 +2441,7 @@ qsci->undo (); } -file_editor_tab *file_editor::reset_focus (void) +file_editor_tab *file_editor::reset_focus () { // Reset the focus of the tab and the related edit area file_editor_tab *f @@ -2456,9 +2453,12 @@ file_editor_tab * file_editor::make_file_editor_tab (const QString& directory) { - file_editor_tab *f = new file_editor_tab (m_octave_qobj, directory); + file_editor_tab *f = new file_editor_tab (directory); // signals from the qscintilla edit area + connect (f->qsci_edit_area (), &octave_qscintilla::show_symbol_tooltip_signal, + this, &file_editor::show_symbol_tooltip_signal); + connect (f->qsci_edit_area (), &octave_qscintilla::status_update, this, &file_editor::edit_status_update); @@ -2467,10 +2467,10 @@ connect (f->qsci_edit_area (), SIGNAL (SCN_AUTOCCOMPLETED (const char *, int, int, int)), - this, SLOT (reset_focus (void))); - - connect (f->qsci_edit_area (), SIGNAL (SCN_AUTOCCANCELLED (void)), - this, SLOT (handle_autoc_cancelled (void))); + this, SLOT (reset_focus ())); + + connect (f->qsci_edit_area (), SIGNAL (SCN_AUTOCCANCELLED ()), + this, SLOT (handle_autoc_cancelled ())); // signals from the qscintilla edit area connect (this, &file_editor::enter_debug_mode_signal, @@ -2509,7 +2509,7 @@ // Signals from the file_editor or main-win non-trivial operations connect (this, &file_editor::fetab_settings_changed, - f, [=] (const gui_settings *settings) { f->notice_settings (settings); }); + f, [=] () { f->notice_settings (); }); connect (this, &file_editor::fetab_change_request, f, &file_editor_tab::change_editor_state); @@ -2663,7 +2663,7 @@ check_actions (); } -void file_editor::mru_menu_update (void) +void file_editor::mru_menu_update () { int num_files = qMin (m_mru_files.size (), int (MaxMRUFiles)); @@ -2693,22 +2693,23 @@ } // save actual mru-list in settings - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - - settings->setValue (ed_mru_file_list.key, m_mru_files); - settings->setValue (ed_mru_file_encodings.key, m_mru_files_encodings); - settings->sync (); + + gui_settings settings; + + settings.setValue (ed_mru_file_list.settings_key (), m_mru_files); + settings.setValue (ed_mru_file_encodings.settings_key (), m_mru_files_encodings); + + settings.sync (); } bool file_editor::call_custom_editor (const QString& file_name, int line) { // Check if the user wants to use a custom file editor. - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - - if (settings->value (global_use_custom_editor.key, - global_use_custom_editor.def).toBool ()) + + gui_settings settings; + + if (settings.value (global_use_custom_editor.settings_key (), + global_use_custom_editor.def ()).toBool ()) { // use the external editor interface for handling the call emit request_open_file_external (file_name, line); @@ -2725,12 +2726,11 @@ void file_editor::toggle_preference (const gui_pref& preference) { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - - bool old = settings->value (preference).toBool (); - settings->setValue (preference.key, ! old); - notice_settings (settings); + gui_settings settings; + + bool old = settings.bool_value (preference); + settings.setValue (preference.settings_key (), ! old); + notice_settings (); } // Function for closing the files in a removed directory @@ -2802,7 +2802,7 @@ } } -bool file_editor::editor_tab_has_focus (void) +bool file_editor::editor_tab_has_focus () { QWidget *foc_w = focusWidget (); if (foc_w && foc_w->inherits ("octave::octave_qscintilla")) @@ -2827,7 +2827,8 @@ // // is false - if (same_file (std_file, tab_file.toStdString ()) || file == tab_file) + if (sys::same_file (std_file, tab_file.toStdString ()) + || file == tab_file) return fe_tab; } diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/m-editor/file-editor.h --- a/libgui/src/m-editor/file-editor.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/m-editor/file-editor.h Fri May 12 08:03:14 2023 +0200 @@ -59,11 +59,11 @@ file_editor_tab_widget (QWidget *p, file_editor *fe); - ~file_editor_tab_widget (void) = default; + ~file_editor_tab_widget () = default; - tab_bar * get_tab_bar (void) const; + tab_bar * get_tab_bar () const; - std::list tab_list (void) const; + std::list tab_list () const; }; // the class for the file editor @@ -96,39 +96,39 @@ QString new_file_name; }; - file_editor (QWidget *p, base_qobject& oct_qobj); + file_editor (QWidget *p); - ~file_editor (void) = default; + ~file_editor () = default; - QMenu * get_mru_menu (void) { return m_mru_file_menu; } + QMenu * get_mru_menu () { return m_mru_file_menu; } - QMenu * debug_menu (void) { return m_debug_menu; } + QMenu * debug_menu () { return m_debug_menu; } - QToolBar * toolbar (void) { return m_tool_bar; } + QToolBar * toolbar () { return m_tool_bar; } - QMenuBar * menubar (void) { return m_menu_bar; } + QMenuBar * menubar () { return m_menu_bar; } void insert_global_actions (QList); enum shared_actions_idx - { - NEW_SCRIPT_ACTION = 0, - NEW_FUNCTION_ACTION, - OPEN_ACTION, - FIND_FILES_ACTION, - UNDO_ACTION, - COPY_ACTION, - PASTE_ACTION, - SELECTALL_ACTION - }; + { + NEW_SCRIPT_ACTION = 0, + NEW_FUNCTION_ACTION, + OPEN_ACTION, + FIND_FILES_ACTION, + UNDO_ACTION, + COPY_ACTION, + PASTE_ACTION, + SELECTALL_ACTION + }; - void check_actions (void); + void check_actions (); void empty_script (bool startup, bool visible); - void restore_session (gui_settings *settings); + void restore_session (); signals: - void fetab_settings_changed (const gui_settings *settings); + void fetab_settings_changed (); void fetab_change_request (const QWidget *ID); // Save is a ping-pong type of communication void fetab_save_file (const QWidget *ID, const QString& fileName, @@ -171,38 +171,40 @@ void fetab_zoom_normal (const QWidget *ID); void fetab_set_directory (const QString& dir); - void fetab_recover_from_exit (void); + void fetab_recover_from_exit (); void edit_area_changed (octave_qscintilla *edit_area); void request_settings_dialog (const QString&); void request_open_file_external (const QString& file_name, int line); - void file_loaded_signal (void); + void file_loaded_signal (); void editor_tabs_changed_signal (bool, bool); - void request_dbcont_signal (void); + void request_dbcont_signal (); - void enter_debug_mode_signal (void); - void exit_debug_mode_signal (void); + void enter_debug_mode_signal (); + void exit_debug_mode_signal (); void update_gui_lexer_signal (bool); void execute_command_in_terminal_signal (const QString&); - void focus_console_after_command_signal (void); + void focus_console_after_command_signal (); void run_file_signal (const QFileInfo&); void edit_mfile_request (const QString&, const QString&, const QString&, int); - void debug_quit_signal (void); + void debug_quit_signal (); + + void show_symbol_tooltip_signal (const QPoint&, const QString&); public slots: - void activate (void); + void activate (); void set_focus (QWidget *fet); void enable_menu_shortcuts (bool); - void save_session (void); - bool check_closing (void); - void handle_tab_ready_to_close (void); + void save_session (); + bool check_closing (); + void handle_tab_ready_to_close (); - void handle_enter_debug_mode (void); - void handle_exit_debug_mode (void); + void handle_enter_debug_mode (); + void handle_exit_debug_mode (); void request_new_file (const QString& commands); void request_close_file (bool); @@ -252,7 +254,7 @@ void request_lower_case (bool); void request_indent_selected_text (bool); void request_unindent_selected_text (bool); - void request_smart_indent_line_or_selected_text (void); + void request_smart_indent_line_or_selected_text (); void request_conv_eol_windows (bool); void request_conv_eol_unix (bool); void request_conv_eol_mac (bool); @@ -268,7 +270,7 @@ const QString& toolTip, bool modified); void handle_tab_close_request (int index); - void handle_tab_remove_request (void); + void handle_tab_remove_request (); void active_tab_changed (int index); void handle_editor_state_changed (bool enableCopy, bool is_octave_file, bool is_modified); @@ -287,9 +289,9 @@ void handle_file_renamed (bool load_new = true); // Tells the editor to react on changed settings. - void notice_settings (const gui_settings *settings); + void notice_settings (); - void set_shortcuts (void); + void set_shortcuts (); void handle_visibility (bool visible); @@ -297,16 +299,16 @@ void toplevel_change (bool toplevel); - void handle_autoc_cancelled (void); + void handle_autoc_cancelled (); - file_editor_tab * reset_focus (void); + file_editor_tab * reset_focus (); protected slots: - void copyClipboard (void); - void pasteClipboard (void); - void selectAll (void); - void do_undo (void); + void copyClipboard (); + void pasteClipboard (); + void selectAll (); + void do_undo (); private slots: @@ -345,20 +347,20 @@ file_editor_tab * make_file_editor_tab (const QString& directory = ""); - bool is_editor_console_tabbed (void); - void construct (void); + bool is_editor_console_tabbed (); + void construct (); void add_file_editor_tab (file_editor_tab *f, const QString& fn, int index = -1); - void mru_menu_update (void); + void mru_menu_update (); bool call_custom_editor (const QString& file_name = QString (), int line = -1); void toggle_preference (const gui_pref& preference); void handle_dir_remove (const QString& old_name, const QString& new_name); - bool editor_tab_has_focus (void); + bool editor_tab_has_focus (); - void find_create (void); + void find_create (); file_editor_tab * find_tab_widget (const QString& openFileName); QAction * add_action (QMenu *menu, const QString& text, diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/m-editor/find-dialog.cc --- a/libgui/src/m-editor/find-dialog.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/m-editor/find-dialog.cc Fri May 12 08:03:14 2023 +0200 @@ -83,15 +83,12 @@ #include "find-dialog.h" #include "gui-preferences-ed.h" #include "gui-utils.h" -#include "resource-manager.h" -#include "octave-qobject.h" OCTAVE_BEGIN_NAMESPACE(octave) -find_dialog::find_dialog (base_qobject& oct_qobj, - octave_dock_widget *ed, QWidget *p) -: QDialog (p), m_octave_qobj (oct_qobj), m_editor (ed), - m_in_sel (false), m_sel_beg (-1), m_sel_end (-1) +find_dialog::find_dialog (octave_dock_widget *ed, QWidget *p) + : QDialog (p), m_editor (ed), m_in_sel (false), + m_sel_beg (-1), m_sel_end (-1) { setWindowTitle (tr ("Editor: Find and Replace")); @@ -111,9 +108,9 @@ m_replace_line_edit->completer ()->setCaseSensitivity (Qt::CaseSensitive); m_replace_label->setBuddy (m_replace_line_edit); - int width = QFontMetrics (m_search_line_edit->font ()).averageCharWidth(); - m_search_line_edit->setFixedWidth (20*width); - m_replace_line_edit->setFixedWidth (20*width); + int width = QFontMetrics (m_search_line_edit->font ()).averageCharWidth(); + m_search_line_edit->setFixedWidth (20*width); + m_replace_line_edit->setFixedWidth (20*width); m_case_check_box = new QCheckBox (tr ("Match &case")); m_from_start_check_box = new QCheckBox (tr ("Search from &start")); @@ -162,7 +159,7 @@ this, &find_dialog::handle_sel_search_changed); QVBoxLayout *extension_layout = new QVBoxLayout (); - extension_layout->setMargin (0); + extension_layout->setContentsMargins (0, 0, 0, 0); extension_layout->addWidget (m_whole_words_check_box); extension_layout->addWidget (m_backward_check_box); extension_layout->addWidget (m_search_selection_check_box); @@ -218,8 +215,7 @@ void find_dialog::save_settings () { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *s = rmgr.get_settings (); + gui_settings settings; // Save position QPoint dlg_pos = pos (); @@ -232,7 +228,7 @@ m_last_position = QPoint (dlg_pos.x (), y); - s->setValue (ed_fdlg_pos.key, m_last_position); + settings.setValue (ed_fdlg_pos.settings_key (), m_last_position); // Is current search/replace text in the mru list? mru_update (m_search_line_edit); @@ -242,46 +238,45 @@ QStringList mru; for (int i = 0; i < m_search_line_edit->count (); i++) mru.append (m_search_line_edit->itemText (i)); - s->setValue (ed_fdlg_search.key, mru); + settings.setValue (ed_fdlg_search.settings_key (), mru); mru.clear (); for (int i = 0; i < m_replace_line_edit->count (); i++) mru.append (m_replace_line_edit->itemText (i)); - s->setValue (ed_fdlg_replace.key, mru); + settings.setValue (ed_fdlg_replace.settings_key (), mru); // Store dialog's options int opts = 0 - + m_extension->isVisible () * FIND_DLG_MORE - + m_case_check_box->isChecked () * FIND_DLG_CASE - + m_from_start_check_box->isChecked () * FIND_DLG_START - + m_wrap_check_box->isChecked () * FIND_DLG_WRAP - + m_regex_check_box->isChecked () * FIND_DLG_REGX - + m_whole_words_check_box->isChecked () * FIND_DLG_WORDS - + m_backward_check_box->isChecked () * FIND_DLG_BACK - + m_search_selection_check_box->isChecked () * FIND_DLG_SEL; - s->setValue (ed_fdlg_opts.key, opts); + + m_extension->isVisible () * FIND_DLG_MORE + + m_case_check_box->isChecked () * FIND_DLG_CASE + + m_from_start_check_box->isChecked () * FIND_DLG_START + + m_wrap_check_box->isChecked () * FIND_DLG_WRAP + + m_regex_check_box->isChecked () * FIND_DLG_REGX + + m_whole_words_check_box->isChecked () * FIND_DLG_WORDS + + m_backward_check_box->isChecked () * FIND_DLG_BACK + + m_search_selection_check_box->isChecked () * FIND_DLG_SEL; + settings.setValue (ed_fdlg_opts.settings_key (), opts); - s->sync (); + settings.sync (); } void find_dialog::restore_settings (QPoint ed_bottom_right) { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *s = rmgr.get_settings (); + gui_settings settings; // Get mru lists for search and replace text - QStringList mru = s->value (ed_fdlg_search.key).toStringList (); + QStringList mru = settings.value (ed_fdlg_search.settings_key ()).toStringList (); while (mru.length () > m_mru_length) mru.removeLast (); m_search_line_edit->addItems (mru); - mru = s->value (ed_fdlg_replace.key).toStringList (); + mru = settings.value (ed_fdlg_replace.settings_key ()).toStringList (); while (mru.length () > m_mru_length) mru.removeLast (); m_replace_line_edit->addItems (mru); // Get the dialog's options - int opts = s->value (ed_fdlg_opts.key, ed_fdlg_opts.def).toInt (); + int opts = settings.int_value (ed_fdlg_opts); m_extension->setVisible (FIND_DLG_MORE & opts); m_case_check_box->setChecked (FIND_DLG_CASE & opts); @@ -298,7 +293,7 @@ QRect default_geometry (xp, yp, sizeHint ().width (), sizeHint ().height ()); // Last position from settings - m_last_position = s->value (ed_fdlg_pos.key, QPoint (xp, yp)).toPoint (); + m_last_position = settings.value (ed_fdlg_pos.settings_key (), QPoint (xp, yp)).toPoint (); QRect last_geometry (m_last_position, QSize (sizeHint ().width (), sizeHint ().height ())); @@ -319,7 +314,7 @@ } // search text has changed: reset the search -void find_dialog::handle_search_text_changed (void) +void find_dialog::handle_search_text_changed () { // Return if nothing has changed if (m_search_line_edit->currentText () == m_search_line_edit->itemText (0)) @@ -332,7 +327,7 @@ } // replaced text has changed: reset the search -void find_dialog::handle_replace_text_changed (void) +void find_dialog::handle_replace_text_changed () { // Return if nothing has changed if (m_replace_line_edit->currentText () == m_replace_line_edit->itemText (0)) @@ -384,7 +379,7 @@ } // initialize search text with selected text if this is in one single line -void find_dialog::init_search_text (void) +void find_dialog::init_search_text () { if (m_edit_area && m_edit_area->hasSelectedText ()) { @@ -403,12 +398,12 @@ m_find_next_button->setDefault (true); } -void find_dialog::find_next (void) +void find_dialog::find_next () { find (! m_backward_check_box->isChecked ()); } -void find_dialog::find_prev (void) +void find_dialog::find_prev () { find (m_backward_check_box->isChecked ()); } @@ -523,7 +518,7 @@ #if defined (HAVE_QSCI_VERSION_2_6_0) , true #endif - ); + ); if (m_find_result_available) { @@ -566,7 +561,7 @@ } -void find_dialog::do_replace (void) +void find_dialog::do_replace () { if (m_edit_area) { @@ -577,15 +572,15 @@ { // Update the length of the selection m_sel_end = m_sel_end - - m_search_line_edit->currentText ().toUtf8 ().size () - + m_replace_line_edit->currentText ().toUtf8 ().size (); + - m_search_line_edit->currentText ().toUtf8 ().size () + + m_replace_line_edit->currentText ().toUtf8 ().size (); } m_rep_active = false; } } -void find_dialog::replace (void) +void find_dialog::replace () { if (m_edit_area) { @@ -599,7 +594,7 @@ } } -void find_dialog::replace_all (void) +void find_dialog::replace_all () { int line, col; @@ -634,7 +629,7 @@ } } -void find_dialog::no_matches_message (void) +void find_dialog::no_matches_message () { QMessageBox msg_box (QMessageBox::Information, tr ("Find Result"), tr ("No more matches found"), QMessageBox::Ok, this); diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/m-editor/find-dialog.h --- a/libgui/src/m-editor/find-dialog.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/m-editor/find-dialog.h Fri May 12 08:03:14 2023 +0200 @@ -79,7 +79,6 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; class file_editor; class find_dialog : public QDialog @@ -88,13 +87,13 @@ public: - find_dialog (base_qobject& oct_qobj, octave_dock_widget *ed, QWidget *p); + find_dialog (octave_dock_widget *ed, QWidget *p); //! Set dialog visible or not and storing the new visibility state void set_visible (bool visible); //! Init the search text with the selected text in the editor tab - void init_search_text (void); + void init_search_text (); //! Restore position and the search options from the given settings //! where def_pos is the default position suitable for the current @@ -103,8 +102,8 @@ public slots: - void find_next (void); - void find_prev (void); + void find_next (); + void find_prev (); //! Slot for updating the edit area when the active tab has changed void update_edit_area (octave_qscintilla *); @@ -117,13 +116,11 @@ void handle_backward_search_changed (int); void find (bool forward = true); - void replace (void); - void replace_all (void); + void replace (); + void replace_all (); private: - base_qobject& m_octave_qobj; - //! Save position and the search options in the given settings void save_settings (); @@ -136,11 +133,11 @@ //! Update mru lists with new entry void mru_update (QComboBox *mru); - void no_matches_message (void); - void do_replace (void); + void no_matches_message (); + void do_replace (); - void handle_search_text_changed (void); - void handle_replace_text_changed (void); + void handle_search_text_changed (); + void handle_replace_text_changed (); octave_dock_widget *m_editor; diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/m-editor/marker.cc --- a/libgui/src/m-editor/marker.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/m-editor/marker.cc Fri May 12 08:03:14 2023 +0200 @@ -81,7 +81,7 @@ } } -void marker::handle_remove (void) +void marker::handle_remove () { m_edit_area->markerDeleteHandle (m_mhandle); delete this; diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/m-editor/marker.h --- a/libgui/src/m-editor/marker.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/m-editor/marker.h Fri May 12 08:03:14 2023 +0200 @@ -68,9 +68,9 @@ editor_markers marker_type, int editor_linenr, const QString& condition = ""); - ~marker (void) = default; + ~marker () = default; - const QString& get_cond (void) const { return m_condition; } + const QString& get_cond () const { return m_condition; } void set_cond (const QString& cond) { m_condition = cond; } @@ -82,14 +82,14 @@ void handle_remove_via_original_linenr (int original_linenr); void handle_request_remove_via_editor_linenr (int editor_linenr); - void handle_remove (void); + void handle_remove (); void handle_find_translation (int original_linenr, int& editor_linenr, marker*& bp); void handle_find_just_before (int linenr, int& original_linenr, int& editor_linenr); void handle_find_just_after (int linenr, int& original_linenr, int& editor_linenr); - /* void handle_lines_changed (void);*/ + /* void handle_lines_changed ();*/ void handle_marker_line_deleted (int mhandle); void handle_marker_line_undeleted (int mhandle); void handle_report_editor_linenr (QIntList& lines, QStringList& conditions); diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/m-editor/octave-qscintilla.cc --- a/libgui/src/m-editor/octave-qscintilla.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/m-editor/octave-qscintilla.cc Fri May 12 08:03:14 2023 +0200 @@ -35,7 +35,9 @@ #include #include #include -#include +#include +#include +#include #include #include #if defined (HAVE_QSCI_QSCILEXEROCTAVE_H) @@ -54,17 +56,17 @@ #include "file-editor-tab.h" #include "gui-preferences-ed.h" +#include "gui-settings.h" // FIXME: hardwired marker numbers? #include "marker.h" -#include "octave-qobject.h" #include "octave-qscintilla.h" -#include "shortcut-manager.h" #include "workspace-model.h" #include "builtin-defun-decls.h" #include "cmd-edit.h" #include "interpreter-private.h" #include "interpreter.h" +#include "oct-env.h" // Return true if CANDIDATE is a "closing" that matches OPENING, // such as "end" or "endif" for "if", or "catch" for "try". @@ -110,13 +112,13 @@ return retval; } -octave_qscintilla::octave_qscintilla (QWidget *p, base_qobject& oct_qobj) - : QsciScintilla (p), m_octave_qobj (oct_qobj), m_debug_mode (false), - m_word_at_cursor (), m_selection (), m_selection_replacement (), - m_selection_line (-1), m_selection_col (-1), m_indicator_id (1) +octave_qscintilla::octave_qscintilla (QWidget *p) + : QsciScintilla (p), m_debug_mode (false), m_word_at_cursor (), + m_selection (), m_selection_replacement (), m_selection_line (-1), + m_selection_col (-1), m_indicator_id (1) { - connect (this, SIGNAL (textChanged (void)), - this, SLOT (text_changed (void))); + connect (this, SIGNAL (textChanged ()), + this, SLOT (text_changed ())); connect (this, SIGNAL (cursorPositionChanged (int, int)), this, SLOT (cursor_position_changed (int, int))); @@ -334,20 +336,30 @@ void octave_qscintilla::contextmenu_help_doc (bool documentation) { if (documentation) - m_octave_qobj.show_documentation_window (m_word_at_cursor); + { + std::string name = m_word_at_cursor.toStdString (); + + emit interpreter_event + ([=] (interpreter& interp) + { + // INTERPRETER THREAD + + F__event_manager_show_documentation__ (interp, ovl (name)); + }); + } else emit execute_command_in_terminal_signal ("help " + m_word_at_cursor); } // call edit the function related to the current word -void octave_qscintilla::context_edit (void) +void octave_qscintilla::context_edit () { if (get_actual_word ()) contextmenu_edit (true); } // call edit the function related to the current word -void octave_qscintilla::context_run (void) +void octave_qscintilla::context_run () { if (hasSelectedText ()) { @@ -355,7 +367,7 @@ emit interpreter_event ([] (interpreter&) - { command_editor::erase_empty_line (false); }); + { command_editor::erase_empty_line (false); }); } } @@ -370,7 +382,7 @@ } // determine the actual word and whether we are in an octave or matlab script -bool octave_qscintilla::get_actual_word (void) +bool octave_qscintilla::get_actual_word () { QPoint global_pos, local_pos; get_global_textcursor_pos (&global_pos, &local_pos); @@ -381,7 +393,7 @@ } // helper function for clearing all indicators of a specific style -void octave_qscintilla::clear_selection_markers (void) +void octave_qscintilla::clear_selection_markers () { int end_pos = text ().length (); int end_line, end_col; @@ -391,7 +403,7 @@ markerDeleteAll (marker::selection); } -QString octave_qscintilla::eol_string (void) +QString octave_qscintilla::eol_string () { switch (eolMode ()) { @@ -430,20 +442,20 @@ case SCLEX_MATLAB: #endif { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); + gui_settings settings; + int comment_string; if (comment) { // The commenting string is requested - if (settings->contains (ed_comment_str.key)) + if (settings.contains (ed_comment_str.settings_key ())) // new version (radio buttons) - comment_string = settings->value (ed_comment_str).toInt (); + comment_string = settings.int_value (ed_comment_str); else // old version (combo box) - comment_string = settings->value (ed_comment_str_old.key, - ed_comment_str.def).toInt (); + comment_string = settings.value (ed_comment_str_old.settings_key (), + ed_comment_str.def ()).toInt (); return (QStringList (ed_comment_strings.at (comment_string))); } @@ -452,7 +464,7 @@ QStringList c_str; // The possible uncommenting string(s) are requested - comment_string = settings->value (ed_uncomment_str).toInt (); + comment_string = settings.int_value (ed_uncomment_str); for (int i = 0; i < ed_comment_strings_count; i++) { @@ -542,31 +554,32 @@ { QString prevline = text (line); - QRegExp bkey = QRegExp ("^[\t ]*(if|for|while|switch" - "|do|function|properties|events|classdef" - "|unwind_protect|try" - "|parfor|methods)" - "[\r]?[\n\t #%]"); + QRegularExpression bkey {"^[\t ]*(if|for|while|switch" + "|do|function|properties|events|classdef" + "|unwind_protect|try" + "|parfor|methods)" + "[\r]?[\n\t #%]"}; // last word except for comments, assuming no ' or " in comment. // rx_end = QRegExp ("(\\w+)[ \t;\r\n]*([%#][^\"']*)?$"); // last word except for comments, // allowing % and # in single or double quoted strings // FIXME: This will get confused by transpose. - QRegExp ekey = QRegExp ("(?:(?:['\"][^'\"]*['\"])?[^%#]*)*" - "(\\w+)[ \t;\r\n]*(?:[%#].*)?$"); + QRegularExpression ekey {"(?:(?:['\"][^'\"]*['\"])?[^%#]*)*" + "(\\w+)[ \t;\r\n]*(?:[%#].*)?$"}; - int bpos = bkey.indexIn (prevline, 0); - int epos; + QRegularExpressionMatch bmatch = bkey.match (prevline); - if (bpos > -1) + if (bmatch.hasMatch ()) { // Found keyword after that indentation should be added // Check for existing end statement in the same line - epos = ekey.indexIn (prevline, bpos); - QString first_word = bkey.cap(1); - bool inline_end = (epos > -1) && is_end (ekey.cap(1), first_word); + QRegularExpressionMatch ematch = ekey.match (prevline, + bmatch.capturedStart ()); + QString first_word = bmatch.captured (1); + bool inline_end = ematch.hasMatch () + && is_end (ematch.captured (1), first_word); if (do_smart_indent && ! inline_end) { @@ -577,7 +590,9 @@ if (do_auto_close && ! inline_end - && ! first_word.contains (QRegExp ("(?:case|otherwise|unwind_protect_cleanup)"))) + && ! first_word.contains + (QRegularExpression + {"(?:case|otherwise|unwind_protect_cleanup)"})) { // Do auto close auto_close (do_auto_close, line, prevline, first_word); @@ -586,8 +601,8 @@ return; } - QRegExp mkey = QRegExp ("^[\t ]*(?:else|elseif|catch|unwind_protect_cleanup)" - "[\r]?[\t #%\n]"); + QRegularExpression mkey {"^[\t ]*(?:else|elseif|catch|unwind_protect_cleanup)" + "[\r]?[\t #%\n]"}; if (prevline.contains (mkey)) { int prev_ind = indentation (line-1); @@ -603,14 +618,14 @@ return; } - QRegExp case_key = QRegExp ("^[\t ]*(?:case|otherwise)[\r]?[\t #%\n]"); + QRegularExpression case_key {"^[\t ]*(?:case|otherwise)[\r]?[\t #%\n]"}; if (prevline.contains (case_key) && do_smart_indent) { QString last_line = text (line-1); int prev_ind = indentation (line-1); int act_ind = indentation (line); - if (last_line.contains (QRegExp ("^[\t ]*switch"))) + if (last_line.contains (QRegularExpression {"^[\t ]*switch"})) { indent (line+1); act_ind = indentation (line+1); @@ -627,8 +642,9 @@ setCursorPosition (line+1, act_ind); } - ekey = QRegExp ("^[\t ]*(?:end|endif|endfor|endwhile|until|endfunction" - "|endswitch|end_try_catch|end_unwind_protect)[\r]?[\t #%\n(;]"); + ekey = QRegularExpression + {"^[\t ]*(?:end|endif|endfor|endwhile|until|endfunction" + "|endswitch|end_try_catch|end_unwind_protect)[\r]?[\t #%\n(;]"}; if (prevline.contains (ekey)) { if (indentation (line-1) <= indentation (line)) @@ -652,38 +668,40 @@ void octave_qscintilla::smart_indent_line_or_selected_text (int lineFrom, int lineTo) { - QRegExp blank_line_regexp = QRegExp ("^[\t ]*$"); + QRegularExpression blank_line_regexp {"^[\t ]*$"}; // end[xxxxx] [# comment] at end of a line - QRegExp end_word_regexp - = QRegExp ("(?:(?:['\"][^'\"]*['\"])?[^%#]*)*" - "(?:end\\w*)[\r\n\t ;]*(?:[%#].*)?$"); + QRegularExpression + end_word_regexp {"(?:(?:['\"][^'\"]*['\"])?[^%#]*)*" + "(?:end\\w*)[\r\n\t ;]*(?:[%#].*)?$"}; - QRegExp begin_block_regexp - = QRegExp ("^[\t ]*(?:if|elseif|else" - "|for|while|do|parfor" - "|switch|case|otherwise" - "|function" - "|classdef|properties|events|enumeration|methods" - "|unwind_protect|unwind_protect_cleanup|try|catch)" - "[\r\n\t #%]"); + QRegularExpression + begin_block_regexp {"^[\t ]*(?:if|elseif|else" + "|for|while|do|parfor" + "|switch|case|otherwise" + "|function" + "|classdef|properties|events|enumeration|methods" + "|unwind_protect|unwind_protect_cleanup|try|catch)" + "[\r\n\t #%]"}; - QRegExp mid_block_regexp - = QRegExp ("^[\t ]*(?:elseif|else" - "|unwind_protect_cleanup|catch)" - "[\r\n\t #%]"); + QRegularExpression + mid_block_regexp {"^[\t ]*(?:elseif|else" + "|unwind_protect_cleanup|catch)" + "[\r\n\t #%]"}; - QRegExp end_block_regexp - = QRegExp ("^[\t ]*(?:end" - "|end(for|function|if|parfor|switch|while" - "|classdef|enumeration|events|methods|properties)" - "|end_(try_catch|unwind_protect)" - "|until)" - "[\r\n\t #%]"); + QRegularExpression + end_block_regexp {"^[\t ]*(?:end" + "|end(for|function|if|parfor|switch|while" + "|classdef|enumeration|events|methods|properties)" + "|end_(try_catch|unwind_protect)" + "|until)" + "[\r\n\t #%]"}; - QRegExp case_block_regexp - = QRegExp ("^[\t ]*(?:case|otherwise)" - "[\r\n\t #%]"); + QRegularExpression + case_block_regexp {"^[\t ]*(?:case|otherwise)" + "[\r\n\t #%]"}; + + QRegularExpressionMatch match; int indent_column = -1; int indent_increment = indentationWidth (); @@ -693,7 +711,8 @@ { QString line_text = text (line); - if (blank_line_regexp.indexIn (line_text) < 0) + match = blank_line_regexp.match (line_text); + if (! match.hasMatch ()) { // Found first non-blank line above beginning of region or // current line. Base indentation from this line, increasing @@ -702,7 +721,8 @@ indent_column = indentation (line); - if (begin_block_regexp.indexIn (line_text) > -1) + match = begin_block_regexp.match (line_text); + if (match.hasMatch ()) { indent_column += indent_increment; if (line_text.contains ("switch")) @@ -721,7 +741,8 @@ { QString line_text = text (line); - if (end_block_regexp.indexIn (line_text) > -1) + match = end_block_regexp.match (line_text); + if (match.hasMatch ()) { indent_column -= indent_increment; if (line_text.contains ("endswitch")) @@ -733,31 +754,35 @@ } } - if (mid_block_regexp.indexIn (line_text) > -1) + match = mid_block_regexp.match (line_text); + if (match.hasMatch ()) indent_column -= indent_increment; - if (case_block_regexp.indexIn (line_text) > -1) + match = case_block_regexp.match (line_text); + if (match.hasMatch ()) { - if (case_block_regexp.indexIn (prev_line) < 0 - && !prev_line.contains("switch")) + match = case_block_regexp.match (prev_line); + if (! match.hasMatch () + && ! prev_line.contains ("switch")) indent_column -= indent_increment; in_switch = true; } setIndentation (line, indent_column); - int bpos = begin_block_regexp.indexIn (line_text); - if (bpos > -1) + match = begin_block_regexp.match (line_text); + if (match.hasMatch ()) { // Check for existing end statement in the same line - int epos = end_word_regexp.indexIn (line_text, bpos); - if (epos == -1) + match = end_word_regexp.match (line_text, match.capturedStart ()); + if (! match.hasMatch ()) indent_column += indent_increment; if (line_text.contains ("switch")) in_switch = true; } - if (blank_line_regexp.indexIn (line_text) < 0) + match = blank_line_regexp.match (line_text); + if (! match.hasMatch ()) prev_line = line_text; } } @@ -813,7 +838,7 @@ emit context_menu_edit_signal (m_word_at_cursor); } -void octave_qscintilla::contextmenu_run_temp_error (void) +void octave_qscintilla::contextmenu_run_temp_error () { QMessageBox::critical (this, tr ("Octave Editor"), tr ("Creating temporary files failed.\n" @@ -824,222 +849,217 @@ void octave_qscintilla::contextmenu_run (bool) { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - // Take selected code and extend it by commands for echoing each // evaluated line and for adding the line to the history (use script) QString code = QString (); QString hist = QString (); // Split contents into single lines and complete commands - QStringList lines = selectedText ().split (QRegExp ("[\r\n]"), + QStringList lines = selectedText ().split (QRegularExpression {"[\r\n]"}, #if defined (HAVE_QT_SPLITBEHAVIOR_ENUM) Qt::SkipEmptyParts); #else - QString::SkipEmptyParts); + QString::SkipEmptyParts); #endif -for (int i = 0; i < lines.count (); i++) - { - QString line = lines.at (i); - if (line.trimmed ().isEmpty ()) - continue; - QString line_escaped = line; - line_escaped.replace (QString ("'"), QString ("''")); - QString line_history = line; + for (int i = 0; i < lines.count (); i++) + { + QString line = lines.at (i); + if (line.trimmed ().isEmpty ()) + continue; + QString line_escaped = line; + line_escaped.replace (QString ("'"), QString ("''")); + QString line_history = line; - // Prevent output of breakpoint in temp. file for keyboard - QString next_bp_quiet; - QString next_bp_quiet_reset; - if (line.contains ("keyboard")) - { - // Define commands for not showing bp location and for resetting - // this in case "keyboard" was within a comment - next_bp_quiet = "__db_next_breakpoint_quiet__;\n"; - next_bp_quiet_reset = "\n__db_next_breakpoint_quiet__(false);"; - } + // Prevent output of breakpoint in temp. file for keyboard + QString next_bp_quiet; + QString next_bp_quiet_reset; + if (line.contains ("keyboard")) + { + // Define commands for not showing bp location and for resetting + // this in case "keyboard" was within a comment + next_bp_quiet = "__db_next_breakpoint_quiet__;\n"; + next_bp_quiet_reset = "\n__db_next_breakpoint_quiet__(false);"; + } - // Add codeline - code += next_bp_quiet + line + next_bp_quiet_reset + "\n"; - hist += line_history + "\n"; - } + // Add codeline + code += next_bp_quiet + line + next_bp_quiet_reset + "\n"; + hist += line_history + "\n"; + } -octave_stdout << hist.toStdString (); + octave_stdout << hist.toStdString (); -// Create tmp file with the code to be executed by the interpreter -QPointer tmp_file -= rmgr.create_tmp_file ("m", code); + // Create tmp file with the code to be executed by the interpreter + QPointer tmp_file = create_tmp_file ("m", code); -bool tmp = (tmp_file && tmp_file->open ()); -if (! tmp) - { - // tmp files not working: use old way to run selection - contextmenu_run_temp_error (); - return; - } - -tmp_file->close (); + if (tmp_file && tmp_file->open ()) + tmp_file->close (); + else + { + // tmp files not working: use old way to run selection + contextmenu_run_temp_error (); + return; + } -// Create tmp file required for adding command to history -QPointer tmp_hist -= rmgr.create_tmp_file ("", hist); // empty tmp file for history + // Create tmp file required for adding command to history + QPointer tmp_hist = create_tmp_file ("", hist); -tmp = (tmp_hist && tmp_hist->open ()); -if (! tmp) - { - // tmp files not working: use old way to run selection - contextmenu_run_temp_error (); - return; - } + if (tmp_hist && tmp_hist->open ()) + tmp_hist->close (); + else + { + // tmp files not working: use old way to run selection + contextmenu_run_temp_error (); + return; + } -tmp_hist->close (); + // Add commands to the history + emit interpreter_event + ([=] (interpreter& interp) + { + // INTERPRETER THREAD -// Add commands to the history -emit interpreter_event -([=] (interpreter& interp) - { - // INTERPRETER THREAD + if (tmp_hist.isNull ()) + return; - if (tmp_hist.isNull ()) - return; + std::string opt = "-r"; + std::string path = tmp_hist->fileName ().toStdString (); - std::string opt = "-r"; - std::string path = tmp_hist->fileName ().toStdString (); + Fhistory (interp, ovl (opt, path)); + }); + + // Disable opening a file at a breakpoint in case keyboard () is used + gui_settings settings; - Fhistory (interp, ovl (opt, path)); - }); + bool show_dbg_file = settings.bool_value (ed_show_dbg_file); + settings.setValue (ed_show_dbg_file.settings_key (), false); -// Disable opening a file at a breakpoint in case keyboard () is used -gui_settings *settings = rmgr.get_settings (); -bool show_dbg_file = settings->value (ed_show_dbg_file).toBool (); -settings->setValue (ed_show_dbg_file.key, false); + // The interpreter_event callback function below emits a signal. + // Because we don't control when that happens, use a guarded pointer + // so that the callback can abort if this object is no longer valid. -// The interpreter_event callback function below emits a signal. -// Because we don't control when that happens, use a guarded pointer -// so that the callback can abort if this object is no longer valid. - -QPointer this_oq (this); - -// Let the interpreter execute the tmp file -emit interpreter_event -([=] (interpreter& interp) - { - // INTERPRETER THREAD - - // FIXME: For now, just skip the entire callback if THIS_OQ is no - // longer valid. Maybe there is a better way to do this job? - - if (this_oq.isNull ()) - return; + QPointer this_oq (this); - std::string file = tmp_file->fileName ().toStdString (); - - std::string pending_input = command_editor::get_current_line (); - - int err_line = -1; // For storing the line of a poss. error - - // Get current state of auto command repeat in debug mode - octave_value_list ovl_dbg = Fisdebugmode (interp); - bool dbg = ovl_dbg(0).bool_value (); - octave_value_list ovl_auto_repeat = ovl (true); - if (dbg) - ovl_auto_repeat = Fauto_repeat_debug_command (interp, ovl (false), 1); - bool auto_repeat = ovl_auto_repeat(0).bool_value (); - - try - { - // Do the job - interp.source_file (file); - } - catch (const execution_exception& ee) + // Let the interpreter execute the tmp file + emit interpreter_event + ([=] (interpreter& interp) { - // Catch errors otherwise the rest of the interpreter - // will not be executed (cleaning up). + // INTERPRETER THREAD + + // FIXME: For now, just skip the entire callback if THIS_OQ is + // no longer valid. Maybe there is a better way to do this + // job? - // New error message and error stack - QString new_msg = QString::fromStdString (ee.message ()); - std::list stack = ee.stack_info (); + if (this_oq.isNull ()) + return; + + std::string file = tmp_file->fileName ().toStdString (); + + std::string pending_input = command_editor::get_current_line (); + + int err_line = -1; // For storing the line of a poss. error - // Remove line and column from first line of error message only - // if it is related to the tmp itself, i.e. only if the - // the error stack size is 0, 1, or, if in debug mode, 2 - size_t max_stack_size = 1; + // Get current state of auto command repeat in debug mode + octave_value_list ovl_dbg = Fisdebugmode (interp); + bool dbg = ovl_dbg(0).bool_value (); + octave_value_list ovl_auto_repeat = ovl (true); if (dbg) - max_stack_size = 2; - if (stack.size () <= max_stack_size) + ovl_auto_repeat = Fauto_repeat_debug_command (interp, ovl (false), 1); + bool auto_repeat = ovl_auto_repeat(0).bool_value (); + + try + { + // Do the job + interp.source_file (file); + } + catch (const execution_exception& ee) { - QRegExp rx ("source: error sourcing file [^\n]*$"); - if (new_msg.contains (rx)) + // Catch errors otherwise the rest of the interpreter + // will not be executed (cleaning up). + + // New error message and error stack + QString new_msg = QString::fromStdString (ee.message ()); + std::list stack = ee.stack_info (); + + // Remove line and column from first line of error message only + // if it is related to the tmp itself, i.e. only if the + // the error stack size is 0, 1, or, if in debug mode, 2 + size_t max_stack_size = 1; + if (dbg) + max_stack_size = 2; + if (stack.size () <= max_stack_size) { - // Selected code has syntax errors - new_msg.replace (rx, "error sourcing selected code"); - err_line = 0; // Nothing into history? - } - else - { - // Normal error, detect line and remove file - // name from message - QStringList rx_list; - rx_list << "near line (\\d+),[^\n]*\n"; - rx_list << "near line (\\d+),[^\n]*$"; + QRegularExpression rx {"source: error sourcing file [^\n]*$"}; + if (new_msg.contains (rx)) + { + // Selected code has syntax errors + new_msg.replace (rx, "error sourcing selected code"); + err_line = 0; // Nothing into history? + } + else + { + // Normal error, detect line and remove file + // name from message + QStringList rx_list; + rx_list << "near line (\\d+),[^\n]*\n"; + rx_list << "near line (\\d+),[^\n]*$"; - QStringList replace_list; - replace_list << "\n"; - replace_list << ""; + QStringList replace_list; + replace_list << "\n"; + replace_list << ""; - for (int i = 0; i < rx_list.length (); i++) - { - int pos = 0; - rx = QRegExp (rx_list.at (i)); - pos = rx.indexIn (new_msg, pos); - if (pos != -1) + for (int i = 0; i < rx_list.length (); i++) { - err_line = rx.cap (1).toInt (); - new_msg = new_msg.replace (rx, replace_list.at (i)); + rx = QRegularExpression {rx_list.at (i)}; + QRegularExpressionMatch match = rx.match(new_msg); + if (match.hasMatch ()) + { + err_line = match.captured (1).toInt (); + new_msg = new_msg.replace (rx, replace_list.at (i)); + } } } } + + // Drop first stack level, which is the temporary function file, + // or, if in debug mode, drop first two stack levels + if (stack.size () > 0) + stack.pop_back (); + if (dbg && (stack.size () > 0)) + stack.pop_back (); + + // Clean up before throwing the modified error. + emit ctx_menu_run_finished_signal (show_dbg_file, err_line, + tmp_file, tmp_hist, + dbg, auto_repeat); + + // New exception with updated message and stack + execution_exception nee (ee.err_type (), ee.identifier (), + new_msg.toStdString (), stack); + + // Throw + throw (nee); } - // Drop first stack level, which is the temporary function file, - // or, if in debug mode, drop first two stack levels - if (stack.size () > 0) - stack.pop_back (); - if (dbg && (stack.size () > 0)) - stack.pop_back (); + // Clean up - // Clean up before throwing the modified error. emit ctx_menu_run_finished_signal (show_dbg_file, err_line, tmp_file, tmp_hist, dbg, auto_repeat); - // New exception with updated message and stack - execution_exception nee (ee.err_type (), ee.identifier (), - new_msg.toStdString (), stack); - - // Throw - throw (nee); - } - - // Clean up + command_editor::erase_empty_line (true); + command_editor::replace_line (""); + command_editor::set_initial_input (pending_input); + command_editor::redisplay (); + command_editor::interrupt_event_loop (); + command_editor::accept_line (); + command_editor::erase_empty_line (true); - emit ctx_menu_run_finished_signal (show_dbg_file, err_line, - tmp_file, tmp_hist, - dbg, auto_repeat); - - command_editor::erase_empty_line (true); - command_editor::replace_line (""); - command_editor::set_initial_input (pending_input); - command_editor::redisplay (); - command_editor::interrupt_event_loop (); - command_editor::accept_line (); - command_editor::erase_empty_line (true); - - }); + }); } -void octave_qscintilla::ctx_menu_run_finished (bool show_dbg_file, int, - QTemporaryFile* tmp_file, QTemporaryFile* tmp_hist, - bool dbg, bool auto_repeat) +void octave_qscintilla::ctx_menu_run_finished + (bool show_dbg_file, int, QPointer tmp_file, + QPointer tmp_hist, bool dbg, bool auto_repeat) { emit focus_console_after_command_signal (); @@ -1047,19 +1067,24 @@ // lines from history that were never executed. For this, // possible lines from commands at a debug prompt must be // taken into consideration. - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - settings->setValue (ed_show_dbg_file.key, show_dbg_file); - rmgr.remove_tmp_file (tmp_file); - rmgr.remove_tmp_file (tmp_hist); + + gui_settings settings; + + settings.setValue (ed_show_dbg_file.settings_key (), show_dbg_file); + + if (tmp_file && tmp_file->exists ()) + tmp_file->remove (); + + if (tmp_hist && tmp_hist->exists ()) + tmp_hist->remove (); emit interpreter_event ([=] (interpreter& interp) - { - // INTERPRETER THREAD - if (dbg) - Fauto_repeat_debug_command (interp, ovl (auto_repeat)); - }); + { + // INTERPRETER THREAD + if (dbg) + Fauto_repeat_debug_command (interp, ovl (auto_repeat)); + }); } // wrappers for dbstop related context menu items @@ -1088,7 +1113,7 @@ #endif } -void octave_qscintilla::text_changed (void) +void octave_qscintilla::text_changed () { emit status_update (isUndoAvailable (), isRedoAvailable ()); } @@ -1113,14 +1138,14 @@ QsciScintilla::focusInEvent (focusEvent); } -void octave_qscintilla::show_replace_action_tooltip (void) +void octave_qscintilla::show_replace_action_tooltip () { int pos; get_current_position (&pos, &m_selection_line, &m_selection_col); // Offer to replace other instances. - QKeySequence keyseq = Qt::SHIFT + Qt::Key_Return; + QKeySequence keyseq = Qt::SHIFT | Qt::Key_Return; QString msg = (tr ("Press '%1' to replace all occurrences of '%2' with '%3'.") . arg (keyseq.toString ()) @@ -1187,23 +1212,13 @@ { if (m_debug_mode && e->type() == QEvent::ToolTip) { - QHelpEvent *help_e = static_cast(e); - QString variable = wordAtPoint (help_e->pos()); - QStringList symbol_names - = m_octave_qobj.get_workspace_model ()->get_symbol_names (); - int symbol_idx = symbol_names.indexOf (variable); - if (symbol_idx > -1) - { - QStringList symbol_values - = m_octave_qobj.get_workspace_model ()->get_symbol_values (); - QToolTip::showText (help_e->globalPos(), variable - + " = " + symbol_values.at (symbol_idx)); - } - else - { - QToolTip::hideText(); - e->ignore(); - } + // FIXME: can we handle display of a tooltip using an + // interpreter event or a custom signal/slot connection? + + QHelpEvent *help_e = static_cast (e); + QString symbol = wordAtPoint (help_e->pos()); + + emit show_symbol_tooltip_signal (help_e->globalPos (), symbol); return true; } @@ -1286,7 +1301,7 @@ if (linenr < lines () - 1) { int offset = 2; // linenr is the old line, thus, linnr+1 is the - // new one and can not be taken into account + // new one and can not be taken into account std::size_t next_start; QString next_line; @@ -1306,9 +1321,9 @@ return; if (next_start == start) // same => check if already is "end" { - QRegExp rx_start = QRegExp (R"((\w+))"); - int tmp = rx_start.indexIn (next_line, start); - if (tmp != -1 && is_end (rx_start.cap(1), first_word)) + QRegularExpression rx_start {R"((\w+))"}; + QRegularExpressionMatch match = rx_start.match (next_line, start); + if (match.hasMatch () && is_end (match.captured (1), first_word)) return; } } @@ -1367,16 +1382,40 @@ } } -void octave_qscintilla::handle_enter_debug_mode (void) +void octave_qscintilla::handle_enter_debug_mode () { m_debug_mode = true; } -void octave_qscintilla::handle_exit_debug_mode (void) +void octave_qscintilla::handle_exit_debug_mode () { m_debug_mode = false; } +QPointer +octave_qscintilla::create_tmp_file (const QString& extension, + const QString& contents) +{ + QString ext = extension; + if ((! ext.isEmpty ()) && (! ext.startsWith ('.'))) + ext = QString (".") + ext; + + // Create octave dir within temp. dir + QString tmp_dir = QString::fromStdString (sys::env::get_temp_directory ()); + + QString tmp_name = tmp_dir + QDir::separator() + "octave_XXXXXX" + ext; + + QPointer tmp_file (new QTemporaryFile (tmp_name, this)); + + if (! contents.isEmpty () && tmp_file && tmp_file->open ()) + { + tmp_file->write (contents.toUtf8 ()); + tmp_file->close (); + } + + return tmp_file; +} + OCTAVE_END_NAMESPACE(octave) #endif diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/m-editor/octave-qscintilla.h --- a/libgui/src/m-editor/octave-qscintilla.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/m-editor/octave-qscintilla.h Fri May 12 08:03:14 2023 +0200 @@ -30,25 +30,24 @@ #include #include #include +#include +#include #include -#include #include "gui-settings.h" #include "qt-interpreter-events.h" OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; - class octave_qscintilla : public QsciScintilla { Q_OBJECT public: - octave_qscintilla (QWidget *p, base_qobject& oct_qobj); + octave_qscintilla (QWidget *p); - ~octave_qscintilla (void) = default; + ~octave_qscintilla () = default; enum { @@ -61,12 +60,12 @@ virtual void setCursorPosition (int line, int col); void context_help_doc (bool); - void context_edit (void); - void context_run (void); + void context_edit (); + void context_run (); void get_global_textcursor_pos (QPoint *global_pos, QPoint *local_pos); - bool get_actual_word (void); - void clear_selection_markers (void); - QString eol_string (void); + bool get_actual_word (); + void clear_selection_markers (); + QString eol_string (); void get_current_position (int *pos, int *line, int *col); QStringList comment_string (bool comment = true); int get_style (int pos = -1); @@ -94,43 +93,44 @@ void qsci_has_focus_signal (bool); void status_update (bool, bool); void show_doc_signal (const QString&); + void show_symbol_tooltip_signal (const QPoint&, const QString&); void context_menu_break_condition_signal (int); void context_menu_break_once (int); - void ctx_menu_run_finished_signal (bool, int, QTemporaryFile *, - QTemporaryFile *, bool, bool); - void focus_console_after_command_signal (void); + void ctx_menu_run_finished_signal (bool, int, QPointer, + QPointer, bool, bool); + void focus_console_after_command_signal (); void interpreter_event (const fcn_callback& fcn); void interpreter_event (const meth_callback& meth); public slots: - void handle_enter_debug_mode (void); - void handle_exit_debug_mode (void); + void handle_enter_debug_mode (); + void handle_exit_debug_mode (); private slots: - void ctx_menu_run_finished (bool, int, QTemporaryFile *, QTemporaryFile *, - bool, bool); + void ctx_menu_run_finished (bool, int, QPointer, + QPointer, bool, bool); void contextmenu_help (bool); void contextmenu_doc (bool); void contextmenu_help_doc (bool); void contextmenu_edit (bool); void contextmenu_run (bool); - void contextmenu_run_temp_error (void); + void contextmenu_run_temp_error (); void contextmenu_break_condition (bool); void contextmenu_break_once (const QPoint&); - void text_changed (void); + void text_changed (); void cursor_position_changed (int, int); protected: void focusInEvent (QFocusEvent *focusEvent); - void show_replace_action_tooltip (void); + void show_replace_action_tooltip (); bool event (QEvent *e); @@ -143,7 +143,8 @@ void auto_close (int auto_endif, int l, const QString& line, QString& first_word); - base_qobject& m_octave_qobj; + QPointer create_tmp_file (const QString& extension, + const QString& contents); bool m_debug_mode; diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/m-editor/octave-txt-lexer.cc --- a/libgui/src/m-editor/octave-txt-lexer.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/m-editor/octave-txt-lexer.cc Fri May 12 08:03:14 2023 +0200 @@ -43,12 +43,12 @@ return QString (); }; -const char * octave_txt_lexer::language (void) const +const char * octave_txt_lexer::language () const { return "Text"; } -const char * octave_txt_lexer::lexer (void) const +const char * octave_txt_lexer::lexer () const { return "text"; } diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/m-editor/octave-txt-lexer.h --- a/libgui/src/m-editor/octave-txt-lexer.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/m-editor/octave-txt-lexer.h Fri May 12 08:03:14 2023 +0200 @@ -37,9 +37,9 @@ public: - virtual const char * language (void) const; + virtual const char * language () const; - virtual const char * lexer (void) const; + virtual const char * lexer () const; virtual QString description (int style) const; }; diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/main-window.cc --- a/libgui/src/main-window.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/main-window.cc Fri May 12 08:03:14 2023 +0200 @@ -73,9 +73,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" #include "cmd-edit.h" @@ -93,41 +91,43 @@ OCTAVE_BEGIN_NAMESPACE(octave) main_window::main_window (base_qobject& oct_qobj) -: QMainWindow (), m_octave_qobj (oct_qobj), - m_status_bar (nullptr), - m_command_window (nullptr), - m_history_window (nullptr), - m_file_browser_window (nullptr), - m_editor_window (nullptr), - m_workspace_window (nullptr), - m_external_editor (new external_editor_interface (this, m_octave_qobj)), - m_active_editor (m_external_editor), m_settings_dlg (nullptr), - m_find_files_dlg (nullptr), m_set_path_dlg (nullptr), - m_clipboard (QApplication::clipboard ()), - m_prevent_readline_conflicts (true), - m_prevent_readline_conflicts_menu (false), - m_suppress_dbg_location (true), - m_closing (false), m_file_encoding (QString ()) + : QMainWindow (), m_octave_qobj (oct_qobj), + m_status_bar (nullptr), + m_command_window (nullptr), + m_history_window (nullptr), + m_file_browser_window (nullptr), + m_editor_window (nullptr), + m_workspace_window (nullptr), + m_external_editor (new external_editor_interface (this)), + m_active_editor (m_external_editor), m_settings_dlg (nullptr), + m_find_files_dlg (nullptr), m_set_path_dlg (nullptr), + m_clipboard (QApplication::clipboard ()), + m_prevent_readline_conflicts (true), + m_prevent_readline_conflicts_menu (false), + m_suppress_dbg_location (true), + m_closing (false), m_file_encoding (QString ()) { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - - if (rmgr.is_first_run ()) + gui_settings settings; + + if (! settings.bool_value (global_skip_welcome_wizard)) { // Before wizard. m_octave_qobj.config_translators (); - welcome_wizard welcomeWizard (m_octave_qobj); + welcome_wizard welcomeWizard; if (welcomeWizard.exec () == QDialog::Rejected) exit (1); + settings.setValue (global_skip_welcome_wizard.settings_key (), QVariant (true)); + // Install settings file. - rmgr.reload_settings (); + settings.reload (); } else { // Get settings file. - rmgr.reload_settings (); + settings.reload (); // After settings. m_octave_qobj.config_translators (); @@ -135,9 +135,9 @@ setObjectName (gui_obj_name_main_window); - rmgr.config_icon_theme (); - - rmgr.update_network_settings (); + settings.config_icon_theme (); + + settings.update_network_settings (); // We provide specific terminal capabilities, so ensure that // TERM is always set appropriately. @@ -148,13 +148,6 @@ sys::env::putenv ("TERM", "xterm"); #endif - // FIXME: can we do this job when creating the shortcut manager? - // A quick look shows that it may require some coordination with the - // resource manager. Startup is complicated, but maybe we can make - // it simpler? - shortcut_manager& scmgr = m_octave_qobj.get_shortcut_manager (); - scmgr.init_data (); - construct_central_widget (); m_status_bar = new QStatusBar (this); @@ -165,33 +158,22 @@ adopt_dock_widgets (); -#if defined (HAVE_QGUIAPPLICATION_SETDESKTOPFILENAME) QGuiApplication::setDesktopFileName ("org.octave.Octave.desktop"); -#endif QApplication *qapp = m_octave_qobj.qapplication (); m_default_style = qapp->style ()->objectName (); m_default_palette = qapp->palette (); - gui_settings *settings = rmgr.get_settings (); - bool connect_to_web = true; QDateTime last_checked; int serial = 0; m_active_dock = nullptr; - if (settings) - { - connect_to_web - = settings->value (nr_allow_connection).toBool (); - - last_checked - = settings->value (nr_last_time).toDateTime (); - - serial = settings->value (nr_last_news).toInt (); - m_default_encoding = settings->value (ed_default_enc).toString (); - } + connect_to_web = settings.bool_value (nr_allow_connection); + last_checked = settings.date_time_value (nr_last_time); + serial = settings.int_value (nr_last_news); + m_default_encoding = settings.string_value (ed_default_enc); QDateTime current = QDateTime::currentDateTime (); QDateTime one_day_ago = current.addDays (-1); @@ -216,9 +198,9 @@ focus_command_window (); } -main_window::~main_window (void) { } - -void main_window::adopt_dock_widgets (void) +main_window::~main_window () { } + +void main_window::adopt_dock_widgets () { adopt_terminal_widget (); adopt_documentation_widget (); @@ -231,7 +213,7 @@ m_previous_dock = m_command_window; } -void main_window::adopt_terminal_widget (void) +void main_window::adopt_terminal_widget () { m_command_window = m_octave_qobj.terminal_widget (this); @@ -289,14 +271,14 @@ } } -void main_window::adopt_documentation_widget (void) +void main_window::adopt_documentation_widget () { m_doc_browser_window = m_octave_qobj.documentation_widget (this); make_dock_widget_connections (m_doc_browser_window); } -void main_window::adopt_file_browser_widget (void) +void main_window::adopt_file_browser_widget () { m_file_browser_window = m_octave_qobj.file_browser_widget (this); @@ -324,7 +306,7 @@ this, &main_window::find_files); } -void main_window::adopt_history_widget (void) +void main_window::adopt_history_widget () { m_history_window = m_octave_qobj.history_widget (this); @@ -337,7 +319,7 @@ this, &main_window::execute_command_in_terminal); } -void main_window::adopt_workspace_widget (void) +void main_window::adopt_workspace_widget () { m_workspace_window = m_octave_qobj.workspace_widget (this); @@ -347,14 +329,14 @@ this, &main_window::execute_command_in_terminal); } -void main_window::adopt_editor_widget (void) +void main_window::adopt_editor_widget () { interpreter_qobject *interp_qobj = m_octave_qobj.interpreter_qobj (); qt_interpreter_events *qt_link = interp_qobj->qt_link (); #if defined (HAVE_QSCINTILLA) - file_editor *editor = new file_editor (this, m_octave_qobj); + file_editor *editor = new file_editor (this); make_dock_widget_connections (editor); @@ -363,6 +345,10 @@ // connections here instead of in base_qobject::editor_widget. m_octave_qobj.connect_interpreter_events (editor); + connect (editor, &file_editor::show_symbol_tooltip_signal, + m_octave_qobj.get_workspace_model (), + &workspace_model::show_symbol_tooltip); + connect (editor, &file_editor::request_settings_dialog, this, QOverload::of (&main_window::process_settings_dialog_request)); @@ -451,7 +437,7 @@ m_active_editor, SLOT (handle_edit_file_request (const QString&))); } -void main_window::adopt_variable_editor_widget (void) +void main_window::adopt_variable_editor_widget () { m_variable_editor_window = m_octave_qobj.variable_editor_widget (this); @@ -482,12 +468,12 @@ dw, &octave_dock_widget::save_settings); } -bool main_window::command_window_has_focus (void) const +bool main_window::command_window_has_focus () const { return m_command_window->has_focus (); } -void main_window::focus_command_window (void) +void main_window::focus_command_window () { m_command_window->activate (); } @@ -504,15 +490,14 @@ m_file_browser_window->activate (); } -bool main_window::confirm_shutdown (void) +bool main_window::confirm_shutdown () { bool closenow = true; - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - - if (settings->value (global_prompt_to_exit.key, - global_prompt_to_exit.def).toBool ()) + gui_settings settings; + + if (settings.value (global_prompt_to_exit.settings_key (), + global_prompt_to_exit.def ()).toBool ()) { int ans = QMessageBox::question (this, tr ("Octave"), tr ("Are you sure you want to exit Octave?"), @@ -646,13 +631,9 @@ } } -void main_window::request_reload_settings (void) +void main_window::request_reload_settings () { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - - if (settings) - emit settings_changed (settings); + emit settings_changed (); } void main_window::report_status_message (const QString& statusMessage) @@ -660,13 +641,14 @@ m_status_bar->showMessage (statusMessage, 1000); } -void main_window::handle_save_workspace_request (void) +void main_window::handle_save_workspace_request () { // FIXME: Remove, if for all common KDE versions (bug #54607) is resolved. int opts = 0; // No options by default. - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - if (! settings->value (global_use_native_dialogs).toBool ()) + + gui_settings settings; + + if (! settings.bool_value (global_use_native_dialogs)) opts = QFileDialog::DontUseNativeDialog; QString file @@ -677,11 +659,11 @@ { emit interpreter_event ([=] (interpreter& interp) - { - // INTERPRETER THREAD - - Fsave (interp, ovl (file.toStdString ())); - }); + { + // INTERPRETER THREAD + + Fsave (interp, ovl (file.toStdString ())); + }); } } @@ -689,9 +671,10 @@ { // FIXME: Remove, if for all common KDE versions (bug #54607) is resolved. int opts = 0; // No options by default. - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - if (! settings->value (global_use_native_dialogs).toBool ()) + + gui_settings settings; + + if (! settings.bool_value (global_use_native_dialogs)) opts = QFileDialog::DontUseNativeDialog; QString file = file_arg; @@ -704,17 +687,17 @@ { emit interpreter_event ([=] (interpreter& interp) - { - // INTERPRETER THREAD - - Fload (interp, ovl (file.toStdString ())); - - tree_evaluator& tw = interp.get_evaluator (); - - event_manager& xevmgr = interp.get_event_manager (); - - xevmgr.set_workspace (true, tw.get_symbol_info ()); - }); + { + // INTERPRETER THREAD + + Fload (interp, ovl (file.toStdString ())); + + tree_evaluator& tw = interp.get_evaluator (); + + event_manager& xevmgr = interp.get_event_manager (); + + xevmgr.set_workspace (true, tw.get_symbol_info ()); + }); } } @@ -726,70 +709,70 @@ emit interpreter_event ([=] (interpreter& interp) - { - // INTERPRETER THREAD - - interp.feval ("open", ovl (file)); - - // Update the workspace since open.m may have loaded new - // variables. - tree_evaluator& tw = interp.get_evaluator (); - - event_manager& xevmgr = interp.get_event_manager (); - - xevmgr.set_workspace (true, tw.get_symbol_info ()); - }); + { + // INTERPRETER THREAD + + interp.feval ("open", ovl (file)); + + // Update the workspace since open.m may have loaded new + // variables. + tree_evaluator& tw = interp.get_evaluator (); + + event_manager& xevmgr = interp.get_event_manager (); + + xevmgr.set_workspace (true, tw.get_symbol_info ()); + }); } } -void main_window::handle_clear_workspace_request (void) +void main_window::handle_clear_workspace_request () { emit interpreter_event ([] (interpreter& interp) - { - // INTERPRETER THREAD - - Fclear (interp); - }); + { + // INTERPRETER THREAD + + Fclear (interp); + }); } -void main_window::handle_clear_command_window_request (void) +void main_window::handle_clear_command_window_request () { emit interpreter_event - ([] (void) - { - // INTERPRETER THREAD - - command_editor::kill_full_line (); - command_editor::clear_screen (); - }); + ([] () + { + // INTERPRETER THREAD + + command_editor::kill_full_line (); + command_editor::clear_screen (); + }); } -void main_window::handle_clear_history_request (void) +void main_window::handle_clear_history_request () { emit interpreter_event ([] (interpreter& interp) - { - // INTERPRETER THREAD - - history_system& history_sys = interp.get_history_system (); - - history_sys.do_history (ovl ("-c")); - }); + { + // INTERPRETER THREAD + + history_system& history_sys = interp.get_history_system (); + + history_sys.do_history (ovl ("-c")); + }); } -void main_window::handle_undo_request (void) +void main_window::handle_undo_request () { if (command_window_has_focus ()) { emit interpreter_event - ([] (void) - { - // INTERPRETER THREAD - - command_editor::undo (); - command_editor::redisplay (); - }); + ([] () + { + // INTERPRETER THREAD + + command_editor::undo (); + command_editor::redisplay (); + }); } else emit undo_signal (); @@ -849,28 +832,28 @@ qt_link->wake_all (); } -void main_window::open_online_documentation_page (void) +void main_window::open_online_documentation_page () { QDesktopServices::openUrl (QUrl ("https://octave.org/doc/interpreter/index.html")); } -void main_window::open_bug_tracker_page (void) +void main_window::open_bug_tracker_page () { QDesktopServices::openUrl (QUrl ("https://octave.org/bugs.html")); } -void main_window::open_octave_packages_page (void) +void main_window::open_octave_packages_page () { QDesktopServices::openUrl (QUrl ("https://packages.octave.org/index.html")); } -void main_window::open_contribute_page (void) +void main_window::open_contribute_page () { QDesktopServices::openUrl (QUrl ("https://octave.org/contribute.html")); } -void main_window::open_donate_page (void) +void main_window::open_donate_page () { QDesktopServices::openUrl (QUrl ("https://octave.org/donate.html")); } @@ -885,17 +868,13 @@ return; } - m_settings_dlg = new settings_dialog (this, m_octave_qobj, desired_tab); + m_settings_dlg = new settings_dialog (this, desired_tab); connect (m_settings_dlg, &settings_dialog::apply_new_settings, this, &main_window::request_reload_settings); - - m_settings_dlg->setModal (false); - m_settings_dlg->setAttribute (Qt::WA_DeleteOnClose); - m_settings_dlg->show (); } -void main_window::show_about_octave (void) +void main_window::show_about_octave () { std::string message = octave_name_version_copyright_copying_warranty_and_bugs (true); @@ -904,17 +883,15 @@ QString::fromStdString (message)); } -void main_window::notice_settings (const gui_settings *settings, - bool update_by_worker) +void main_window::notice_settings (bool update_by_worker) { - if (! settings) - return; + gui_settings settings; // Get desired style from preferences or take the default one if // the desired one is not found - QString preferred_style = settings->value (global_style).toString (); - - if (preferred_style == global_style.def.toString ()) + QString preferred_style = settings.string_value (global_style); + + if (preferred_style == global_style.def ().toString ()) preferred_style = m_default_style; QApplication* qapp = m_octave_qobj.qapplication(); @@ -938,7 +915,7 @@ } // the widget's icons (when floating) - QString icon_set = settings->value (dw_icon_set).toString (); + QString icon_set = settings.string_value (dw_icon_set); QString icon; for (auto *widget : dock_widget_list ()) @@ -954,29 +931,28 @@ } } - int size_idx = settings->value (global_icon_size).toInt (); + int size_idx = settings.int_value (global_icon_size); size_idx = (size_idx > 0) - (size_idx < 0) + 1; // Make valid index from 0 to 2 QStyle *st = style (); int icon_size = st->pixelMetric (global_icon_sizes[size_idx]); m_main_tool_bar->setIconSize (QSize (icon_size, icon_size)); - if (settings->value (global_status_bar).toBool ()) + if (settings.bool_value (global_status_bar)) m_status_bar->show (); else m_status_bar->hide (); m_prevent_readline_conflicts - = settings->value (sc_prevent_rl_conflicts).toBool (); + = settings.bool_value (sc_prevent_rl_conflicts); m_prevent_readline_conflicts_menu - = settings->value (sc_prevent_rl_conflicts_menu).toBool (); + = settings.bool_value (sc_prevent_rl_conflicts_menu); m_suppress_dbg_location - = ! settings->value (cs_dbg_location).toBool (); - - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - rmgr.update_network_settings (); + = ! settings.bool_value (cs_dbg_location); + + settings.update_network_settings (); emit active_dock_changed (nullptr, m_active_dock); // update dock widget styles @@ -984,14 +960,14 @@ bool do_disable_main_menu_shortcuts = (m_active_dock == m_editor_window) - || (m_prevent_readline_conflicts_menu - && (m_active_dock == m_command_window)); + || (m_prevent_readline_conflicts_menu + && (m_active_dock == m_command_window)); disable_menu_shortcuts (do_disable_main_menu_shortcuts); // Check whether some octave internal preferences have to be updated QString new_default_encoding - = settings->value (ed_default_enc).toString (); + = settings.string_value (ed_default_enc); // Do not update internal pref only if a) this update was not initiated // by the worker and b) the pref has really changes if (! update_by_worker && (new_default_encoding != m_default_encoding)) @@ -1003,10 +979,10 @@ // getting the cursor blink preferences from all OS environments bool cursor_blinking; - if (settings->contains (global_cursor_blinking.key)) - cursor_blinking = settings->value (global_cursor_blinking).toBool (); + if (settings.contains (global_cursor_blinking.settings_key ())) + cursor_blinking = settings.bool_value (global_cursor_blinking); else - cursor_blinking = settings->value (cs_cursor_blinking).toBool (); + cursor_blinking = settings.bool_value (cs_cursor_blinking); if (cursor_blinking) QApplication::setCursorFlashTime (1000); // 1000 ms flash time @@ -1042,7 +1018,7 @@ return darkPalette; } -void main_window::prepare_to_exit (void) +void main_window::prepare_to_exit () { // Find files dialog is constructed dynamically, not at time of main_window // construction. Connecting it to qApp aboutToQuit signal would have @@ -1060,7 +1036,7 @@ m_active_dock = nullptr; } -void main_window::go_to_previous_widget (void) +void main_window::go_to_previous_widget () { m_previous_dock->activate (); } @@ -1080,13 +1056,14 @@ m_current_directory_combo_box->setCurrentIndex (0); } -void main_window::browse_for_directory (void) +void main_window::browse_for_directory () { // FIXME: Remove, if for all common KDE versions (bug #54607) is resolved. int opts = QFileDialog::ShowDirsOnly; - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - if (! settings->value (global_use_native_dialogs).toBool ()) + + gui_settings settings; + + if (! settings.bool_value (global_use_native_dialogs)) opts = QFileDialog::DontUseNativeDialog; QString dir @@ -1113,15 +1090,15 @@ { emit interpreter_event ([=] (interpreter& interp) - { - // INTERPRETER THREAD - - interp.chdir (xdir.toStdString ()); - }); + { + // INTERPRETER THREAD + + interp.chdir (xdir.toStdString ()); + }); } } -void main_window::change_directory_up (void) +void main_window::change_directory_up () { set_current_working_directory (".."); } @@ -1130,7 +1107,7 @@ // combobox to change to a new directory or a directory that is already // in the drop down list. -void main_window::accept_directory_line_edit (void) +void main_window::accept_directory_line_edit () { // Get new directory name, and change to it if it is new. Otherwise, // the combo box will trigger the "activated" signal to change to the @@ -1153,18 +1130,18 @@ else { emit interpreter_event - ([=] (void) - { - // INTERPRETER THREAD - - std::string pending_input = command_editor::get_current_line (); - - command_editor::set_initial_input (pending_input); - command_editor::replace_line (command.toStdString ()); - command_editor::redisplay (); - command_editor::interrupt_event_loop (); - command_editor::accept_line (); - }); + ([=] () + { + // INTERPRETER THREAD + + std::string pending_input = command_editor::get_current_line (); + + command_editor::set_initial_input (pending_input); + command_editor::replace_line (command.toStdString ()); + command_editor::redisplay (); + command_editor::interrupt_event_loop (); + command_editor::accept_line (); + }); } focus_console_after_command (); @@ -1174,59 +1151,59 @@ { emit interpreter_event ([=] (interpreter& interp) - { - // INTERPRETER THREAD - - QString function_name = info.fileName (); - function_name.chop (info.suffix ().length () + 1); - std::string file_path = info.absoluteFilePath ().toStdString (); - - std::string pending_input = command_editor::get_current_line (); - - if (valid_identifier (function_name.toStdString ())) - { - // Valid identifier: call as function with possibility to - // debug. - - load_path& lp = interp.get_load_path (); - - std::string path = info.absolutePath ().toStdString (); - - if (lp.contains_file_in_dir (file_path, path)) - command_editor::replace_line (function_name.toStdString ()); - } - else - { - // No valid identifier: use equivalent of Fsource (), no - // debug possible. - - interp.source_file (file_path); - - command_editor::replace_line (""); - } - - command_editor::set_initial_input (pending_input); - command_editor::redisplay (); - command_editor::interrupt_event_loop (); - command_editor::accept_line (); - }); + { + // INTERPRETER THREAD + + QString function_name = info.fileName (); + function_name.chop (info.suffix ().length () + 1); + std::string file_path = info.absoluteFilePath ().toStdString (); + + std::string pending_input = command_editor::get_current_line (); + + if (valid_identifier (function_name.toStdString ())) + { + // Valid identifier: call as function with possibility to + // debug. + + load_path& lp = interp.get_load_path (); + + std::string path = info.absolutePath ().toStdString (); + + if (lp.contains_file_in_dir (file_path, path)) + command_editor::replace_line (function_name.toStdString ()); + } + else + { + // No valid identifier: use equivalent of Fsource (), no + // debug possible. + + interp.source_file (file_path); + + command_editor::replace_line (""); + } + + command_editor::set_initial_input (pending_input); + command_editor::redisplay (); + command_editor::interrupt_event_loop (); + command_editor::accept_line (); + }); focus_console_after_command (); } -void main_window::handle_new_figure_request (void) +void main_window::handle_new_figure_request () { emit interpreter_event ([] (interpreter& interp) - { - // INTERPRETER THREAD - - Fbuiltin (interp, ovl ("figure")); - Fdrawnow (interp); - }); + { + // INTERPRETER THREAD + + Fbuiltin (interp, ovl ("figure")); + Fdrawnow (interp); + }); } -void main_window::handle_enter_debugger (void) +void main_window::handle_enter_debugger () { setWindowTitle ("Octave (Debugging)"); @@ -1237,7 +1214,7 @@ m_debug_quit->setEnabled (true); } -void main_window::handle_exit_debugger (void) +void main_window::handle_exit_debugger () { setWindowTitle ("Octave"); @@ -1248,35 +1225,35 @@ m_debug_quit->setEnabled (false); } -void main_window::debug_continue (void) +void main_window::debug_continue () { emit interpreter_event ([=] (interpreter& interp) - { - // INTERPRETER THREAD - - F__db_next_breakpoint_quiet__ (interp, ovl (m_suppress_dbg_location)); - Fdbcont (interp); - - command_editor::interrupt (true); - }); + { + // INTERPRETER THREAD + + F__db_next_breakpoint_quiet__ (interp, ovl (m_suppress_dbg_location)); + Fdbcont (interp); + + command_editor::interrupt (true); + }); } -void main_window::debug_step_into (void) +void main_window::debug_step_into () { emit interpreter_event ([=] (interpreter& interp) - { - // INTERPRETER THREAD - - F__db_next_breakpoint_quiet__ (interp, ovl (m_suppress_dbg_location)); - Fdbstep (interp, ovl ("in")); - - command_editor::interrupt (true); - }); + { + // INTERPRETER THREAD + + F__db_next_breakpoint_quiet__ (interp, ovl (m_suppress_dbg_location)); + Fdbstep (interp, ovl ("in")); + + command_editor::interrupt (true); + }); } -void main_window::debug_step_over (void) +void main_window::debug_step_over () { if (m_debug_quit->isEnabled ()) { @@ -1284,15 +1261,15 @@ emit interpreter_event ([=] (interpreter& interp) - { - // INTERPRETER THREAD - - F__db_next_breakpoint_quiet__ (interp, - ovl (m_suppress_dbg_location)); - Fdbstep (interp); - - command_editor::interrupt (true); - }); + { + // INTERPRETER THREAD + + F__db_next_breakpoint_quiet__ (interp, + ovl (m_suppress_dbg_location)); + Fdbstep (interp); + + command_editor::interrupt (true); + }); } else { @@ -1301,31 +1278,31 @@ } } -void main_window::debug_step_out (void) +void main_window::debug_step_out () { emit interpreter_event ([=] (interpreter& interp) - { - // INTERPRETER THREAD - - F__db_next_breakpoint_quiet__ (interp, ovl (m_suppress_dbg_location)); - Fdbstep (interp, ovl ("out")); - - command_editor::interrupt (true); - }); + { + // INTERPRETER THREAD + + F__db_next_breakpoint_quiet__ (interp, ovl (m_suppress_dbg_location)); + Fdbstep (interp, ovl ("out")); + + command_editor::interrupt (true); + }); } -void main_window::debug_quit (void) +void main_window::debug_quit () { emit interpreter_event ([] (interpreter& interp) - { - // INTERPRETER THREAD - - Fdbquit (interp); - - command_editor::interrupt (true); - }); + { + // INTERPRETER THREAD + + Fdbquit (interp); + + command_editor::interrupt (true); + }); } // @@ -1334,16 +1311,16 @@ // These are moved from editor to here for also using them when octave // is built without qscintilla // -void main_window::request_open_file (void) +void main_window::request_open_file () { // Open file isn't a file_editor_tab or editor function since the file // might be opened in an external editor. Hence, functionality is here. - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); + gui_settings settings; + bool is_internal = m_editor_window - && ! settings->value (global_use_custom_editor.key, - global_use_custom_editor.def).toBool (); + && ! settings.value (global_use_custom_editor.settings_key (), + global_use_custom_editor.def ()).toBool (); // Create a NonModal message. QWidget *p = this; @@ -1358,7 +1335,7 @@ fileDialog->setDirectory (m_current_directory_combo_box->itemText (0)); // FIXME: Remove, if for all common KDE versions (bug #54607) is resolved. - if (! settings->value (global_use_native_dialogs).toBool ()) + if (! settings.bool_value (global_use_native_dialogs)) fileDialog->setOption(QFileDialog::DontUseNativeDialog); connect (fileDialog, &QFileDialog::filesSelected, @@ -1383,10 +1360,11 @@ // editor window or the main window. The latter is chosen, if a custom // editor is used or qscintilla is not available QWidget *p = m_editor_window; - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - if (! p || settings->value (global_use_custom_editor.key, - global_use_custom_editor.def).toBool ()) + + gui_settings settings; + + if (! p || settings.value (global_use_custom_editor.settings_key (), + global_use_custom_editor.def ()).toBool ()) p = this; QString new_name = QInputDialog::getText (p, tr ("New Function"), tr ("New function name:\n"), QLineEdit::Normal, "", &ok); @@ -1394,15 +1372,15 @@ if (ok && new_name.length () > 0) { // append suffix if it does not already exist - if (new_name.rightRef (2) != ".m") + if (new_name.right (2) != ".m") new_name.append (".m"); // check whether new files are created without prompt - if (! settings->value (ed_create_new_file).toBool ()) + if (! settings.bool_value (ed_create_new_file)) { // no, so enable this settings and wait for end of new file loading - settings->setValue (ed_create_new_file.key, true); - connect (m_editor_window, SIGNAL (file_loaded_signal (void)), - this, SLOT (restore_create_file_setting (void))); + settings.setValue (ed_create_new_file.settings_key (), true); + connect (m_editor_window, SIGNAL (file_loaded_signal ()), + this, SLOT (restore_create_file_setting ())); } // start the edit command execute_command_in_terminal ("edit " + new_name); @@ -1422,92 +1400,92 @@ emit interpreter_event ([=] (interpreter& interp) - { - // INTERPRETER THREAD - - // We can skip the entire callback function because it does not - // make any changes to the interpreter state. - - if (this_mw.isNull ()) - return; - - // Split possible subfunctions - QStringList fcn_list = fname.split ('>'); - QString fcn_name = fcn_list.at (0) + ".m"; - - // FIXME: could use symbol_exist directly, but we may also want - // to fix that to be a member function in the interpreter - // class? - - // Is it a regular function within the search path? (Call Fexist) - octave_value_list fct = Fexist (interp, ovl (fname.toStdString ()),0); - int type = fct (0).int_value (); - - QString message = QString (); - QString filename = QString (); - - switch (type) - { - case 3: - case 5: - case 103: - message = tr ("%1 is a built-in, compiled or inline\n" - "function and can not be edited."); - break; - - case 2: - // FIXME: could use a load_path function directly. - octave_value_list file_path - = Ffile_in_loadpath (interp, ovl (fcn_name.toStdString ()), 0); - if (file_path.length () > 0) - filename = QString::fromStdString (file_path (0).string_value ()); - break; - } - - if (filename.isEmpty () && message.isEmpty ()) - { - // No error so far, but function still not known - // -> try directory of edited file - // get directory - QDir dir; - if (ffile.isEmpty ()) - { - if (curr_dir.isEmpty ()) - dir = QDir (m_current_directory_combo_box->itemText (0)); - else - dir = QDir (curr_dir); - } - else - dir = QDir (QFileInfo (ffile).canonicalPath ()); - - QFileInfo file = QFileInfo (dir, fcn_name); - if (file.exists ()) - filename = file.canonicalFilePath (); // local file exists - else - { - // local file does not exist -> try private directory - file = QFileInfo (ffile); - file = QFileInfo (QDir (file.canonicalPath () + "/private"), - fcn_name); - if (file.exists ()) - filename = file.canonicalFilePath (); // private function exists - else - message = tr ("Can not find function %1"); // no file found - } - } - - if (! message.isEmpty ()) - { - emit warning_function_not_found_signal (message.arg (fname)); - return; - } - - if (! filename.endsWith (".m")) - filename.append (".m"); - - // default encoding - emit open_file_signal (filename, QString (), line); - }); + { + // INTERPRETER THREAD + + // We can skip the entire callback function because it does not + // make any changes to the interpreter state. + + if (this_mw.isNull ()) + return; + + // Split possible subfunctions + QStringList fcn_list = fname.split ('>'); + QString fcn_name = fcn_list.at (0) + ".m"; + + // FIXME: could use symbol_exist directly, but we may also want + // to fix that to be a member function in the interpreter + // class? + + // Is it a regular function within the search path? (Call Fexist) + octave_value_list fct = Fexist (interp, ovl (fname.toStdString ()),0); + int type = fct (0).int_value (); + + QString message = QString (); + QString filename = QString (); + + switch (type) + { + case 3: + case 5: + case 103: + message = tr ("%1 is a built-in, compiled or inline\n" + "function and can not be edited."); + break; + + case 2: + // FIXME: could use a load_path function directly. + octave_value_list file_path + = Ffile_in_loadpath (interp, ovl (fcn_name.toStdString ()), 0); + if (file_path.length () > 0) + filename = QString::fromStdString (file_path (0).string_value ()); + break; + } + + if (filename.isEmpty () && message.isEmpty ()) + { + // No error so far, but function still not known + // -> try directory of edited file + // get directory + QDir dir; + if (ffile.isEmpty ()) + { + if (curr_dir.isEmpty ()) + dir = QDir (m_current_directory_combo_box->itemText (0)); + else + dir = QDir (curr_dir); + } + else + dir = QDir (QFileInfo (ffile).canonicalPath ()); + + QFileInfo file = QFileInfo (dir, fcn_name); + if (file.exists ()) + filename = file.canonicalFilePath (); // local file exists + else + { + // local file does not exist -> try private directory + file = QFileInfo (ffile); + file = QFileInfo (QDir (file.canonicalPath () + "/private"), + fcn_name); + if (file.exists ()) + filename = file.canonicalFilePath (); // private function exists + else + message = tr ("Can not find function %1"); // no file found + } + } + + if (! message.isEmpty ()) + { + emit warning_function_not_found_signal (message.arg (fname)); + return; + } + + if (! filename.endsWith (".m")) + filename.append (".m"); + + // default encoding + emit open_file_signal (filename, QString (), line); + }); } void main_window::warning_function_not_found (const QString& message) @@ -1555,42 +1533,38 @@ focus_command_window (); } -void main_window::read_settings (void) +void main_window::read_settings () { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - - if (! settings) - { - qDebug ("Error: gui_settings pointer from resource manager is NULL."); - return; - } - - set_window_layout (settings); + gui_settings settings; + + set_window_layout (); // restore the list of the last directories - QStringList curr_dirs = settings->value (mw_dir_list).toStringList (); + QStringList curr_dirs = settings.string_list_value (mw_dir_list); for (int i=0; i < curr_dirs.size (); i++) { m_current_directory_combo_box->addItem (curr_dirs.at (i)); } - emit settings_changed (settings); + + emit settings_changed (); } -void main_window::init_terminal_size (void) +void main_window::init_terminal_size () { emit init_terminal_size_signal (); } -void main_window::set_window_layout (gui_settings *settings) +void main_window::set_window_layout () { + gui_settings settings; + // For resetting from some inconsistent state, first reset layout // without saving or showing it do_reset_windows (true, false); // Restore main window state and geometry from settings file or, in case // of an error (no pref values yet), from the default layout. - if (! restoreGeometry (settings->value (mw_geometry).toByteArray ())) + if (! restoreGeometry (settings.byte_array_value (mw_geometry))) { do_reset_windows (true); return; @@ -1619,7 +1593,7 @@ | Qt::WindowCloseButtonHint); } - if (! restoreState (settings->value (mw_state).toByteArray ())) + if (! restoreState (settings.byte_array_value (mw_state))) { do_reset_windows (true); return; @@ -1642,10 +1616,10 @@ bool floating = false; bool visible = true; - floating = settings->value - (dw_is_floating.key.arg (name), dw_is_floating.def).toBool (); - visible = settings->value - (dw_is_visible.key.arg (name), dw_is_visible.def).toBool (); + floating = settings.value + (dw_is_floating.settings_key ().arg (name), dw_is_floating.def ()).toBool (); + visible = settings.value + (dw_is_visible.settings_key ().arg (name), dw_is_visible.def ()).toBool (); // If floating, make window from widget. if (floating) @@ -1654,8 +1628,8 @@ if (visible) { - if (settings->value (dw_is_minimized.key.arg (name), - dw_is_minimized.def).toBool ()) + if (settings.value (dw_is_minimized.settings_key ().arg (name), + dw_is_minimized.def ()).toBool ()) widget->showMinimized (); else widget->setVisible (true); @@ -1677,29 +1651,23 @@ show (); } -void main_window::write_settings (void) +void main_window::write_settings () { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - if (! settings) - { - qDebug ("Error: gui_settings pointer from resource manager is NULL."); - return; - } - - settings->setValue (mw_geometry.key, saveGeometry ()); - settings->setValue (mw_state.key, saveState ()); + gui_settings settings; + + settings.setValue (mw_geometry.settings_key (), saveGeometry ()); + settings.setValue (mw_state.settings_key (), saveState ()); // write the list of recently used directories QStringList curr_dirs; for (int i=0; icount (); i++) { curr_dirs.append (m_current_directory_combo_box->itemText (i)); } - settings->setValue (mw_dir_list.key, curr_dirs); - settings->sync (); + settings.setValue (mw_dir_list.settings_key (), curr_dirs); + settings.sync (); } -void main_window::copyClipboard (void) +void main_window::copyClipboard () { if (m_current_directory_combo_box->hasFocus ()) { @@ -1714,7 +1682,7 @@ emit copyClipboard_signal (); } -void main_window::pasteClipboard (void) +void main_window::pasteClipboard () { if (m_current_directory_combo_box->hasFocus ()) { @@ -1730,7 +1698,7 @@ emit pasteClipboard_signal (); } -void main_window::selectAll (void) +void main_window::selectAll () { if (m_current_directory_combo_box->hasFocus ()) { @@ -1759,33 +1727,30 @@ } } -void main_window::handle_octave_ready (void) +void main_window::handle_octave_ready () { // actions after the startup files are executed - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); + + gui_settings settings; QDir startup_dir = QDir (); // current octave dir after startup - if (settings) + if (settings.bool_value (global_restore_ov_dir)) { - if (settings->value (global_restore_ov_dir).toBool ()) - { - // restore last dir from previous session - QStringList curr_dirs - = settings->value (mw_dir_list).toStringList (); - if (curr_dirs.length () > 0) - startup_dir = QDir (curr_dirs.at (0)); // last dir prev. session - } - else if (! settings->value (global_ov_startup_dir).toString ().isEmpty ()) - { - // do not restore but there is a startup dir configured - startup_dir - = QDir (settings->value (global_ov_startup_dir).toString ()); - } - - update_default_encoding (settings->value (ed_default_enc).toString ()); + // restore last dir from previous session + QStringList curr_dirs + = settings.string_list_value (mw_dir_list); + if (curr_dirs.length () > 0) + startup_dir = QDir (curr_dirs.at (0)); // last dir prev. session } + else if (! settings.string_value (global_ov_startup_dir).isEmpty ()) + { + // do not restore but there is a startup dir configured + startup_dir + = QDir (settings.string_value (global_ov_startup_dir)); + } + + update_default_encoding (settings.string_value (ed_default_enc)); if (! startup_dir.exists ()) { @@ -1802,7 +1767,7 @@ // This can not be done when the editor is created because all functions // must be known for the lexer's auto completion information m_editor_window->empty_script (true, false); - m_editor_window->restore_session (settings); + m_editor_window->restore_session (); #endif } @@ -1810,18 +1775,31 @@ { // Set initial prompt. + // The interpreter_event callback function below emits a + // signal. Because we don't control when that happens, use a + // guarded pointer so that the callback can abort if this object + // is no longer valid. + + QPointer this_mw (this); + emit interpreter_event - ([] (interpreter& interp) + ([=] (interpreter& interp) { // INTERPRETER_THREAD - event_manager& evmgr = interp.get_event_manager (); - input_system& input_sys = interp.get_input_system (); - - input_sys.PS1 (">> "); - std::string prompt = input_sys.PS1 (); - - evmgr.update_prompt (command_editor::decode_prompt_string (prompt)); + // We can skip the entire callback function because it does + // not make any changes to the interpreter state. + + if (this_mw.isNull ()) + return; + + interp.PS1 (">> "); + std::string prompt = interp.PS1 (); + + std::string decoded_prompt + = command_editor::decode_prompt_string (prompt); + + emit update_prompt_signal (QString::fromStdString (decoded_prompt)); }); } @@ -1829,12 +1807,12 @@ focus_command_window (); // make sure that the command window has focus } -void main_window::handle_set_path_dialog_request (void) +void main_window::handle_set_path_dialog_request () { if (m_set_path_dlg) // m_set_path_dlg is a guarded pointer! return; - m_set_path_dlg = new set_path_dialog (this, m_octave_qobj); + m_set_path_dlg = new set_path_dialog (this); m_set_path_dlg->setModal (false); m_set_path_dlg->setAttribute (Qt::WA_DeleteOnClose); @@ -1870,7 +1848,7 @@ if (! m_find_files_dlg) { - m_find_files_dlg = new find_files_dialog (this, m_octave_qobj); + m_find_files_dlg = new find_files_dialog (this); connect (m_find_files_dlg, &find_files_dialog::finished, this, &main_window::find_files_finished); @@ -1898,15 +1876,15 @@ void main_window::set_screen_size (int ht, int wd) { emit interpreter_event - ([=] (void) - { - // INTERPRETER THREAD - - command_editor::set_screen_size (ht, wd); - }); + ([=] () + { + // INTERPRETER THREAD + + command_editor::set_screen_size (ht, wd); + }); } -void main_window::clipboard_has_changed (void) +void main_window::clipboard_has_changed () { if (m_clipboard->text ().isEmpty ()) { @@ -1920,7 +1898,7 @@ } } -void main_window::clear_clipboard (void) +void main_window::clear_clipboard () { m_clipboard->clear (QClipboard::Clipboard); } @@ -1936,14 +1914,15 @@ } } -void main_window::restore_create_file_setting (void) +void main_window::restore_create_file_setting () { // restore the new files creation setting - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - settings->setValue (ed_create_new_file.key, false); - disconnect (m_editor_window, SIGNAL (file_loaded_signal (void)), - this, SLOT (restore_create_file_setting (void))); + + gui_settings settings; + + settings.setValue (ed_create_new_file.settings_key (), false); + disconnect (m_editor_window, SIGNAL (file_loaded_signal ()), + this, SLOT (restore_create_file_setting ())); } void main_window::set_file_encoding (const QString& new_encoding) @@ -1960,37 +1939,34 @@ emit open_file_signal (open_file_names.at (i), m_file_encoding, -1); } -void main_window::profiler_session (void) +void main_window::profiler_session () { emit interpreter_event ([=] (interpreter& interp) - { - // INTERPRETER THREAD - - Ffeval (interp, ovl ("profile","on")); - }); + { + // INTERPRETER THREAD + F__profiler_enable__ (interp, ovl (true)); + }); } -void main_window::profiler_session_resume (void) +void main_window::profiler_session_resume () { emit interpreter_event ([=] (interpreter& interp) - { - // INTERPRETER THREAD - - Ffeval (interp, ovl ("profile","resume")); - }); + { + // INTERPRETER THREAD + F__profiler_enable__ (interp, ovl (true)); + }); } -void main_window::profiler_stop (void) +void main_window::profiler_stop () { emit interpreter_event ([=] (interpreter& interp) - { - // INTERPRETER THREAD - - Ffeval (interp, ovl ("profile","off")); - }); + { + // INTERPRETER THREAD + F__profiler_enable__ (interp, ovl (false)); + }); } void main_window::handle_profiler_status_update (bool active) @@ -2005,7 +1981,7 @@ m_profiler_status_indicator->set_state (state); } -void main_window::profiler_show (void) +void main_window::profiler_show () { // Do not use a separate interpreter event as in the other // profiler slots since the output of the command "profshow" @@ -2036,18 +2012,18 @@ { emit interpreter_event ([] (interpreter& interp) - { - // INTERPRETER THREAD - - interp.quit (0, false, false); - }); + { + // INTERPRETER THREAD + + interp.quit (0, false, false); + }); } } else e->ignore (); } -void main_window::construct_central_widget (void) +void main_window::construct_central_widget () { // Create and set the central widget. QMainWindow takes ownership of // the widget (pointer) so there is no need to delete the object upon @@ -2063,7 +2039,7 @@ // Main subroutine of the constructor -void main_window::construct (void) +void main_window::construct () { setWindowIcon (QIcon (dw_icon_set_names["NONE"])); @@ -2083,8 +2059,9 @@ connect (qApp, &QApplication::focusChanged, this, &main_window::focus_changed); + // Default argument requires wrapper. connect (this, &main_window::settings_changed, - this, [=] (const gui_settings *settings) { notice_settings (settings); }); + this, [=] () { notice_settings (); }); // Connections for signals from the interpreter thread where the slot // should be executed by the gui thread @@ -2109,7 +2086,7 @@ configure_shortcuts (); } -void main_window::construct_octave_qt_link (void) +void main_window::construct_octave_qt_link () { interpreter_qobject *interp_qobj = m_octave_qobj.interpreter_qobj (); @@ -2186,7 +2163,7 @@ return menu; } -void main_window::construct_menu_bar (void) +void main_window::construct_menu_bar () { QMenuBar *menu_bar = menuBar (); @@ -2227,11 +2204,11 @@ construct_new_menu (file_menu); - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - - m_open_action = add_action ( - file_menu, rmgr.icon ("document-open"), tr ("Open..."), - SLOT (request_open_file (void)), this); + gui_settings settings; + + m_open_action + = add_action (file_menu, settings.icon ("document-open"), tr ("Open..."), + SLOT (request_open_file ()), this); m_open_action->setToolTip (tr ("Open an existing file in editor")); #if defined (HAVE_QSCINTILLA) @@ -2240,19 +2217,19 @@ file_menu->addSeparator (); - m_load_workspace_action = add_action ( - file_menu, QIcon (), tr ("Load Workspace..."), - SLOT (handle_load_workspace_request (void)), this); - - m_save_workspace_action = add_action ( - file_menu, QIcon (), tr ("Save Workspace As..."), - SLOT (handle_save_workspace_request (void)), this); + m_load_workspace_action + = add_action (file_menu, QIcon (), tr ("Load Workspace..."), + SLOT (handle_load_workspace_request ()), this); + + m_save_workspace_action + = add_action (file_menu, QIcon (), tr ("Save Workspace As..."), + SLOT (handle_save_workspace_request ()), this); file_menu->addSeparator (); - m_exit_action = add_action ( - file_menu, QIcon (), tr ("Exit"), - SLOT (close (void)), this); + m_exit_action + = add_action (file_menu, QIcon (), tr ("Exit"), + SLOT (close ()), this); m_exit_action->setMenuRole (QAction::QuitRole); // Connect signal related to opening or creating editor files @@ -2272,41 +2249,40 @@ { QMenu *new_menu = p->addMenu (tr ("New")); - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - - m_new_script_action = add_action ( - new_menu, rmgr.icon ("document-new"), tr ("New Script"), - SLOT (request_new_script (void)), this); - - m_new_function_action = add_action ( - new_menu, QIcon (), tr ("New Function..."), - SLOT (request_new_function (void)), this); - - m_new_figure_action = add_action ( - new_menu, QIcon (), tr ("New Figure"), - SLOT (handle_new_figure_request (void)), this); + gui_settings settings; + + m_new_script_action + = add_action (new_menu, settings.icon ("document-new"), tr ("New Script"), + SLOT (request_new_script ()), this); + + m_new_function_action + = add_action (new_menu, QIcon (), tr ("New Function..."), + SLOT (request_new_function ()), this); + + m_new_figure_action + = add_action (new_menu, QIcon (), tr ("New Figure"), + SLOT (handle_new_figure_request ()), this); } void main_window::construct_edit_menu (QMenuBar *p) { QMenu *edit_menu = m_add_menu (p, tr ("&Edit")); - QKeySequence ctrl_shift = Qt::ControlModifier + Qt::ShiftModifier; - - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); + gui_settings settings; + m_undo_action - = edit_menu->addAction (rmgr.icon ("edit-undo"), tr ("Undo")); + = edit_menu->addAction (settings.icon ("edit-undo"), tr ("Undo")); m_undo_action->setShortcutContext (Qt::ApplicationShortcut); edit_menu->addSeparator (); m_copy_action - = edit_menu->addAction (rmgr.icon ("edit-copy"), tr ("Copy"), this, + = edit_menu->addAction (settings.icon ("edit-copy"), tr ("Copy"), this, &main_window::copyClipboard); m_copy_action->setShortcutContext (Qt::ApplicationShortcut); m_paste_action - = edit_menu->addAction (rmgr.icon ("edit-paste"), tr ("Paste"), this, + = edit_menu->addAction (settings.icon ("edit-paste"), tr ("Paste"), this, &main_window::pasteClipboard); m_paste_action->setShortcutContext (Qt::ApplicationShortcut); @@ -2322,7 +2298,8 @@ edit_menu->addSeparator (); m_find_files_action - = edit_menu->addAction (rmgr.icon ("edit-find"), tr ("Find Files...")); + = edit_menu->addAction (settings.icon ("edit-find"), + tr ("Find Files...")); edit_menu->addSeparator (); @@ -2341,7 +2318,7 @@ = edit_menu->addAction (tr ("Set Path")); m_preferences_action - = edit_menu->addAction (rmgr.icon ("preferences-system"), + = edit_menu->addAction (settings.icon ("preferences-system"), tr ("Preferences...")); connect (m_find_files_action, &QAction::triggered, @@ -2379,8 +2356,9 @@ const QString& item, const char *member) { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - QAction *action = add_action (m_debug_menu, rmgr.icon (QString (icon)), + gui_settings settings; + + QAction *action = add_action (m_debug_menu, settings.icon (QString (icon)), item, member); action->setEnabled (false); @@ -2399,19 +2377,19 @@ m_debug_step_over = construct_debug_menu_item ("db-step", tr ("Step"), - SLOT (debug_step_over (void))); + SLOT (debug_step_over ())); m_debug_step_into = construct_debug_menu_item ("db-step-in", tr ("Step In"), - SLOT (debug_step_into (void))); + SLOT (debug_step_into ())); m_debug_step_out = construct_debug_menu_item ("db-step-out", tr ("Step Out"), - SLOT (debug_step_out (void))); + SLOT (debug_step_out ())); m_debug_continue = construct_debug_menu_item ("db-cont", tr ("Continue"), - SLOT (debug_continue (void))); + SLOT (debug_continue ())); m_debug_menu->addSeparator (); #if defined (HAVE_QSCINTILLA) @@ -2420,7 +2398,7 @@ m_debug_quit = construct_debug_menu_item ("db-stop", tr ("Quit Debug Mode"), - SLOT (debug_quit (void))); + SLOT (debug_quit ())); } void main_window::construct_tools_menu (QMenuBar *p) @@ -2428,17 +2406,17 @@ QMenu *tools_menu = m_add_menu (p, tr ("&Tools")); m_profiler_start = add_action (tools_menu, QIcon (), - tr ("Start &Profiler Session"), SLOT (profiler_session ())); + tr ("Start &Profiler Session"), SLOT (profiler_session ())); m_profiler_resume = add_action (tools_menu, QIcon (), - tr ("&Resume Profiler Session"), SLOT (profiler_session_resume ())); + tr ("&Resume Profiler Session"), SLOT (profiler_session_resume ())); m_profiler_stop = add_action (tools_menu, QIcon (), - tr ("&Stop Profiler"), SLOT (profiler_stop ())); + tr ("&Stop Profiler"), SLOT (profiler_stop ())); m_profiler_stop->setEnabled (false); m_profiler_show = add_action (tools_menu, QIcon (), - tr ("&Show Profile Data"), SLOT (profiler_show ())); + tr ("&Show Profile Data"), SLOT (profiler_show ())); } void main_window::editor_tabs_changed (bool have_tabs, bool is_octave) @@ -2474,8 +2452,8 @@ else { // action for focus of dock widget - connect (action, SIGNAL (triggered (void)), - widget, SLOT (activate (void))); + connect (action, SIGNAL (triggered ()), + widget, SLOT (activate ())); } } else @@ -2537,12 +2515,12 @@ window_menu->addSeparator (); m_previous_dock_action = add_action (window_menu, QIcon (), - tr ("Previous Widget"), SLOT (go_to_previous_widget (void))); + tr ("Previous Widget"), SLOT (go_to_previous_widget ())); window_menu->addSeparator (); m_reset_windows_action = add_action (window_menu, QIcon (), - tr ("Reset Default Window Layout"), SLOT (reset_windows (void))); + tr ("Reset Default Window Layout"), SLOT (reset_windows ())); } void main_window::construct_help_menu (QMenuBar *p) @@ -2603,7 +2581,7 @@ m_current_news_action->setShortcutContext (Qt::ApplicationShortcut); } -void main_window::construct_tool_bar (void) +void main_window::construct_tool_bar () { m_main_tool_bar = addToolBar (tr ("Toolbar")); m_main_tool_bar->setStyleSheet (m_main_tool_bar->styleSheet () @@ -2627,8 +2605,8 @@ m_current_directory_combo_box->setEditable (true); m_current_directory_combo_box->setInsertPolicy (QComboBox::NoInsert); m_current_directory_combo_box->setToolTip (tr ("Enter directory name")); - m_current_directory_combo_box->setMaxVisibleItems (current_directory_max_visible); - m_current_directory_combo_box->setMaxCount (current_directory_max_count); + m_current_directory_combo_box->setMaxVisibleItems (CURRENT_DIRECTORY_MAX_VISIBLE); + m_current_directory_combo_box->setMaxCount (CURRENT_DIRECTORY_MAX_COUNT); QSizePolicy sizePol (QSizePolicy::Preferred, QSizePolicy::Preferred); m_current_directory_combo_box->setSizePolicy (sizePol); @@ -2636,12 +2614,14 @@ // need to delete these upon destroying this main_window. m_main_tool_bar->addWidget (new QLabel (tr ("Current Directory: "))); m_main_tool_bar->addWidget (m_current_directory_combo_box); - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); + + gui_settings settings; + QAction *current_dir_up - = m_main_tool_bar->addAction (rmgr.icon ("folder-up", false, "go-up"), + = m_main_tool_bar->addAction (settings.icon ("folder-up", false, "go-up"), tr ("One directory up")); QAction *current_dir_search - = m_main_tool_bar->addAction (rmgr.icon ("folder"), + = m_main_tool_bar->addAction (settings.icon ("folder"), tr ("Browse directories")); connect (m_current_directory_combo_box, SIGNAL (activated (const QString&)), @@ -2661,90 +2641,90 @@ this, &main_window::handle_undo_request); } -void main_window::focus_console_after_command (void) +void main_window::focus_console_after_command () { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - if (settings->value (cs_focus_cmd).toBool ()) + gui_settings settings; + + if (settings.bool_value (cs_focus_cmd)) focus_command_window (); } -void main_window::configure_shortcuts (void) +void main_window::configure_shortcuts () { + gui_settings settings; + bool enable = ! ((m_active_dock == m_command_window) && m_prevent_readline_conflicts); - shortcut_manager& scmgr = m_octave_qobj.get_shortcut_manager (); - // file menu - scmgr.set_shortcut (m_open_action, sc_main_file_open_file, enable); - scmgr.set_shortcut (m_new_script_action, sc_main_file_new_file, enable); - scmgr.set_shortcut (m_new_function_action, sc_main_file_new_function, enable); - scmgr.set_shortcut (m_new_figure_action, sc_main_file_new_figure, enable); - scmgr.set_shortcut (m_load_workspace_action, sc_main_file_load_workspace, enable); - scmgr.set_shortcut (m_save_workspace_action, sc_main_file_save_workspace, enable); - scmgr.set_shortcut (m_exit_action, sc_main_file_exit, enable); + settings.set_shortcut (m_open_action, sc_main_file_open_file, enable); + settings.set_shortcut (m_new_script_action, sc_main_file_new_file, enable); + settings.set_shortcut (m_new_function_action, sc_main_file_new_function, enable); + settings.set_shortcut (m_new_figure_action, sc_main_file_new_figure, enable); + settings.set_shortcut (m_load_workspace_action, sc_main_file_load_workspace, enable); + settings.set_shortcut (m_save_workspace_action, sc_main_file_save_workspace, enable); + settings.set_shortcut (m_exit_action, sc_main_file_exit, enable); // edit menu - scmgr.set_shortcut (m_copy_action, sc_main_edit_copy, enable); - scmgr.set_shortcut (m_paste_action, sc_main_edit_paste, enable); - scmgr.set_shortcut (m_undo_action, sc_main_edit_undo, enable); - scmgr.set_shortcut (m_select_all_action, sc_main_edit_select_all, enable); - scmgr.set_shortcut (m_clear_clipboard_action, sc_main_edit_clear_clipboard, enable); - scmgr.set_shortcut (m_find_files_action, sc_main_edit_find_in_files, enable); - scmgr.set_shortcut (m_clear_command_history_action, sc_main_edit_clear_history, enable); - scmgr.set_shortcut (m_clear_command_window_action, sc_main_edit_clear_command_window, enable); - scmgr.set_shortcut (m_clear_workspace_action, sc_main_edit_clear_workspace, enable); - scmgr.set_shortcut (m_set_path_action, sc_main_edit_set_path, enable); - scmgr.set_shortcut (m_preferences_action, sc_main_edit_preferences, enable); + settings.set_shortcut (m_copy_action, sc_main_edit_copy, enable); + settings.set_shortcut (m_paste_action, sc_main_edit_paste, enable); + settings.set_shortcut (m_undo_action, sc_main_edit_undo, enable); + settings.set_shortcut (m_select_all_action, sc_main_edit_select_all, enable); + settings.set_shortcut (m_clear_clipboard_action, sc_main_edit_clear_clipboard, enable); + settings.set_shortcut (m_find_files_action, sc_main_edit_find_in_files, enable); + settings.set_shortcut (m_clear_command_history_action, sc_main_edit_clear_history, enable); + settings.set_shortcut (m_clear_command_window_action, sc_main_edit_clear_command_window, enable); + settings.set_shortcut (m_clear_workspace_action, sc_main_edit_clear_workspace, enable); + settings.set_shortcut (m_set_path_action, sc_main_edit_set_path, enable); + settings.set_shortcut (m_preferences_action, sc_main_edit_preferences, enable); // debug menu - scmgr.set_shortcut (m_debug_step_over, sc_main_debug_step_over, enable); - scmgr.set_shortcut (m_debug_step_into, sc_main_debug_step_into, enable); - scmgr.set_shortcut (m_debug_step_out, sc_main_debug_step_out, enable); - scmgr.set_shortcut (m_debug_continue, sc_main_debug_continue, enable); - scmgr.set_shortcut (m_debug_quit, sc_main_debug_quit, enable); + settings.set_shortcut (m_debug_step_over, sc_main_debug_step_over, enable); + settings.set_shortcut (m_debug_step_into, sc_main_debug_step_into, enable); + settings.set_shortcut (m_debug_step_out, sc_main_debug_step_out, enable); + settings.set_shortcut (m_debug_continue, sc_main_debug_continue, enable); + settings.set_shortcut (m_debug_quit, sc_main_debug_quit, enable); // tools menu - scmgr.set_shortcut (m_profiler_start, sc_main_tools_start_profiler, enable); - scmgr.set_shortcut (m_profiler_resume, sc_main_tools_resume_profiler, enable); - scmgr.set_shortcut (m_profiler_stop, sc_main_tools_start_profiler, enable); // same, toggling - scmgr.set_shortcut (m_profiler_show, sc_main_tools_show_profiler, enable); + settings.set_shortcut (m_profiler_start, sc_main_tools_start_profiler, enable); + settings.set_shortcut (m_profiler_resume, sc_main_tools_resume_profiler, enable); + settings.set_shortcut (m_profiler_stop, sc_main_tools_start_profiler, enable); // same, toggling + settings.set_shortcut (m_profiler_show, sc_main_tools_show_profiler, enable); // window menu - scmgr.set_shortcut (m_show_command_window_action, sc_main_window_show_command, enable); - scmgr.set_shortcut (m_show_history_action, sc_main_window_show_history, enable); - scmgr.set_shortcut (m_show_workspace_action, sc_main_window_show_workspace, enable); - scmgr.set_shortcut (m_show_file_browser_action, sc_main_window_show_file_browser, enable); - scmgr.set_shortcut (m_show_editor_action, sc_main_window_show_editor, enable); - scmgr.set_shortcut (m_show_documentation_action, sc_main_window_show_doc, enable); - scmgr.set_shortcut (m_show_variable_editor_action, sc_main_window_show_variable_editor, enable); - scmgr.set_shortcut (m_reset_windows_action, sc_main_window_reset, enable); - scmgr.set_shortcut (m_command_window_action, sc_main_window_command, enable); + settings.set_shortcut (m_show_command_window_action, sc_main_window_show_command, enable); + settings.set_shortcut (m_show_history_action, sc_main_window_show_history, enable); + settings.set_shortcut (m_show_workspace_action, sc_main_window_show_workspace, enable); + settings.set_shortcut (m_show_file_browser_action, sc_main_window_show_file_browser, enable); + settings.set_shortcut (m_show_editor_action, sc_main_window_show_editor, enable); + settings.set_shortcut (m_show_documentation_action, sc_main_window_show_doc, enable); + settings.set_shortcut (m_show_variable_editor_action, sc_main_window_show_variable_editor, enable); + settings.set_shortcut (m_reset_windows_action, sc_main_window_reset, enable); + settings.set_shortcut (m_command_window_action, sc_main_window_command, enable); // Switching to the other widgets (including the previous one) is always enabled - scmgr.set_shortcut (m_history_action, sc_main_window_history, true); - scmgr.set_shortcut (m_workspace_action, sc_main_window_workspace, true); - scmgr.set_shortcut (m_file_browser_action, sc_main_window_file_browser, true); - scmgr.set_shortcut (m_editor_action, sc_main_window_editor, true); - scmgr.set_shortcut (m_documentation_action, sc_main_window_doc, true); - scmgr.set_shortcut (m_variable_editor_action, sc_main_window_variable_editor, true); - scmgr.set_shortcut (m_previous_dock_action, sc_main_window_previous_dock, true); + settings.set_shortcut (m_history_action, sc_main_window_history, true); + settings.set_shortcut (m_workspace_action, sc_main_window_workspace, true); + settings.set_shortcut (m_file_browser_action, sc_main_window_file_browser, true); + settings.set_shortcut (m_editor_action, sc_main_window_editor, true); + settings.set_shortcut (m_documentation_action, sc_main_window_doc, true); + settings.set_shortcut (m_variable_editor_action, sc_main_window_variable_editor, true); + settings.set_shortcut (m_previous_dock_action, sc_main_window_previous_dock, true); // help menu - scmgr.set_shortcut (m_ondisk_doc_action, sc_main_help_ondisk_doc, enable); - scmgr.set_shortcut (m_online_doc_action, sc_main_help_online_doc, enable); - scmgr.set_shortcut (m_report_bug_action, sc_main_help_report_bug, enable); - scmgr.set_shortcut (m_octave_packages_action, sc_main_help_packages, enable); - scmgr.set_shortcut (m_contribute_action, sc_main_help_contribute, enable); - scmgr.set_shortcut (m_developer_action, sc_main_help_developer, enable); - scmgr.set_shortcut (m_about_octave_action, sc_main_help_about, enable); + settings.set_shortcut (m_ondisk_doc_action, sc_main_help_ondisk_doc, enable); + settings.set_shortcut (m_online_doc_action, sc_main_help_online_doc, enable); + settings.set_shortcut (m_report_bug_action, sc_main_help_report_bug, enable); + settings.set_shortcut (m_octave_packages_action, sc_main_help_packages, enable); + settings.set_shortcut (m_contribute_action, sc_main_help_contribute, enable); + settings.set_shortcut (m_developer_action, sc_main_help_developer, enable); + settings.set_shortcut (m_about_octave_action, sc_main_help_about, enable); // news menu - scmgr.set_shortcut (m_release_notes_action, sc_main_news_release_notes, enable); - scmgr.set_shortcut (m_current_news_action, sc_main_news_community_news, enable); + settings.set_shortcut (m_release_notes_action, sc_main_news_release_notes, enable); + settings.set_shortcut (m_current_news_action, sc_main_news_community_news, enable); } -QList main_window::dock_widget_list (void) +QList main_window::dock_widget_list () { QList list = QList (); list.append (static_cast (m_command_window)); @@ -2768,32 +2748,20 @@ emit interpreter_event ([=] (interpreter& interp) - { - // INTERPRETER THREAD - - F__mfile_encoding__ (interp, ovl (mfile_encoding)); - }); + { + // INTERPRETER THREAD + + Fmfile_encoding (interp, ovl (mfile_encoding)); + }); } void main_window::resize_dock (QDockWidget *dw, int width, int height) { -#if defined (HAVE_QMAINWINDOW_RESIZEDOCKS) // resizeDockWidget was added to Qt in Qt 5.6 if (width >= 0) resizeDocks ({dw}, {width}, Qt::Horizontal); if (height >= 0) resizeDocks ({dw}, {height}, Qt::Vertical); -#else - // This replacement of resizeDockWidget is not very reliable. - // But even if Qt4 is not yet - QSize s = dw->widget ()->size (); - if (width >= 0) - s.setWidth (width); - if (height >= 0) - s.setHeight (height); - dw->widget ()->resize (s); - dw->adjustSize (); -#endif } // The default main window size relative to the desktop size @@ -2806,7 +2774,7 @@ resize (2*win_x/3, 7*win_y/8); } -void main_window::reset_windows (void) +void main_window::reset_windows () { // Slot for resetting the window layout to the default one hide (); @@ -2913,11 +2881,10 @@ if (save) { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - - settings->setValue (mw_geometry.key, saveGeometry ()); - settings->setValue (mw_state.key, saveState ()); + gui_settings settings; + + settings.setValue (mw_geometry.settings_key (), saveGeometry ()); + settings.setValue (mw_state.settings_key (), saveState ()); } focus_command_window (); diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/main-window.h --- a/libgui/src/main-window.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/main-window.h Fri May 12 08:03:14 2023 +0200 @@ -52,7 +52,6 @@ #include "interpreter-qobject.h" #include "led-indicator.h" #include "octave-dock-widget.h" -#include "octave-qobject.h" #include "qt-interpreter-events.h" #include "set-path-dialog.h" #include "terminal-dock-widget.h" @@ -65,6 +64,7 @@ class interpreter; +class base_qobject; class settings_dialog; //! Represents the main window. @@ -80,35 +80,35 @@ main_window (base_qobject& oct_qobj); - ~main_window (void); + ~main_window (); void make_dock_widget_connections (octave_dock_widget *dw); - bool command_window_has_focus (void) const; + bool command_window_has_focus () const; - void focus_command_window (void); + void focus_command_window (); - bool confirm_shutdown (void); + bool confirm_shutdown (); signals: // Note: CLOSE_GUI_SIGNAL is currently only used by the new // experimental terminal widget. - void close_gui_signal (void); + void close_gui_signal (); void active_dock_changed (octave_dock_widget *, octave_dock_widget *); void editor_focus_changed (bool); - void settings_changed (const gui_settings *); - void init_terminal_size_signal (void); - void init_window_menu (void); + void settings_changed (); + void init_terminal_size_signal (); + void init_window_menu (); void new_file_signal (const QString&); void open_file_signal (const QString&); void open_file_signal (const QString& file, const QString& enc, int line); - void step_into_file_signal (void); + void step_into_file_signal (); void show_community_news_signal (int serial); - void show_release_notes_signal (void); + void show_release_notes_signal (); void update_gui_lexer_signal (bool); @@ -117,10 +117,10 @@ void update_breakpoint_marker_signal (bool insert, const QString& file, int line, const QString& cond); - void copyClipboard_signal (void); - void pasteClipboard_signal (void); - void selectAll_signal (void); - void undo_signal (void); + void copyClipboard_signal (); + void pasteClipboard_signal (); + void selectAll_signal (); + void undo_signal (); void add_actions_signal (QList action_list); @@ -131,61 +131,62 @@ void execute_command_signal (const QString& command); + void update_prompt_signal (const QString& prompt); + public slots: void focus_changed (QWidget *w_old, QWidget *w_new); void focus_window (const QString& win_name); - void request_reload_settings (void); + void request_reload_settings (); void report_status_message (const QString& statusMessage); - void handle_save_workspace_request (void); + void handle_save_workspace_request (); void handle_load_workspace_request (const QString& file = QString ()); void handle_open_any_request (const QString& file = QString ()); - void handle_clear_workspace_request (void); - void handle_clear_command_window_request (void); - void handle_clear_history_request (void); - void handle_undo_request (void); + void handle_clear_workspace_request (); + void handle_clear_command_window_request (); + void handle_clear_history_request (); + void handle_undo_request (); void modify_path (const QStringList& dir_list, bool rm, bool subdirs); void edit_mfile (const QString&, int); void file_remove_proxy (const QString& o, const QString& n); - void open_online_documentation_page (void); - void open_bug_tracker_page (void); - void open_octave_packages_page (void); - void open_contribute_page (void); - void open_donate_page (void); + void open_online_documentation_page (); + void open_bug_tracker_page (); + void open_octave_packages_page (); + void open_contribute_page (); + void open_donate_page (); void process_settings_dialog_request (const QString& desired_tab = QString ()); - void show_about_octave (void); - void notice_settings (const gui_settings *settings, - bool update_by_worker = false); + void show_about_octave (); + void notice_settings (bool update_by_worker = false); QPalette getFusionDarkPalette(); - void prepare_to_exit (void); - void go_to_previous_widget (void); - void reset_windows (void); + void prepare_to_exit (); + void go_to_previous_widget (); + void reset_windows (); void do_reset_windows (bool show = true, bool save = true, bool force_all = false); void update_octave_directory (const QString& dir); - void browse_for_directory (void); + void browse_for_directory (); void set_current_working_directory (const QString& dir); - void change_directory_up (void); - void accept_directory_line_edit (void); + void change_directory_up (); + void accept_directory_line_edit (); void execute_command_in_terminal (const QString& dir); void run_file_in_terminal (const QFileInfo& info); - void handle_new_figure_request (void); + void handle_new_figure_request (); - void handle_enter_debugger (void); - void handle_exit_debugger (void); - void debug_continue (void); - void debug_step_into (void); - void debug_step_over (void); - void debug_step_out (void); - void debug_quit (void); + void handle_enter_debugger (); + void handle_exit_debugger (); + void debug_continue (); + void debug_step_into (); + void debug_step_over (); + void debug_step_out (); + void debug_quit (); void editor_tabs_changed (bool, bool); - void request_open_file (void); + void request_open_file (); void request_new_script (const QString& commands = QString ()); void request_new_function (bool triggered = true); void handle_edit_mfile_request (const QString& name, const QString& file, @@ -197,28 +198,28 @@ const QString& file, int line, const QString& cond); - void read_settings (void); - void init_terminal_size (void); - void set_window_layout (gui_settings *settings); - void write_settings (void); + void read_settings (); + void init_terminal_size (); + void set_window_layout (); + void write_settings (); - void copyClipboard (void); - void pasteClipboard (void); - void selectAll (void); + void copyClipboard (); + void pasteClipboard (); + void selectAll (); void handle_gui_status_update (const QString& feature, const QString& status); - void focus_console_after_command (void); + void focus_console_after_command (); - void profiler_session (void); - void profiler_session_resume (void); - void profiler_stop (void); + void profiler_session (); + void profiler_session_resume (); + void profiler_stop (); void handle_profiler_status_update (bool); - void profiler_show (void); + void profiler_show (); void handle_octave_ready (); - void handle_set_path_dialog_request (void); + void handle_set_path_dialog_request (); //! Find files dialog. //!@{ @@ -230,13 +231,13 @@ //! Handling the clipboard. //!@{ - void clipboard_has_changed (void); + void clipboard_has_changed (); void clear_clipboard (); //!@} //! Returns a list of dock widgets. - QList get_dock_widget_list (void) + QList get_dock_widget_list () { return dock_widget_list (); } @@ -244,7 +245,7 @@ private slots: void disable_menu_shortcuts (bool disable); - void restore_create_file_setting (void); + void restore_create_file_setting (); void set_file_encoding (const QString& new_encoding); void request_open_files (const QStringList& open_file_names); @@ -256,28 +257,28 @@ private: - void adopt_dock_widgets (void); + void adopt_dock_widgets (); - void adopt_terminal_widget (void); - void adopt_documentation_widget (void); - void adopt_file_browser_widget (void); - void adopt_history_widget (void); - void adopt_workspace_widget (void); - void adopt_editor_widget (void); - void adopt_variable_editor_widget (void); + void adopt_terminal_widget (); + void adopt_documentation_widget (); + void adopt_file_browser_widget (); + void adopt_history_widget (); + void adopt_workspace_widget (); + void adopt_editor_widget (); + void adopt_variable_editor_widget (); - void construct_central_widget (void); + void construct_central_widget (); - void construct (void); + void construct (); - void construct_octave_qt_link (void); + void construct_octave_qt_link (); QAction * add_action (QMenu *menu, const QIcon& icon, const QString& text, const char *member, const QWidget *receiver = nullptr); QMenu * m_add_menu (QMenuBar *p, QString text); - void construct_menu_bar (void); + void construct_menu_bar (); void construct_file_menu (QMenuBar *p); void construct_new_menu (QMenu *p); void construct_edit_menu (QMenuBar *p); @@ -293,15 +294,15 @@ void construct_news_menu (QMenuBar *p); - void construct_tool_bar (void); + void construct_tool_bar (); - void configure_shortcuts (void); + void configure_shortcuts (); - QList dock_widget_list (void); + QList dock_widget_list (); void update_default_encoding (const QString& default_encoding); - void set_default_geometry (void); + void set_default_geometry (); void resize_dock (QDockWidget *dw, int width, int height); base_qobject& m_octave_qobj; @@ -403,8 +404,8 @@ //! For Toolbars. //!@{ QComboBox *m_current_directory_combo_box; - static const int current_directory_max_visible = 16; - static const int current_directory_max_count = 16; + static const int CURRENT_DIRECTORY_MAX_VISIBLE = 16; + static const int CURRENT_DIRECTORY_MAX_COUNT = 16; QLineEdit *m_current_directory_line_edit; //!@} diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/module.mk --- a/libgui/src/module.mk Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/module.mk Fri May 12 08:03:14 2023 +0200 @@ -301,8 +301,7 @@ %reldir%/moc-color-picker.cc \ %reldir%/moc-tab-bar.cc \ %reldir%/moc-qt-interpreter-events.cc \ - %reldir%/moc-resource-manager.cc \ - %reldir%/moc-shortcut-manager.cc \ + %reldir%/moc-shortcuts-tree-widget.cc \ %reldir%/moc-welcome-wizard.cc \ %reldir%/moc-workspace-model.cc \ %reldir%/moc-workspace-view.cc \ @@ -378,14 +377,12 @@ %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 \ %reldir%/release-notes.h \ - %reldir%/resource-manager.h \ %reldir%/settings-dialog.h \ - %reldir%/shortcut-manager.h \ + %reldir%/shortcuts-tree-widget.h \ %reldir%/tab-bar.h \ %reldir%/terminal-dock-widget.h \ %reldir%/color-picker.h \ @@ -412,6 +409,23 @@ %reldir%/external-editor-interface.cc \ %reldir%/files-dock-widget.cc \ %reldir%/graphics-init.cc \ + %reldir%/gui-preferences-cs.cc \ + %reldir%/gui-preferences-dc.cc \ + %reldir%/gui-preferences-dw.cc \ + %reldir%/gui-preferences-ed.cc \ + %reldir%/gui-preferences-fb.cc \ + %reldir%/gui-preferences-ff.cc \ + %reldir%/gui-preferences-global.cc \ + %reldir%/gui-preferences-gp.cc \ + %reldir%/gui-preferences-hw.cc \ + %reldir%/gui-preferences-mw.cc \ + %reldir%/gui-preferences-nr.cc \ + %reldir%/gui-preferences-pd.cc \ + %reldir%/gui-preferences-sc.cc \ + %reldir%/gui-preferences-sd.cc \ + %reldir%/gui-preferences-ve.cc \ + %reldir%/gui-preferences-ws.cc \ + %reldir%/gui-preferences.cc \ %reldir%/gui-settings.cc \ %reldir%/history-dock-widget.cc \ %reldir%/interpreter-qobject.cc \ @@ -429,9 +443,8 @@ %reldir%/qt-interpreter-events.cc \ %reldir%/qt-application.cc \ %reldir%/release-notes.cc \ - %reldir%/resource-manager.cc \ %reldir%/settings-dialog.cc \ - %reldir%/shortcut-manager.cc \ + %reldir%/shortcuts-tree-widget.cc \ %reldir%/tab-bar.cc \ %reldir%/terminal-dock-widget.cc \ %reldir%/color-picker.cc \ diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/news-reader.cc --- a/libgui/src/news-reader.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/news-reader.cc Fri May 12 08:03:14 2023 +0200 @@ -33,15 +33,15 @@ #include #include "news-reader.h" -#include "octave-qobject.h" #include "gui-preferences-nr.h" +#include "gui-settings.h" #include "url-transfer.h" #include "version.h" OCTAVE_BEGIN_NAMESPACE(octave) -void news_reader::process (void) +void news_reader::process () { QString html_text; @@ -68,16 +68,12 @@ { if (m_serial >= 0) { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); + gui_settings settings; - if (settings) - { - settings->setValue (nr_last_time.key, - QDateTime::currentDateTime ()); + settings.setValue (nr_last_time.settings_key (), + QDateTime::currentDateTime ()); - settings->sync (); - } + settings.sync (); QString tag ("community-news-page-serial="); @@ -95,13 +91,8 @@ if (curr_page_serial > m_serial) { - if (settings) - { - settings->setValue (nr_last_news.key, - curr_page_serial); - - settings->sync (); - } + settings.setValue (nr_last_news.settings_key (), curr_page_serial); + settings.sync (); } else return; diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/news-reader.h --- a/libgui/src/news-reader.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/news-reader.h Fri May 12 08:03:14 2023 +0200 @@ -31,18 +31,15 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; - class news_reader : public QObject { Q_OBJECT public: - news_reader (base_qobject& oct_qobj, const QString& base_url, - const QString& page, int serial = -1, - bool connect_to_web = false) - : QObject (), m_octave_qobj (oct_qobj), m_base_url (base_url), + news_reader (const QString& base_url, const QString& page, + int serial = -1, bool connect_to_web = false) + : QObject (), m_base_url (base_url), m_page (page), m_serial (serial), m_connect_to_web (connect_to_web) { } @@ -50,16 +47,14 @@ void display_news_signal (const QString& news); - void finished (void); + void finished (); public slots: - void process (void); + void process (); private: - base_qobject& m_octave_qobj; - QString m_base_url; QString m_page; int m_serial; diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/octave-dock-widget.cc --- a/libgui/src/octave-dock-widget.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/octave-dock-widget.cc Fri May 12 08:03:14 2023 +0200 @@ -45,13 +45,12 @@ #include "gui-utils.h" #include "main-window.h" #include "octave-dock-widget.h" -#include "octave-qobject.h" OCTAVE_BEGIN_NAMESPACE(octave) -label_dock_widget::label_dock_widget (QWidget *p, base_qobject& oct_qobj) -: QDockWidget (p), m_octave_qobj (oct_qobj), - m_default_float_button (nullptr), m_default_close_button (nullptr) +label_dock_widget::label_dock_widget (QWidget *p) + : QDockWidget (p), m_default_float_button (nullptr), + m_default_close_button (nullptr) { QStyle *st = style (); m_icon_size = 0.75*st->pixelMetric (QStyle::PM_SmallIconSize); @@ -73,13 +72,13 @@ } } - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); + gui_settings settings; // the custom (extra) title bar of the widget m_title_widget = new QWidget (); m_dock_action = new QAction - (rmgr.icon ("widget-undock", true), "", this); + (settings.icon ("widget-undock", true), "", this); m_dock_action->setToolTip (tr ("Undock widget")); m_dock_button = new QToolButton (m_title_widget); m_dock_button->setDefaultAction (m_dock_action); @@ -87,7 +86,7 @@ m_dock_button->setIconSize (QSize (m_icon_size, m_icon_size)); m_close_action = new QAction - (rmgr.icon ("widget-close", true), "", this); + (settings.icon ("widget-close", true), "", this); m_close_action->setToolTip (tr ("Close widget")); m_close_button = new QToolButton (m_title_widget); m_close_button->setDefaultAction (m_close_action); @@ -184,14 +183,13 @@ " top: 3px;\n" "}\n" ).arg (close_icon).arg (float_icon).arg (icon_size) - .arg (close_tooltip).arg (float_tooltip) - .arg (titlebar_foreground).arg (titlebar_background) - .arg ((icon_size*2)/3).arg((icon_size*7)/3); + .arg (close_tooltip).arg (float_tooltip) + .arg (titlebar_foreground).arg (titlebar_background) + .arg ((icon_size*2)/3).arg((icon_size*7)/3); } -octave_dock_widget::octave_dock_widget (const QString& obj_name, QWidget *p, - base_qobject& oct_qobj) - : label_dock_widget (p, oct_qobj), m_adopted (false), +octave_dock_widget::octave_dock_widget (const QString& obj_name, QWidget *p) + : label_dock_widget (p), m_main_window (nullptr), m_adopted (false), m_custom_style (false), m_focus_follows_mouse (false), m_recent_float_geom (), m_recent_dock_geom (), m_waiting_for_mouse_button_release (false) @@ -219,14 +217,15 @@ connect (this, &octave_dock_widget::queue_make_widget, this, [=] () { make_widget (); }, Qt::QueuedConnection); - shortcut_manager& scmgr = m_octave_qobj.get_shortcut_manager (); - scmgr.set_shortcut (m_dock_action, sc_dock_widget_dock); + gui_settings settings; + + settings.set_shortcut (m_dock_action, sc_dock_widget_dock); m_dock_action->setShortcutContext (Qt::WidgetWithChildrenShortcut); addAction (m_dock_action); connect (m_dock_action, &QAction::triggered, this, &octave_dock_widget::make_window); - scmgr.set_shortcut (m_close_action, sc_dock_widget_close); + settings.set_shortcut (m_close_action, sc_dock_widget_close); m_close_action->setShortcutContext (Qt::WidgetWithChildrenShortcut); addAction (m_close_action); connect (m_close_action, &QAction::triggered, @@ -234,17 +233,14 @@ m_close_action->setToolTip (tr ("Hide widget")); - setStyleSheet (qdockwidget_css ( - global_icon_paths.at (ICON_THEME_OCTAVE) + "widget-close.png", - QString ("Close widget"), - global_icon_paths.at (ICON_THEME_OCTAVE) + "widget-undock.png", - QString ("Undock widget"), - m_icon_size, - QString (""), - QString (""))); + setStyleSheet (qdockwidget_css + (global_icon_paths.at (ICON_THEME_OCTAVE) + "widget-close.png", + QString ("Close widget"), + global_icon_paths.at (ICON_THEME_OCTAVE) + "widget-undock.png", + QString ("Undock widget"), m_icon_size, "", "")); if (widget ()) - widget ()->setToolTip (QString ("")); + widget ()->setToolTip (""); m_icon_color = ""; m_title_3d = 50; @@ -257,12 +253,11 @@ | QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable); - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - handle_settings (rmgr.get_settings ()); + handle_settings (); } void -octave_dock_widget::init_window_menu_entry (void) +octave_dock_widget::init_window_menu_entry () { emit active_changed (isVisible ()); // emit once for init of window menu } @@ -303,7 +298,7 @@ // the window outside the main window if (! widget_was_dragged) geom = m_recent_float_geom.isNull () ? QRect (50,100,480,480) - : m_recent_float_geom; + : m_recent_float_geom; setGeometry (geom); // adjust the (un)dock action @@ -314,8 +309,9 @@ // adjust the (un)dock icon if (titleBarWidget ()) { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - m_dock_action->setIcon (rmgr.icon ("widget-dock" + m_icon_color, true)); + gui_settings settings; + + m_dock_action->setIcon (settings.icon ("widget-dock" + m_icon_color, true)); m_dock_action->setToolTip (tr ("Dock widget")); } else @@ -342,15 +338,15 @@ void octave_dock_widget::make_widget (bool) { + gui_settings settings; + bool vis = isVisible (); // Since floating widget has no parent, we have to read it - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); if (m_main_window) { - settings->setValue (mw_state.key, m_main_window->saveState ()); + settings.setValue (mw_state.settings_key (), m_main_window->saveState ()); // Stay window, otherwise will bounce back to window by default // because there is no layout information for this widget in the @@ -359,7 +355,7 @@ m_main_window->addDockWidget (Qt::BottomDockWidgetArea, this); m_adopted = false; // recover old window states, hide and re-show new added widget - m_main_window->restoreState (settings->value (mw_state.key).toByteArray ()); + m_main_window->restoreState (settings.value (mw_state.settings_key ()).toByteArray ()); setFloating (false); // restore size using setGeometry instead of restoreGeometry // following this post: @@ -373,7 +369,7 @@ this, &octave_dock_widget::make_window); if (titleBarWidget ()) { - m_dock_action->setIcon (rmgr.icon ("widget-undock" + m_icon_color, true)); + m_dock_action->setIcon (settings.icon ("widget-undock" + m_icon_color, true)); m_dock_action->setToolTip (tr ("Undock widget")); } else @@ -442,7 +438,7 @@ // get focus widget QWidget * -octave_dock_widget::focusWidget (void) +octave_dock_widget::focusWidget () { QWidget *w = QApplication::focusWidget (); if (w && w->focusProxy ()) w = w->focusProxy (); @@ -471,28 +467,24 @@ } void -octave_dock_widget::handle_settings (const gui_settings *settings) +octave_dock_widget::handle_settings () { - if (! settings) - return; + gui_settings settings; - m_focus_follows_mouse = settings->value (dw_focus_follows_mouse).toBool (); + m_focus_follows_mouse = settings.bool_value (dw_focus_follows_mouse); m_custom_style - = settings->value (dw_title_custom_style).toBool (); + = settings.bool_value (dw_title_custom_style); - m_title_3d = settings->value (dw_title_3d.key, dw_title_3d.def).toInt (); + m_title_3d = settings.int_value (dw_title_3d); - m_fg_color - = settings->value (dw_title_fg_color).value (); + m_fg_color = settings.color_value (dw_title_fg_color); - m_fg_color_active - = settings->value (dw_title_fg_color_active).value (); + m_fg_color_active = settings.color_value (dw_title_fg_color_active); - m_bg_color = settings->value (dw_title_bg_color).value (); + m_bg_color = settings.color_value (dw_title_bg_color); - m_bg_color_active - = settings->value (dw_title_bg_color_active).value (); + m_bg_color_active = settings.color_value (dw_title_bg_color_active); QColor bcol (m_bg_color); QColor bcola (m_bg_color_active); @@ -534,7 +526,7 @@ } m_recent_float_geom - = settings->value (dw_float_geometry.key.arg (objectName ()), + = settings.value (dw_float_geometry.settings_key ().arg (objectName ()), default_floating_size).toRect (); adjust_to_screen (m_recent_float_geom, default_floating_size); @@ -543,14 +535,14 @@ // saveGeomety to new QRect setting (see comment for restoring size // of docked widgets) QVariant dock_geom - = settings->value (dw_dock_geometry.key.arg (objectName ()), - default_dock_size); + = settings.value (dw_dock_geometry.settings_key ().arg (objectName ()), + default_dock_size); if (dock_geom.canConvert (QMetaType::QRect)) m_recent_dock_geom = dock_geom.toRect (); else - m_recent_dock_geom = dw_dock_geometry.def.toRect (); + m_recent_dock_geom = dw_dock_geometry.def ().toRect (); - notice_settings (settings); // call individual handler + notice_settings (); // call individual handler set_style (false); @@ -583,29 +575,26 @@ } void -octave_dock_widget::save_settings (void) +octave_dock_widget::save_settings () { + gui_settings settings; + // save state of this dock-widget QString name = objectName (); - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - - if (! settings) - return; store_geometry (); // conditional needed? if (! m_recent_float_geom.isNull ()) - settings->setValue (dw_float_geometry.key.arg (name), m_recent_float_geom); + settings.setValue (dw_float_geometry.settings_key ().arg (name), m_recent_float_geom); if (! m_recent_dock_geom.isEmpty ()) - settings->setValue (dw_dock_geometry.key.arg (name), m_recent_dock_geom); - settings->setValue (dw_is_visible.key.arg (name), isVisible ()); // store visibility - settings->setValue (dw_is_floating.key.arg (name), isFloating ()); // store floating - settings->setValue (dw_is_minimized.key.arg (name), isMinimized ()); // store minimized + settings.setValue (dw_dock_geometry.settings_key ().arg (name), m_recent_dock_geom); + settings.setValue (dw_is_visible.settings_key ().arg (name), isVisible ()); // store visibility + settings.setValue (dw_is_floating.settings_key ().arg (name), isFloating ()); // store floating + settings.setValue (dw_is_minimized.settings_key ().arg (name), isMinimized ()); // store minimized - settings->sync (); + settings.sync (); } bool octave_dock_widget::eventFilter (QObject *obj, QEvent *e) @@ -627,7 +616,7 @@ } void -octave_dock_widget::store_geometry (void) +octave_dock_widget::store_geometry () { if (isFloating ()) { @@ -664,7 +653,7 @@ emit active_changed (false); } -void octave_dock_widget::activate (void) +void octave_dock_widget::activate () { if (! isVisible ()) setVisible (true); @@ -795,21 +784,22 @@ } else { - css_foreground = QString (""); - css_background = QString (""); + css_foreground = ""; + css_background = ""; } QString full_dock_icon = dock_icon + icon_col; QString full_close_icon = "widget-close" + icon_col; if (titleBarWidget ()) { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); + gui_settings settings; + titleBarWidget ()->setStyleSheet (css_foreground + css_background); css_button = QString ("QToolButton {background: transparent; border: 0px;}"); m_dock_button->setStyleSheet (css_button); m_close_button->setStyleSheet (css_button); - m_dock_action->setIcon (rmgr.icon (full_dock_icon, true)); - m_close_action->setIcon (rmgr.icon (full_close_icon, true)); + m_dock_action->setIcon (settings.icon (full_dock_icon, true)); + m_close_action->setIcon (settings.icon (full_close_icon, true)); } else { @@ -825,34 +815,13 @@ // set focus to previously active widget in tabbed widget stack void -octave_dock_widget::set_focus_predecessor (void) +octave_dock_widget::set_focus_predecessor () { // only != 0 if widget was tabbed if (m_predecessor_widget && m_predecessor_widget->isVisible ()) m_predecessor_widget->setFocus (); m_predecessor_widget = nullptr; - - // FIXME: Until cset bda0c5b38bda, the wrong keys "Dockwidget/..." were used - // here. This had no effect in Qt4, but does in Qt5. In the following, the - // four incorrect keys are updated if still present in the settings files. - // The keys are also used in the settings dialog, but - // octave_dock_widget::handle_settings is already called at program start. - // These tests can be removed in a future version of Octave (version 6). - - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - - rmgr.update_settings_key ("Dockwidgets/title_bg_color", - dw_title_bg_color.key); - - rmgr.update_settings_key ("Dockwidgets/title_bg_color_active", - dw_title_bg_color_active.key); - - rmgr.update_settings_key ("Dockwidgets/title_fg_color", - dw_title_fg_color.key); - - rmgr.update_settings_key ("Dockwidgets/title_fg_color_active", - dw_title_fg_color_active.key); } OCTAVE_END_NAMESPACE(octave) diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/octave-dock-widget.h --- a/libgui/src/octave-dock-widget.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/octave-dock-widget.h Fri May 12 08:03:14 2023 +0200 @@ -31,12 +31,10 @@ #include #include -#include "gui-settings.h" #include "qt-interpreter-events.h" OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; class main_window; // The few decoration items common to both main window and variable editor. @@ -47,9 +45,9 @@ public: - label_dock_widget (QWidget *p, base_qobject& oct_qobj); + label_dock_widget (QWidget *p); - ~label_dock_widget (void) = default; + ~label_dock_widget () = default; // set_title() uses the custom title bar while setWindowTitle() uses // the default title bar (with style sheets) @@ -59,19 +57,17 @@ //! Slots to handle copy & paste. //!@{ - virtual void copyClipboard (void) { } - virtual void pasteClipboard (void) { } - virtual void selectAll (void) { } + virtual void copyClipboard () { } + virtual void pasteClipboard () { } + virtual void selectAll () { } //!@} //! Slot to handle undo. - virtual void do_undo (void) { } + virtual void do_undo () { } protected: - base_qobject& m_octave_qobj; - int m_icon_size; QWidget *m_title_widget; QToolButton *m_dock_button; @@ -89,17 +85,16 @@ public: - octave_dock_widget (const QString& obj_name, QWidget *p, - base_qobject& oct_qobj); + octave_dock_widget (const QString& obj_name, QWidget *p); - ~octave_dock_widget (void) = default; + ~octave_dock_widget () = default; void set_predecessor_widget (octave_dock_widget *prev_widget); void set_main_window (main_window *mw); void set_adopted (bool adopted = true) { m_adopted = adopted; } - bool adopted (void) const { return m_adopted; } + bool adopted () const { return m_adopted; } signals: @@ -110,29 +105,29 @@ void queue_make_window (bool widget_was_dragged); - void queue_make_widget (void); + void queue_make_widget (); protected: virtual void closeEvent (QCloseEvent *e); - QWidget * focusWidget (void); + QWidget * focusWidget (); bool event (QEvent *event); public slots: - virtual void activate (void); + virtual void activate (); virtual void handle_visibility (bool visible); - virtual void notice_settings (const gui_settings *) { } + virtual void notice_settings () { } - virtual void save_settings (void); + virtual void save_settings (); - void init_window_menu_entry (void); + void init_window_menu_entry (); - void handle_settings (const gui_settings *); + void handle_settings (); void handle_active_dock_changed (octave_dock_widget *, octave_dock_widget *); @@ -161,8 +156,10 @@ private: void set_style (bool active); - void set_focus_predecessor (void); - void store_geometry (void); + void set_focus_predecessor (); + void store_geometry (); + +private: //! Stores the parent, since we are reparenting to 0. diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/octave-qobject.cc --- a/libgui/src/octave-qobject.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/octave-qobject.cc Fri May 12 08:03:14 2023 +0200 @@ -32,7 +32,9 @@ #include #include #include -#include +#if ! defined (Q_OS_WIN32) +# include +#endif #include #include #include @@ -46,6 +48,7 @@ #include "community-news.h" #include "documentation-dock-widget.h" #include "files-dock-widget.h" +#include "gui-settings.h" #include "history-dock-widget.h" #include "interpreter-qobject.h" #include "main-window.h" @@ -53,8 +56,6 @@ #include "qt-application.h" #include "qt-interpreter-events.h" #include "release-notes.h" -#include "resource-manager.h" -#include "shortcut-manager.h" #include "terminal-dock-widget.h" #include "variable-editor.h" #include "workspace-model.h" @@ -74,7 +75,7 @@ // Bug #55940 (Disable App Nap on Mac) #if defined (Q_OS_MAC) -static void disable_app_nap (void) +static void disable_app_nap () { Class process_info_class; SEL process_info_selector; @@ -149,11 +150,11 @@ catch (execution_exception& ee) { emit interpreter_event - ([=] (void) - { - // INTERPRETER THREAD - throw ee; - }); + ([=] () + { + // INTERPRETER THREAD + throw ee; + }); } return false; @@ -174,8 +175,6 @@ m_argc (m_app_context.sys_argc ()), m_argv (m_app_context.sys_argv ()), m_qapplication (new octave_qapplication (m_argc, m_argv)), - m_resource_manager (), - m_shortcut_manager (*this), m_qt_tr (new QTranslator ()), m_gui_tr (new QTranslator ()), m_qsci_tr (new QTranslator ()), @@ -194,24 +193,18 @@ m_variable_editor_widget (), m_main_window (nullptr) { - std::string show_gui_msgs = - sys::env::getenv ("OCTAVE_SHOW_GUI_MESSAGES"); + std::string show_gui_msgs = sys::env::getenv ("OCTAVE_SHOW_GUI_MESSAGES"); // Installing our handler suppresses the messages. if (show_gui_msgs.empty ()) qInstallMessageHandler (message_handler); +#if ! defined (Q_OS_WIN32) // Set the codec for all strings (before wizard or any GUI object) -#if ! defined (Q_OS_WIN32) QTextCodec::setCodecForLocale (QTextCodec::codecForName ("UTF-8")); #endif - // Initialize global Qt application metadata. - - QCoreApplication::setApplicationName ("GNU Octave"); - QCoreApplication::setApplicationVersion (OCTAVE_VERSION); - // Register octave_value_list for connecting thread crossing signals. qRegisterMetaType ("octave_value_list"); @@ -221,6 +214,9 @@ // Mac App Nap feature causes pause() and sleep() to misbehave. // Disable it for the entire program run. disable_app_nap (); + + // Don't let Qt interpret CMD key ("Meta" in Qt terminology) as Ctrl. + QCoreApplication::setAttribute (Qt::AA_MacDontSwapCtrlAndMeta, true); #endif // Force left-to-right alignment (see bug #46204) @@ -310,14 +306,14 @@ else { // Get settings file. - m_resource_manager.reload_settings (); + gui_settings settings; + + settings.reload (); // After settings. config_translators (); - m_resource_manager.config_icon_theme (); - // Initilize the shortcut-manager - m_shortcut_manager.init_data (); + settings.config_icon_theme (); m_qapplication->setQuitOnLastWindowClosed (false); } @@ -326,7 +322,7 @@ start_main_thread (); } -base_qobject::~base_qobject (void) +base_qobject::~base_qobject () { // Note that we don't delete m_main_thread here. That is handled by // deleteLater slot that is called when the m_main_thread issues a @@ -389,12 +385,14 @@ string_vector::delete_c_str_vec (m_argv); } -void base_qobject::config_translators (void) +void base_qobject::config_translators () { if (m_translators_installed) return; - m_resource_manager.config_translators (m_qt_tr, m_qsci_tr, m_gui_tr); + gui_settings settings; + + settings.config_translators (m_qt_tr, m_qsci_tr, m_gui_tr); m_qapplication->installTranslator (m_qt_tr); m_qapplication->installTranslator (m_gui_tr); @@ -403,7 +401,7 @@ m_translators_installed = true; } -void base_qobject::start_main_thread (void) +void base_qobject::start_main_thread () { // Note: if using the new experimental terminal widget, we defer // initializing and executing the interpreter until the main event @@ -413,14 +411,14 @@ // the interpreter until after the main window and QApplication are // running to prevent race conditions. - QTimer::singleShot (0, m_interpreter_qobj, SLOT (execute (void))); + QTimer::singleShot (0, m_interpreter_qobj, SLOT (execute ())); m_interpreter_qobj->moveToThread (m_main_thread); m_main_thread->start (); } -int base_qobject::exec (void) +int base_qobject::exec () { int status = m_qapplication->exec (); @@ -437,12 +435,12 @@ // Provided for convenience. Will be removed once we eliminate the // old terminal widget. -bool base_qobject::experimental_terminal_widget (void) const +bool base_qobject::experimental_terminal_widget () const { return m_app_context.experimental_terminal_widget (); } -bool base_qobject::gui_running (void) const +bool base_qobject::gui_running () const { return m_app_context.gui_running (); } @@ -457,9 +455,12 @@ } else if (! m_terminal_widget) { + bool etw = m_app_context.experimental_terminal_widget (); + m_terminal_widget - = QPointer (new terminal_dock_widget (mw, *this)); - if (experimental_terminal_widget ()) + = QPointer (new terminal_dock_widget (mw, etw)); + + if (etw) { #if defined (HAVE_QSCINTILLA) command_widget *cmd_widget @@ -483,6 +484,9 @@ connect (qt_link (), &qt_interpreter_events::new_command_line_signal, m_terminal_widget, &terminal_dock_widget::new_command_line_signal); + connect (mw, &main_window::update_prompt_signal, + m_terminal_widget, &terminal_dock_widget::update_prompt_signal); + connect_interpreter_events (cmd_widget); #endif } @@ -493,6 +497,8 @@ // Connect the interrupt signal (emitted by Ctrl-C) connect (cmd_widget, &QTerminal::interrupt_signal, this, &base_qobject::interpreter_interrupt); + + connect_interpreter_events (cmd_widget); } } @@ -510,7 +516,7 @@ else if (! m_documentation_widget) { m_documentation_widget - = QPointer (new documentation_dock_widget (mw, *this)); + = QPointer (new documentation_dock_widget (mw)); connect (qt_link (), &qt_interpreter_events::register_documentation_signal, @@ -536,7 +542,7 @@ } else if (! m_file_browser_widget) m_file_browser_widget - = QPointer (new files_dock_widget (mw, *this)); + = QPointer (new files_dock_widget (mw)); connect (qt_link (), &qt_interpreter_events::directory_changed_signal, m_file_browser_widget, &files_dock_widget::update_octave_directory); @@ -555,7 +561,7 @@ else if (! m_history_widget) { m_history_widget - = QPointer (new history_dock_widget (mw, *this)); + = QPointer (new history_dock_widget (mw)); connect (qt_link (), &qt_interpreter_events::set_history_signal, m_history_widget, &history_dock_widget::set_history); @@ -590,7 +596,7 @@ else if (! m_workspace_widget) { m_workspace_widget - = QPointer (new workspace_view (mw, *this)); + = QPointer (new workspace_view (mw)); m_workspace_widget->setModel (m_workspace_model); @@ -608,23 +614,23 @@ [=] (const QString& var_name) { emit interpreter_event ([=] (interpreter& interp) - { - // INTERPRETER THREAD + { + // INTERPRETER THREAD - octave_value val = interp.varval (var_name.toStdString ()); + octave_value val = interp.varval (var_name.toStdString ()); - if (val.is_undefined ()) - val = 0; + if (val.is_undefined ()) + val = 0; - std::ostringstream buf; - val.print_raw (buf, true); + std::ostringstream buf; + val.print_raw (buf, true); - // FIXME: is the following operation thread safe or should - // it be done with a signal/slot connection? + // FIXME: is the following operation thread safe or should + // it be done with a signal/slot connection? - QClipboard *clipboard = QApplication::clipboard (); - clipboard->setText (QString::fromStdString (buf.str ())); - }); + QClipboard *clipboard = QApplication::clipboard (); + clipboard->setText (QString::fromStdString (buf.str ())); + }); }); connect (m_workspace_widget, &workspace_view::rename_variable_signal, @@ -683,16 +689,6 @@ QPointer base_qobject::editor_widget (main_window */*mw*/) { -#if 0 - if (m_editor_widget && mw) - { - m_editor_widget->set_main_window (mw); - m_editor_widget->set_adopted (true); - } - else if (! m_editor_widget) - m_editor_widget = new file_editor (mw, *this); -#endif - return m_editor_widget; } @@ -707,7 +703,7 @@ else if (! m_variable_editor_widget) { m_variable_editor_widget - = QPointer (new variable_editor (mw, *this)); + = QPointer (new variable_editor (mw)); connect (m_variable_editor_widget, &variable_editor::updated, this, &base_qobject::handle_variable_editor_update); @@ -729,20 +725,20 @@ { if (! m_community_news) m_community_news - = QPointer (new community_news (*this, serial)); + = QPointer (new community_news (serial)); return m_community_news; } -QPointer base_qobject::release_notes_widget (void) +QPointer base_qobject::release_notes_widget () { if (! m_release_notes) - m_release_notes = QPointer (new release_notes (*this)); + m_release_notes = QPointer (new release_notes ()); return m_release_notes; } -bool base_qobject::confirm_shutdown (void) +bool base_qobject::confirm_shutdown () { // Currently, we forward to main_window::confirm_shutdown instead of // just displaying a dialog box here because the main_window also @@ -795,7 +791,7 @@ } } -void base_qobject::show_terminal_window (void) +void base_qobject::show_terminal_window () { terminal_dock_widget *widget = (m_terminal_widget @@ -823,7 +819,7 @@ } } -void base_qobject::show_file_browser_window (void) +void base_qobject::show_file_browser_window () { files_dock_widget *widget = m_file_browser_widget ? m_file_browser_widget : file_browser_widget (); @@ -835,7 +831,7 @@ } } -void base_qobject::show_command_history_window (void) +void base_qobject::show_command_history_window () { history_dock_widget *widget = m_history_widget ? m_history_widget : history_widget (); @@ -847,7 +843,7 @@ } } -void base_qobject::show_workspace_window (void) +void base_qobject::show_workspace_window () { workspace_view *widget = m_workspace_widget ? m_workspace_widget : workspace_widget (); @@ -876,7 +872,7 @@ widget->edit_variable (name, value); } -void base_qobject::handle_variable_editor_update (void) +void base_qobject::handle_variable_editor_update () { // Called when the variable editor emits the updated signal. The size // of a variable may have changed, so we refresh the workspace in the @@ -885,15 +881,15 @@ interpreter_event ([] (interpreter& interp) - { - // INTERPRETER THREAD + { + // INTERPRETER THREAD - tree_evaluator& tw = interp.get_evaluator (); + tree_evaluator& tw = interp.get_evaluator (); - event_manager& xevmgr = interp.get_event_manager (); + event_manager& xevmgr = interp.get_event_manager (); - xevmgr.set_workspace (true, tw.get_symbol_info (), false); - }); + xevmgr.set_workspace (true, tw.get_symbol_info (), false); + }); } void base_qobject::show_community_news (int serial) @@ -904,7 +900,7 @@ m_community_news->display (); } -void base_qobject::show_release_notes (void) +void base_qobject::show_release_notes () { // Ensure widget exists. release_notes_widget (); @@ -930,7 +926,7 @@ }); } -void base_qobject::close_gui (void) +void base_qobject::close_gui () { if (m_app_context.experimental_terminal_widget ()) { @@ -964,7 +960,7 @@ } } -void base_qobject::interpreter_ready (void) +void base_qobject::interpreter_ready () { m_interpreter_ready = true; } @@ -993,7 +989,7 @@ m_interpreter_qobj->interpreter_event (meth); } -void base_qobject::interpreter_interrupt (void) +void base_qobject::interpreter_interrupt () { m_interpreter_qobj->interrupt (); } @@ -1001,19 +997,19 @@ // FIXME: Should we try to make the pause, stop, and resume actions // work for both the old and new terminal widget? -void base_qobject::interpreter_pause (void) +void base_qobject::interpreter_pause () { if (m_app_context.experimental_terminal_widget ()) m_interpreter_qobj->pause (); } -void base_qobject::interpreter_stop (void) +void base_qobject::interpreter_stop () { if (m_app_context.experimental_terminal_widget ()) m_interpreter_qobj->stop (); } -void base_qobject::interpreter_resume (void) +void base_qobject::interpreter_resume () { if (m_app_context.experimental_terminal_widget ()) m_interpreter_qobj->resume (); diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/octave-qobject.h --- a/libgui/src/octave-qobject.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/octave-qobject.h Fri May 12 08:03:14 2023 +0200 @@ -31,12 +31,11 @@ #include #include #include +#include #include #include #include "interpreter-qobject.h" -#include "resource-manager.h" -#include "shortcut-manager.h" OCTAVE_BEGIN_NAMESPACE(octave) @@ -65,7 +64,7 @@ virtual bool notify (QObject *receiver, QEvent *e) override; - ~octave_qapplication (void) { }; + ~octave_qapplication () { }; signals: @@ -105,63 +104,53 @@ // experimental terminal widget. base_qobject (qt_application& app_context, bool gui_app = false); - ~base_qobject (void); + ~base_qobject (); - void config_translators (void); + void config_translators (); - void start_main_thread (void); + void start_main_thread (); - int exec (void); + int exec (); // The Octave application context. - qt_application& app_context (void) { return m_app_context; } + qt_application& app_context () { return m_app_context; } // The Qt QApplication. - QApplication * qapplication (void) { return m_qapplication; }; + QApplication * qapplication () { return m_qapplication; }; // Provided for convenience. Will be removed once we eliminate the // old terminal widget. - bool experimental_terminal_widget (void) const; + bool experimental_terminal_widget () const; // Provided for convenience. - bool gui_running (void) const; + bool gui_running () const; - bool have_terminal_window (void) const + bool have_terminal_window () const { return ! m_terminal_widget.isNull (); } - main_window * get_main_window (void) + main_window * get_main_window () { return m_main_window; } - resource_manager& get_resource_manager (void) - { - return m_resource_manager; - } - - shortcut_manager& get_shortcut_manager (void) - { - return m_shortcut_manager; - } - - std::shared_ptr get_qt_interpreter_events (void) + std::shared_ptr get_qt_interpreter_events () { return m_qt_interpreter_events; } - qt_interpreter_events * qt_link (void) + qt_interpreter_events * qt_link () { return m_qt_interpreter_events.get (); } - interpreter_qobject * interpreter_qobj (void) + interpreter_qobject * interpreter_qobj () { return m_interpreter_qobj; } - workspace_model * get_workspace_model (void) + workspace_model * get_workspace_model () { return m_workspace_model; } @@ -192,16 +181,16 @@ QPointer community_news_widget (int serial = -1); - QPointer release_notes_widget (void); + QPointer release_notes_widget (); - QThread * main_thread (void) { return m_main_thread; } + QThread * main_thread () { return m_main_thread; } // Declared virtual so that a derived class may redefine this // method. - virtual bool confirm_shutdown (void); + virtual bool confirm_shutdown (); - bool is_gui_app (void) const { return m_gui_app; } + bool is_gui_app () const { return m_gui_app; } template void connect_interpreter_events (T *widget) { @@ -219,40 +208,40 @@ // Note: START_GUI and CLOSE_GUI don't currently perform any work // with the old terminal widget. void start_gui (bool gui_app); - void close_gui (void); + void close_gui (); - void show_terminal_window (void); + void show_terminal_window (); void show_documentation_window (const QString& file); - void show_file_browser_window (void); + void show_file_browser_window (); - void show_command_history_window (void); + void show_command_history_window (); - void show_workspace_window (void); + void show_workspace_window (); void show_variable_editor_window (const QString& name, const octave_value& value); - void handle_variable_editor_update (void); + void handle_variable_editor_update (); void show_community_news (int serial); - void show_release_notes (void); + void show_release_notes (); - void interpreter_ready (void); + void interpreter_ready (); void interpreter_event (const fcn_callback& fcn); void interpreter_event (const meth_callback& meth); - void interpreter_interrupt (void); + void interpreter_interrupt (); // Note: these currently only work with the new experimental // terminal widget. - void interpreter_pause (void); - void interpreter_stop (void); - void interpreter_resume (void); + void interpreter_pause (); + void interpreter_stop (); + void interpreter_resume (); void copy_image_to_clipboard (const QString& file, bool remove_file); @@ -268,10 +257,6 @@ octave_qapplication *m_qapplication; - resource_manager m_resource_manager; - - shortcut_manager m_shortcut_manager; - QTranslator *m_qt_tr; QTranslator *m_gui_tr; QTranslator *m_qsci_tr; diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/octave-qtutils.h --- a/libgui/src/octave-qtutils.h Fri May 12 08:00:41 2023 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,82 +0,0 @@ -//////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2021-2023 The Octave Project Developers -// -// See the file COPYRIGHT.md in the top-level directory of this -// distribution or . -// -// 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 -// . -// -//////////////////////////////////////////////////////////////////////// - -#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 -struct QNonConstOverload -{ - template - constexpr auto operator()(R (T::*ptr)(Args...)) const noexcept -> decltype(ptr) - { return ptr; } - - template - static constexpr auto of(R (T::*ptr)(Args...)) noexcept -> decltype(ptr) - { return ptr; } -}; - -template -struct QConstOverload -{ - template - constexpr auto operator()(R (T::*ptr)(Args...) const) const noexcept -> decltype(ptr) - { return ptr; } - - template - static constexpr auto of(R (T::*ptr)(Args...) const) noexcept -> decltype(ptr) - { return ptr; } -}; - -template -struct QOverload : QConstOverload, QNonConstOverload -{ - using QConstOverload::of; - using QConstOverload::operator(); - using QNonConstOverload::of; - using QNonConstOverload::operator(); - - template - constexpr auto operator()(R (*ptr)(Args...)) const noexcept -> decltype(ptr) - { return ptr; } - - template - static constexpr auto of(R (*ptr)(Args...)) noexcept -> decltype(ptr) - { return ptr; } -}; - -#endif - -#endif diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/qt-application.cc --- a/libgui/src/qt-application.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/qt-application.cc Fri May 12 08:03:14 2023 +0200 @@ -27,6 +27,10 @@ # include "config.h" #endif +#include +#include +#include + #include "main-window.h" #include "octave-qobject.h" #include "qt-application.h" @@ -42,14 +46,39 @@ OCTAVE_BEGIN_NAMESPACE(octave) +qt_application::qt_application (const std::string& organization_name, + const std::string& application_name, + const std::string& application_version, + int argc, char **argv) + : application (argc, argv) +{ + if (! organization_name.empty ()) + QCoreApplication::setOrganizationName + (QString::fromStdString (organization_name)); + + if (! application_name.empty ()) + QCoreApplication::setApplicationName + (QString::fromStdString (application_name)); + + if (! application_version.empty ()) + QCoreApplication::setApplicationVersion + (QString::fromStdString (application_version)); + + // FIXME: Is there a better place for this? + QSettings::setDefaultFormat (QSettings::IniFormat); + + // This should probably happen early. + sysdep_init (); +} + qt_application::qt_application (int argc, char **argv) -: application (argc, argv) + : application (argc, argv) { // This should probably happen early. sysdep_init (); } -bool qt_application::start_gui_p (void) const +bool qt_application::start_gui_p () const { // Note: this function is not needed if using the experimental // terminal widget, so return a dummy value of false in that case. @@ -57,7 +86,7 @@ return experimental_terminal_widget () ? false : m_options.gui (); } -int qt_application::execute (void) +int qt_application::execute () { octave_block_interrupt_signal (); diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/qt-application.h --- a/libgui/src/qt-application.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/qt-application.h Fri May 12 08:03:14 2023 +0200 @@ -26,6 +26,10 @@ #if ! defined (octave_qt_application_h) #define octave_qt_application_h 1 +#include "octave-config.h" + +#include + #include "octave.h" OCTAVE_BEGIN_NAMESPACE(octave) @@ -41,29 +45,30 @@ //! allows Qt graphics to be used or it may start an interface that //! provides the full GUI experience. - class OCTGUI_API qt_application : public application +class OCTGUI_API qt_application : public application { - public: +public: + + qt_application (const std::string& organization_name, + const std::string& application_name, + const std::string& application_version, + int argc, char **argv); qt_application (int argc, char **argv); - // No copying, at least not yet. - - qt_application (const qt_application&) = delete; + OCTAVE_DISABLE_COPY_MOVE (qt_application) - qt_application& operator = (const qt_application&) = delete; - - ~qt_application (void) = default; + ~qt_application () = default; // Should we start the GUI or fall back to the CLI? - bool start_gui_p (void) const; + bool start_gui_p () const; - int execute (void); + int execute (); - bool gui_running (void) const { return m_gui_running; } + bool gui_running () const { return m_gui_running; } void gui_running (bool arg) { m_gui_running = arg; } - private: +private: // If TRUE, the GUI should be started. bool m_gui_running = false; diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/qt-interpreter-events.cc --- a/libgui/src/qt-interpreter-events.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/qt-interpreter-events.cc Fri May 12 08:03:14 2023 +0200 @@ -35,10 +35,12 @@ #include #include #include +#include #include #include "dialog.h" #include "gui-preferences-ed.h" +#include "gui-settings.h" #include "octave-qobject.h" #include "qt-interpreter-events.h" #include "qt-utils.h" @@ -92,7 +94,7 @@ // Strip out extensions from name and replace ';' with spaces in list. - name.replace (QRegExp (R"(\(.*\))"), ""); + name.replace (QRegularExpression {R"(\(.*\))"}, ""); ext.replace (";", " "); if (name.isEmpty ()) @@ -109,7 +111,7 @@ qt_interpreter_events::qt_interpreter_events (base_qobject& oct_qobj) : interpreter_events (), m_octave_qobj (oct_qobj), - m_uiwidget_creator (oct_qobj), m_result (), m_mutex (), + m_uiwidget_creator (), m_result (), m_mutex (), m_waitcondition () { qRegisterMetaType ("QIntList"); @@ -137,7 +139,7 @@ emit start_gui_signal (gui_app); } -void qt_interpreter_events::close_gui (void) +void qt_interpreter_events::close_gui () { if (m_octave_qobj.experimental_terminal_widget ()) emit close_gui_signal (); @@ -244,22 +246,22 @@ return answer.toStdString (); } -void qt_interpreter_events::update_path_dialog (void) +void qt_interpreter_events::update_path_dialog () { emit update_path_dialog_signal (); } -void qt_interpreter_events::show_preferences (void) +void qt_interpreter_events::show_preferences () { emit show_preferences_signal (); } -void qt_interpreter_events::apply_preferences (void) +void qt_interpreter_events::apply_preferences () { emit apply_new_settings (); } -void qt_interpreter_events::show_terminal_window (void) +void qt_interpreter_events::show_terminal_window () { emit show_terminal_window_signal (); } @@ -271,17 +273,17 @@ return true; } -void qt_interpreter_events::show_file_browser (void) +void qt_interpreter_events::show_file_browser () { emit show_file_browser_signal (); } -void qt_interpreter_events::show_command_history (void) +void qt_interpreter_events::show_command_history () { emit show_command_history_signal (); } -void qt_interpreter_events::show_workspace (void) +void qt_interpreter_events::show_workspace () { emit show_workspace_signal (); } @@ -291,7 +293,7 @@ emit show_community_news_signal (serial); } -void qt_interpreter_events::show_release_notes (void) +void qt_interpreter_events::show_release_notes () { emit show_release_notes_signal (); } @@ -309,7 +311,7 @@ emit edit_variable_signal (QString::fromStdString (expr), val); } -bool qt_interpreter_events::confirm_shutdown (void) +bool qt_interpreter_events::confirm_shutdown () { QMutexLocker autolock (&m_mutex); @@ -323,10 +325,9 @@ bool qt_interpreter_events::prompt_new_edit_file (const std::string& file) { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); + gui_settings settings; - if (! settings || settings->value (ed_create_new_file).toBool ()) + if (settings.bool_value (ed_create_new_file)) return true; std::string abs_fname = sys::env::make_absolute (file); @@ -438,8 +439,9 @@ { QMutexLocker autolock (&m_mutex); - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - m_result = QVariant::fromValue (rmgr.icon (name)); + gui_settings settings; + + m_result = QVariant::fromValue (settings.icon (name)); wake_all (); } @@ -533,7 +535,7 @@ QString::fromStdString (status)); } -void qt_interpreter_events::update_gui_lexer (void) +void qt_interpreter_events::update_gui_lexer () { emit update_gui_lexer_signal (true); } @@ -574,7 +576,7 @@ emit refresh_variable_editor_signal (); } -void qt_interpreter_events::clear_workspace (void) +void qt_interpreter_events::clear_workspace () { emit clear_workspace_signal (); } @@ -599,15 +601,15 @@ emit append_history_signal (QString::fromStdString (hist_entry)); } -void qt_interpreter_events::clear_history (void) +void qt_interpreter_events::clear_history () { emit clear_history_signal (); } -void qt_interpreter_events::pre_input_event (void) +void qt_interpreter_events::pre_input_event () { } -void qt_interpreter_events::post_input_event (void) +void qt_interpreter_events::post_input_event () { } void qt_interpreter_events::enter_debugger_event (const std::string& /*fcn_name*/, @@ -629,7 +631,7 @@ delete_debugger_pointer (file, line); } -void qt_interpreter_events::exit_debugger_event (void) +void qt_interpreter_events::exit_debugger_event () { emit exit_debugger_signal (); } @@ -660,7 +662,7 @@ } void -qt_interpreter_events::confirm_shutdown_octave (void) +qt_interpreter_events::confirm_shutdown_octave () { QMutexLocker autolock (&m_mutex); @@ -684,10 +686,10 @@ { QMutexLocker autolock (&m_mutex); - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); + gui_settings settings; - QString read_value = settings->value (key).toString (); + // We don't want to apply default value here. + QString read_value = settings.value (key).toString (); // Some preferences need extra handling QString adjusted_value = gui_preference_adjust (key, value); @@ -695,9 +697,9 @@ if (! adjusted_value.isEmpty () && (read_value != adjusted_value)) { // Change settings only for new, non-empty values - settings->setValue (key, QVariant (adjusted_value)); + settings.setValue (key, QVariant (adjusted_value)); - emit settings_changed (settings, true); // true: changed by worker + emit settings_changed (true); // true: changed by worker } m_result = read_value; @@ -716,35 +718,15 @@ QString adjusted_value = value; - // Not all encodings are available. Encodings are uppercase and do - // not use CPxxx but IBMxxx or WINDOWS-xxx. - - if (key == ed_default_enc.key) + if (key == ed_default_enc.settings_key ()) { adjusted_value = adjusted_value.toUpper (); - QStringList codecs; - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - rmgr.get_codecs (&codecs); - - QRegExp re ("^CP(\\d+)$"); - if (adjusted_value == "SYSTEM") adjusted_value = QString ("SYSTEM (") + QString (octave_locale_charset_wrapper ()).toUpper () + QString (")"); - else if (re.indexIn (adjusted_value) > -1) - { - if (codecs.contains ("IBM" + re.cap (1))) - adjusted_value = "IBM" + re.cap (1); - else if (codecs.contains ("WINDOWS-" + re.cap (1))) - adjusted_value = "WINDOWS-" + re.cap (1); - else - adjusted_value.clear (); - } - else if (! codecs.contains (adjusted_value)) - adjusted_value.clear (); } return adjusted_value; diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/qt-interpreter-events.h --- a/libgui/src/qt-interpreter-events.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/qt-interpreter-events.h Fri May 12 08:03:14 2023 +0200 @@ -26,6 +26,8 @@ #if ! defined (octave_qt_interpreter_events_h) #define octave_qt_interpreter_events_h 1 +#include "octave-config.h" + #include #include @@ -36,7 +38,6 @@ #include #include "dialog.h" -#include "gui-settings.h" #include "event-manager.h" @@ -73,20 +74,16 @@ qt_interpreter_events (base_qobject& oct_qobj); - // No copying! - - qt_interpreter_events (const qt_interpreter_events&) = delete; + OCTAVE_DISABLE_COPY_MOVE (qt_interpreter_events) - qt_interpreter_events& operator = (const qt_interpreter_events&) = delete; - - ~qt_interpreter_events (void) = default; + ~qt_interpreter_events () = default; // Note: these functions currently do nothing with the old terminal // widget. void start_gui (bool gui_app = false); - void close_gui (void); + void close_gui (); - bool have_dialogs (void) const { return true; } + bool have_dialogs () const { return true; } std::list file_dialog (const filter_list& filter, const std::string& title, @@ -113,30 +110,30 @@ const std::string& btn1, const std::string& btn2, const std::string& btn3, const std::string& btndef); - void update_path_dialog (void); + void update_path_dialog (); - void show_preferences (void); + void show_preferences (); - void apply_preferences (void); + void apply_preferences (); - void show_terminal_window (void); + void show_terminal_window (); bool show_documentation (const std::string& file); - void show_file_browser (void); + void show_file_browser (); - void show_command_history (void); + void show_command_history (); - void show_workspace (void); + void show_workspace (); void show_community_news (int serial); - void show_release_notes (void); + void show_release_notes (); bool edit_file (const std::string& file); void edit_variable (const std::string& name, const octave_value& val); - bool confirm_shutdown (void); + bool confirm_shutdown (); bool prompt_new_edit_file (const std::string& file); @@ -167,7 +164,7 @@ void gui_status_update (const std::string& feature, const std::string& status); - void update_gui_lexer (void); + void update_gui_lexer (); void directory_changed (const std::string& dir); @@ -180,7 +177,7 @@ const symbol_info_list& syminfo, bool update_variable_editor); - void clear_workspace (void); + void clear_workspace (); void update_prompt (const std::string& prompt); @@ -188,33 +185,33 @@ void append_history (const std::string& hist_entry); - void clear_history (void); + void clear_history (); - void pre_input_event (void); + void pre_input_event (); - void post_input_event (void); + void post_input_event (); void enter_debugger_event (const std::string& fcn_name, const std::string& fcn_file_name, int line); void execute_in_debugger_event (const std::string& file, int line); - void exit_debugger_event (void); + void exit_debugger_event (); void update_breakpoint (bool insert, const std::string& file, int line, const std::string& cond); - void lock (void) { m_mutex.lock (); } + void lock () { m_mutex.lock (); } - void wait (void) { m_waitcondition.wait (&m_mutex); } + void wait () { m_waitcondition.wait (&m_mutex); } - void unlock (void) { m_mutex.unlock (); } + void unlock () { m_mutex.unlock (); } - void wake_all (void) { m_waitcondition.wakeAll (); } + void wake_all () { m_waitcondition.wakeAll (); } public slots: - void confirm_shutdown_octave (void); + void confirm_shutdown_octave (); void get_named_icon_slot (const QString& name); @@ -224,7 +221,7 @@ // Note: these signals are not currently used by the old terminal widget. void start_gui_signal (bool gui_app); - void close_gui_signal (void); + void close_gui_signal (); void copy_image_to_clipboard_signal (const QString& file, bool remove_file); @@ -234,7 +231,7 @@ void directory_changed_signal (const QString& dir); - void update_path_dialog_signal (void); + void update_path_dialog_signal (); void file_remove_signal (const QString& old_name, const QString& new_name); @@ -245,7 +242,7 @@ void set_workspace_signal (bool top_level, bool debug, const symbol_info_list& syminfo); - void clear_workspace_signal (void); + void clear_workspace_signal (); void update_prompt_signal (const QString& prompt); @@ -253,11 +250,11 @@ void append_history_signal (const QString& hist_entry); - void clear_history_signal (void); + void clear_history_signal (); - void enter_debugger_signal (void); + void enter_debugger_signal (); - void exit_debugger_signal (void); + void exit_debugger_signal (); void update_breakpoint_marker_signal (bool insert, const QString& file, int line, const QString& cond); @@ -266,11 +263,11 @@ void delete_debugger_pointer_signal (const QString&, int); - void show_preferences_signal (void); + void show_preferences_signal (); void gui_preference_signal (const QString& key, const QString& value); - void show_terminal_window_signal (void); + void show_terminal_window_signal (); void show_documentation_signal (const QString& file); @@ -278,14 +275,14 @@ void unregister_documentation_signal (const QString& file); - void show_file_browser_signal (void); + void show_file_browser_signal (); - void show_command_history_signal (void); + void show_command_history_signal (); - void show_workspace_signal (void); + void show_workspace_signal (); void show_community_news_signal (int serial); - void show_release_notes_signal (void); + void show_release_notes_signal (); // Note: the next two signals are currently not used by the old terminal widget. void interpreter_output_signal (const QString& msg); @@ -297,15 +294,15 @@ void edit_variable_signal (const QString& name, const octave_value& val); - void refresh_variable_editor_signal (void); + void refresh_variable_editor_signal (); - void confirm_shutdown_signal (void); + void confirm_shutdown_signal (); void get_named_icon_signal (const QString& name); - void settings_changed (const gui_settings *, bool); + void settings_changed (bool); - void apply_new_settings (void); + void apply_new_settings (); private: diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/release-notes.cc --- a/libgui/src/release-notes.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/release-notes.cc Fri May 12 08:03:14 2023 +0200 @@ -40,25 +40,25 @@ #include "gui-utils.h" #include "gui-preferences-dw.h" #include "gui-preferences-nr.h" +#include "gui-settings.h" #include "news-reader.h" -#include "octave-qobject.h" #include "defaults.h" OCTAVE_BEGIN_NAMESPACE(octave) -release_notes::release_notes (base_qobject& oct_qobj) -: QWidget (nullptr), m_browser (nullptr) +release_notes::release_notes () + : QWidget (nullptr), m_browser (nullptr) { - resource_manager& rmgr = oct_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); + gui_settings settings; // The icon - QString icon_set = settings->value (dw_icon_set).toString (); + QString icon_set = settings.string_value (dw_icon_set); + if (icon_set != "NONE") m_release_notes_icon = dw_icon_set_names[icon_set] - + "ReleaseWidget.png"; + + "ReleaseWidget.png"; else m_release_notes_icon = dw_icon_set_names[icon_set]; @@ -106,7 +106,7 @@ move (20, 20); // move to the top left corner } -void release_notes::display (void) +void release_notes::display () { if (! isVisible ()) show (); diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/release-notes.h --- a/libgui/src/release-notes.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/release-notes.h Fri May 12 08:03:14 2023 +0200 @@ -33,21 +33,19 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; - class release_notes : public QWidget { Q_OBJECT public: - release_notes (base_qobject& qct_qobj); + release_notes (); - ~release_notes (void) = default; + ~release_notes () = default; public slots: - void display (void); + void display (); private: diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/resource-manager.cc --- a/libgui/src/resource-manager.cc Fri May 12 08:00:41 2023 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,794 +0,0 @@ -//////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2011-2023 The Octave Project Developers -// -// See the file COPYRIGHT.md in the top-level directory of this -// distribution or . -// -// 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 -// . -// -//////////////////////////////////////////////////////////////////////// - -#if defined (HAVE_CONFIG_H) -# include "config.h" -#endif - -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "QTerminal.h" -#include "gui-preferences-cs.h" -#include "gui-preferences-ed.h" -#include "gui-preferences-global.h" -#include "octave-qobject.h" -#include "resource-manager.h" -#include "variable-editor.h" -#include "workspace-model.h" - -#include "file-ops.h" -#include "localcharset-wrapper.h" -#include "oct-env.h" - -#include "defaults.h" -#include "error.h" -#include "help.h" - -OCTAVE_BEGIN_NAMESPACE(octave) - -resource_manager::resource_manager (void) -: m_settings_directory (), m_settings_file (), m_settings (nullptr), - m_default_settings (nullptr), m_temporary_files (), m_icon_fallbacks () -{ - // Let gui_settings decide where to put the ini file with gui preferences - m_default_settings - = new gui_settings (QSettings::IniFormat, QSettings::UserScope, - "octave", "octave-gui"); - - m_settings_file = m_default_settings->fileName (); - - QFileInfo sfile (m_settings_file); - m_settings_directory = sfile.absolutePath (); - - QString xdg_config_home - = QString::fromLocal8Bit (qgetenv ("XDG_CONFIG_HOME")); - - if ((! sfile.exists ()) && xdg_config_home.isEmpty ()) - { - // File does not exist yet: Look for a settings file at the old - // location ($HOME/.config/octave/qt-settings) for impoting all - // available keys into the new settings file. - // Do not look for an old settings file if XDG_CONFIG_HOME is set, - // since then a nonexistent new settings file does not necessarily - // indicate a first run of octave with new config file locations. -#if defined (HAVE_QSTANDARDPATHS) - QString home_path - = QStandardPaths::writableLocation (QStandardPaths::HomeLocation); -#else - QString home_path - = QDesktopServices::storageLocation (QDesktopServices::HomeLocation); -#endif - - QString old_settings_directory = home_path + "/.config/octave"; - QString old_settings_file = old_settings_directory + "/qt-settings"; - - QFile ofile (old_settings_file); - - if (ofile.exists ()) - { - // Old settings file exists; create a gui_settings object related - // to it and copy all available keys to the new settings - gui_settings old_settings (old_settings_file, QSettings::IniFormat); - - QStringList keys = old_settings.allKeys (); - for (int i = 0; i < keys.count(); i++) - m_default_settings->setValue (keys.at(i), - old_settings.value(keys.at(i))); - - m_default_settings->sync (); // Done, make sure keys are written - } - } -} - -resource_manager::~resource_manager (void) -{ - delete m_settings; - delete m_default_settings; - - for (int i = m_temporary_files.count () - 1; i >=0; i--) - remove_tmp_file (m_temporary_files.at (i)); -} - -QString resource_manager::get_gui_translation_dir (void) -{ - // get environment variable for the locale dir (e.g. from run-octave) - std::string dldir = sys::env::getenv ("OCTAVE_LOCALE_DIR"); - if (dldir.empty ()) - dldir = config::oct_locale_dir (); // env-var empty, load the default location - return QString::fromStdString (dldir); -} - -void resource_manager::config_translators (QTranslator *qt_tr, - QTranslator *qsci_tr, - QTranslator *gui_tr) -{ - bool loaded; - - QString qt_trans_dir - = QLibraryInfo::location (QLibraryInfo::TranslationsPath); - - QString language = "SYSTEM"; // take system language per default - - // FIXME: can we somehow ensure that the settings object will always - // be initialize and valid? - - if (m_settings) - { - // get the locale from the settings if already available - language = m_settings->value (global_language.key, - global_language.def).toString (); - } - - // load the translations depending on the settings - if (language == "SYSTEM") - { - // get the system locale and pass it to the translators for loading - // the suitable translation files - QLocale sys_locale = QLocale::system (); - - qt_tr->load (sys_locale, "qt", "_", qt_trans_dir); - qsci_tr->load (sys_locale, "qscintilla", "_", qt_trans_dir); - gui_tr->load (sys_locale, "", "", get_gui_translation_dir ()); - } - else - { - // load the translation files depending on the given locale name - loaded = qt_tr->load ("qt_" + language, qt_trans_dir); - if (! loaded) // try lower case - qt_tr->load ("qt_" + language.toLower (), qt_trans_dir); - - loaded = qsci_tr->load ("qscintilla_" + language, qt_trans_dir); - if (! loaded) // try lower case - qsci_tr->load ("qscintilla_" + language.toLower (), qt_trans_dir); - - gui_tr->load (language, get_gui_translation_dir ()); - } - -} - -void resource_manager::config_icon_theme (void) -{ - m_icon_fallbacks.clear (); - - int theme = global_icon_theme_index.def.toInt (); - - if (m_settings) - { - // check for new and old setting and use old if required - if (! m_settings->contains (global_icon_theme_index.key)) - { - // new pref does not exist - if (m_settings->value (global_icon_theme).toBool ()) - theme = ICON_THEME_SYSTEM; - else - theme = ICON_THEME_OCTAVE; - m_settings->setValue (global_icon_theme_index.key, theme); // add new - m_settings->remove (global_icon_theme.key); // remove deprecated key - } - else - { - // get new settings - theme = m_settings->value (global_icon_theme_index).toInt (); - } - } - - QIcon::setThemeName (global_all_icon_themes.at (theme)); - - // set the required fallback search paths - switch (theme) - { - case ICON_THEME_SYSTEM: - m_icon_fallbacks << global_icon_paths.at (ICON_THEME_OCTAVE); - m_icon_fallbacks << global_icon_paths.at (ICON_THEME_TANGO); - break; - case ICON_THEME_TANGO: - m_icon_fallbacks << global_icon_paths.at (ICON_THEME_OCTAVE); - break; - case ICON_THEME_OCTAVE: - m_icon_fallbacks << global_icon_paths.at (ICON_THEME_TANGO); - break; - } - - m_icon_fallbacks << global_icon_paths.at (ICON_THEME_CURSORS); -} - -gui_settings * resource_manager::get_settings (void) const -{ - if (! m_settings) - { - QString msg (QT_TR_NOOP ("Octave has lost its settings.\n" - "This should not happen.\n\n" - "Please report this bug.\n\n" - "Octave GUI must be closed now.")); - - QMessageBox::critical (nullptr, - QString (QT_TR_NOOP ("Octave Critical Error")), - msg); - exit (1); - } - - return m_settings; -} - -gui_settings * resource_manager::get_default_settings (void) const -{ - if (! m_default_settings) - { - QString msg (QT_TR_NOOP ("Octave has lost its default settings.\n" - "This should not happen.\n" - "Please report this bug.\n\n" - "Octave GUI must be closed now.")); - - QMessageBox::critical (nullptr, - QString (QT_TR_NOOP ("Octave Critical Error")), - msg); - exit (1); - } - - return m_default_settings; -} - -QString resource_manager::get_settings_directory (void) -{ - return m_settings_directory; -} - -QString resource_manager::get_settings_file (void) -{ - return m_settings_file; -} - -QString resource_manager::get_default_font_family (void) -{ - QString default_family; - - // Get all available fixed width fonts via a font combobox - QFontComboBox font_combo_box; - font_combo_box.setFontFilters (QFontComboBox::MonospacedFonts); - QStringList fonts; - - for (int index = 0; index < font_combo_box.count(); index++) - fonts << font_combo_box.itemText(index); - -#if defined (Q_OS_MAC) - // Use hard coded default on macOS, since selection of fixed width - // default font is unreliable (see bug #59128). - // Test for macOS default fixed width font - if (fonts.contains (global_mono_font.def.toString ())) - default_family = global_mono_font.def.toString (); -#endif - - // If default font is still empty (on all other platforms or - // if macOS default font is not available): use QFontDatabase - if (default_family.isEmpty ()) - { - // Get the system's default monospaced font - QFont fixed_font = QFontDatabase::systemFont (QFontDatabase::FixedFont); - default_family = fixed_font.defaultFamily (); - - // Since this might be unreliable, test all available fixed width fonts - if (! fonts.contains (default_family)) - { - // Font returned by QFontDatabase is not in fixed fonts list. - // Fallback: take first from this list - default_family = fonts[0]; - } - } - - // Test env variable which has preference - std::string env_default_family = sys::env::getenv ("OCTAVE_DEFAULT_FONT"); - if (! env_default_family.empty ()) - default_family = QString::fromStdString (env_default_family); - - return default_family; -} - -QStringList resource_manager::get_default_font (void) -{ - QString default_family = get_default_font_family (); - - // determine the fefault font size of the system - // FIXME: QApplication::font () does not return the monospace font, - // but the size should be probably near to the monospace font - QFont font = QApplication::font (); - - int font_size = font.pointSize (); - if (font_size == -1) - font_size = static_cast (std::floor(font.pointSizeF ())); - - // check for valid font size, otherwise take default 10 - QString default_font_size = "10"; - if (font_size > 0) - default_font_size = QString::number (font_size); - - std::string env_default_font_size - = sys::env::getenv ("OCTAVE_DEFAULT_FONT_SIZE"); - - if (! env_default_font_size.empty ()) - default_font_size = QString::fromStdString (env_default_font_size); - - QStringList result; - result << default_family; - result << default_font_size; - return result; -} - -void resource_manager::reload_settings (void) -{ - // Declare some empty options, which may be set at first startup for - // writing them into the newly created settings file - QString custom_editor; - QStringList def_font; - - // Check whether the settings file does not yet exist - if (! QFile::exists (m_settings_file)) - { - // Get the default font (for terminal) - def_font = get_default_font (); - - // Get a custom editor defined as env variable - std::string env_default_editor - = sys::env::getenv ("OCTAVE_DEFAULT_EDITOR"); - - if (! env_default_editor.empty ()) - custom_editor = QString::fromStdString (env_default_editor); - } - - set_settings (m_settings_file); - - // Write some settings that were dynamically determined at first startup - if (m_settings) - { - // Custom editor - if (! custom_editor.isEmpty ()) - m_settings->setValue (global_custom_editor.key, custom_editor); - - // Default monospace font for the terminal - if (def_font.count () > 1) - { - m_settings->setValue (cs_font.key, def_font[0]); - m_settings->setValue (cs_font_size.key, def_font[1].toInt ()); - } - - // Write the default monospace font into the settings for later use by - // console and editor as fallbacks of their font preferences. - m_settings->setValue (global_mono_font.key, get_default_font_family ()); - } -} - -#if defined (HAVE_QSCINTILLA) -int resource_manager::get_valid_lexer_styles (QsciLexer *lexer, int *styles) -{ - int max_style = 0; - int actual_style = 0; - while (actual_style < ed_max_style_number && max_style < ed_max_lexer_styles) - { - if ((lexer->description (actual_style)) != "") // valid style - styles[max_style++] = actual_style; - actual_style++; - } - return max_style; -} -#endif - -QFont resource_manager::copy_font_attributes (const QFont& attr, - const QFont& base) const -{ - QFont dest (base); - - dest.setBold (attr.bold ()); - dest.setItalic (attr.italic ()); - dest.setUnderline (attr.underline ()); - - return dest; -} - -#if defined (HAVE_QSCINTILLA) -void resource_manager::read_lexer_settings (QsciLexer *lexer, - gui_settings *settings, - int mode, int def) -{ - // Test whether the settings for lexer is already contained in the - // given gui settings file. If yes, load them, if not copy them from the - // default settings file. - // This is useful when a new language support is implemented and the - // existing settings file is used (which is of course the common case). - int m = mode; - if (m > 1) - m = 1; - - QString group ("Scintilla" + settings_color_modes_ext[m]); - - settings->beginGroup (group); - settings->beginGroup (lexer->language ()); - - QStringList lexer_keys = settings->allKeys (); - - settings->endGroup (); - settings->endGroup (); - - if (def == settings_reload_default_colors_flag || lexer_keys.count () == 0) - { - // We have to reload the default values or no Lexer keys found: - // If mode == 0, take all settings except font from default lexer - // If Mode == 1, take all settings except font from default lexer - // and convert the color by inverting the lightness - - // Get the default font - QStringList def_font = get_default_font (); - QFont df (def_font[0], def_font[1].toInt ()); - QFont dfa = copy_font_attributes (lexer->defaultFont (), df); - lexer->setDefaultFont (dfa); - - QColor c, p; - - int styles[ed_max_lexer_styles]; // array for saving valid styles - int max_style = get_valid_lexer_styles (lexer, styles); - - for (int i = 0; i < max_style; i++) - { - c = settings->get_color_value (QVariant (lexer->color (styles[i])), m); - lexer->setColor (c, styles[i]); - p = settings->get_color_value (QVariant (lexer->paper (styles[i])), m); - lexer->setPaper (p, styles[i]); - dfa = copy_font_attributes (lexer->font (styles[i]), df); - lexer->setFont (dfa, styles[i]); - } - // Set defaults last for not changing the defaults of the styles - lexer->setDefaultColor (lexer->color (styles[0])); - lexer->setDefaultPaper (lexer->paper (styles[0])); - - // Write settings if not just reload the default values - if (def != settings_reload_default_colors_flag) - { - const std::string group_str = group.toStdString (); - lexer->writeSettings (*settings, group_str.c_str ()); - settings->sync (); - } - } - else - { - // Found lexer keys, read the settings - const std::string group_str = group.toStdString (); - lexer->readSettings (*settings, group_str.c_str ()); - } -} -#endif - -void resource_manager::set_settings (const QString& file) -{ - delete m_settings; - m_settings = new gui_settings (file, QSettings::IniFormat); - - if (m_settings->status () == QSettings::NoError) - { - // Test usability (force file to be really created) - m_settings->setValue ("dummy", 0); - m_settings->sync (); - } - - if (! (QFile::exists (m_settings->fileName ()) - && m_settings->isWritable () - && m_settings->status () == QSettings::NoError)) - { - QString msg - = QString (QT_TR_NOOP ("The settings file\n%1\n" - "does not exist and can not be created.\n" - "Make sure you have read and write permissions to\n%2\n\n" - "Octave GUI must be closed now.")); - - QMessageBox::critical (nullptr, - QString (QT_TR_NOOP ("Octave Critical Error")), - msg.arg (get_settings_file ()).arg (get_settings_directory ())); - - exit (1); - } - else - m_settings->remove ("dummy"); // Remove test entry -} - -bool resource_manager::update_settings_key (const QString& old_key, - const QString& new_key) -{ - if (m_settings->contains (old_key)) - { - QVariant preference = m_settings->value (old_key); - m_settings->setValue (new_key, preference); - m_settings->remove (old_key); - return true; - } - - return false; -} - -bool resource_manager::is_first_run (void) const -{ - return ! QFile::exists (m_settings_file); -} - -void resource_manager::update_network_settings (void) -{ - if (! m_settings) - return; - - QNetworkProxy proxy; - - // Assume no proxy and empty proxy data - QNetworkProxy::ProxyType proxy_type = QNetworkProxy::NoProxy; - QString scheme; - QString host; - int port = 0; - QString user; - QString pass; - QUrl proxy_url = QUrl (); - - if (m_settings->value (global_use_proxy.key, global_use_proxy.def).toBool ()) - { - // Use a proxy, collect all required information - QString proxy_type_string - = m_settings->value (global_proxy_type.key, global_proxy_type.def).toString (); - - // The proxy type for the Qt proxy settings - if (proxy_type_string == "Socks5Proxy") - proxy_type = QNetworkProxy::Socks5Proxy; - else if (proxy_type_string == "HttpProxy") - proxy_type = QNetworkProxy::HttpProxy; - - // The proxy data from the settings - if (proxy_type_string == "HttpProxy" - || proxy_type_string == "Socks5Proxy") - { - host = m_settings->value (global_proxy_host.key, - global_proxy_host.def).toString (); - port = m_settings->value (global_proxy_port.key, - global_proxy_port.def).toInt (); - user = m_settings->value (global_proxy_user.key, - global_proxy_user.def).toString (); - pass = m_settings->value (global_proxy_pass.key, - global_proxy_pass.def).toString (); - if (proxy_type_string == "HttpProxy") - scheme = "http"; - else if (proxy_type_string == "Socks5Proxy") - scheme = "socks5"; - - QUrl env_var_url = QUrl (); - proxy_url.setScheme (scheme); - proxy_url.setHost (host); - proxy_url.setPort (port); - if (! user.isEmpty ()) - proxy_url.setUserName (user); - if (! pass.isEmpty ()) - proxy_url.setPassword (pass); - } - - // The proxy data from environment variables - if (proxy_type_string == global_proxy_all_types.at (2)) - { - const std::array env_vars = - { - "ALL_PROXY", "all_proxy", - "HTTP_PROXY", "http_proxy", - "HTTPS_PROXY", "https_proxy" - }; - - unsigned int count = 0; - while (! proxy_url.isValid () && count < env_vars.size ()) - { - proxy_url = QUrl (QString::fromStdString - (sys::env::getenv (env_vars[count]))); - count++; - } - - if (proxy_url.isValid ()) - { - // Found an entry, get the data from the string - scheme = proxy_url.scheme (); - - if (scheme.contains ("socks", Qt::CaseInsensitive)) - proxy_type = QNetworkProxy::Socks5Proxy; - else - proxy_type = QNetworkProxy::HttpProxy; - - host = proxy_url.host (); - port = proxy_url.port (); - user = proxy_url.userName (); - pass = proxy_url.password (); - } - } - } - - // Set proxy for Qt framework - proxy.setType (proxy_type); - proxy.setHostName (host); - proxy.setPort (port); - proxy.setUser (user); - proxy.setPassword (pass); - - QNetworkProxy::setApplicationProxy (proxy); - - // Set proxy for curl library if not based on environment variables - std::string proxy_url_str = proxy_url.toString().toStdString (); - sys::env::putenv ("http_proxy", proxy_url_str); - sys::env::putenv ("HTTP_PROXY", proxy_url_str); - sys::env::putenv ("https_proxy", proxy_url_str); - sys::env::putenv ("HTTPS_PROXY", proxy_url_str); -} - -QIcon resource_manager::icon (const QString& icon_name, bool octave_only, - const QString& icon_alt_name) -{ - if (octave_only) - return QIcon (global_icon_paths.at (ICON_THEME_OCTAVE) + icon_name + ".png"); - - if (QIcon::hasThemeIcon (icon_name)) - return QIcon (QIcon::fromTheme (icon_name)); - else if ((! icon_alt_name.isEmpty ()) && QIcon::hasThemeIcon (icon_alt_name)) - return QIcon (QIcon::fromTheme (icon_alt_name)); - - for (int i = 0; i < m_icon_fallbacks.length (); i++ ) - { - QString icon_file (m_icon_fallbacks.at (i) + icon_name + ".png"); - if (QFile (icon_file).exists ()) - return QIcon (icon_file); - } - - //QIcon::setThemeName (current_theme); - return QIcon (); -} - -// get a list of all available encodings -void resource_manager::get_codecs (QStringList *codecs) -{ - // get the codec name for each mib - QList all_mibs = QTextCodec::availableMibs (); - for (auto mib : all_mibs) - { - QTextCodec *c = QTextCodec::codecForMib (mib); - codecs->append (c->name ().toUpper ()); - } - - // Append SYSTEM - codecs->append (QString ("SYSTEM (") + - QString (octave_locale_charset_wrapper ()).toUpper () + - QString (")")); - - // Clean up and sort list of codecs - codecs->removeDuplicates (); - std::sort (codecs->begin (), codecs->end ()); -} - -// initialize a given combo box with available text encodings -void resource_manager::combo_encoding (QComboBox *combo, - const QString& current) -{ - QStringList all_codecs; - get_codecs (&all_codecs); - - // get the value from the settings file if no current encoding is given - QString enc = current; - - // Check for valid codec for the default. If this fails, "SYSTEM" (i.e. - // locale_charset) will be chosen. - // FIXME: The default is "SYSTEM" on all platforms. So can this fallback - // logic be removed completely? - bool default_exists = false; - bool show_system = false; - if (ed_default_enc.def.toString ().startsWith ("SYSTEM")) - show_system = true; - else if (QTextCodec::codecForName (ed_default_enc.def.toString ().toLatin1 ())) - default_exists = true; - - QString default_enc = - QString ("SYSTEM (") + - QString (octave_locale_charset_wrapper ()).toUpper () + QString (")"); - - if (enc.isEmpty ()) - { - enc = m_settings->value (ed_default_enc).toString (); - - if (enc.isEmpty ()) // still empty? - { - if (default_exists) - enc = ed_default_enc.def.toString (); - else - enc = default_enc; - } - } - - // fill the combo box - for (const auto& c : all_codecs) - combo->addItem (c); - - // prepend the default item - combo->insertSeparator (0); - if (show_system || ! default_exists) - combo->insertItem (0, default_enc); - else - combo->insertItem (0, ed_default_enc.def.toString ()); - - // select the default or the current one - int idx = combo->findText (enc, Qt::MatchExactly); - if (idx >= 0) - combo->setCurrentIndex (idx); - else - combo->setCurrentIndex (0); - - combo->setMaxVisibleItems (12); -} - -QPointer -resource_manager::create_tmp_file (const QString& extension, - const QString& contents) -{ - QString ext = extension; - if ((! ext.isEmpty ()) && (! ext.startsWith ('.'))) - ext = QString (".") + ext; - - // Create octave dir within temp. dir - QString tmp_dir = QString::fromStdString (sys::env::get_temp_directory ()); - - // Create temp. file - QPointer tmp_file - = new QTemporaryFile (tmp_dir + QDir::separator() + - "octave_XXXXXX" + ext, this); - - if (tmp_file->open ()) - { - tmp_file->write (contents.toUtf8 ()); - tmp_file->close (); - - m_temporary_files << tmp_file; - } - - return tmp_file; -} - -void resource_manager::remove_tmp_file (QPointer tmp_file) -{ - if (tmp_file) - { - if (tmp_file->exists ()) - tmp_file->remove (); - - m_temporary_files.removeAll (tmp_file); - } -} - -OCTAVE_END_NAMESPACE(octave) diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/resource-manager.h --- a/libgui/src/resource-manager.h Fri May 12 08:00:41 2023 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,133 +0,0 @@ -//////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2011-2023 The Octave Project Developers -// -// See the file COPYRIGHT.md in the top-level directory of this -// distribution or . -// -// 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 -// . -// -//////////////////////////////////////////////////////////////////////// - -#if ! defined (octave_resource_manager_h) -#define octave_resource_manager_h 1 - -#include -#include -#include -#if defined (HAVE_QSCINTILLA) -# include -#endif -#include -#include - -#include "gui-settings.h" - -OCTAVE_BEGIN_NAMESPACE(octave) - -class resource_manager : public QObject -{ - Q_OBJECT - -protected: - - public: - - resource_manager (void); - - // No copying! - - resource_manager (const resource_manager&) = delete; - - resource_manager& operator = (const resource_manager&) = delete; - - ~resource_manager (); - - QString get_gui_translation_dir (void); - - void config_translators (QTranslator *qt_tr, QTranslator *qsci_tr, - QTranslator *gui_tr); - void config_icon_theme (void); - - gui_settings * get_settings (void) const; - - gui_settings * get_default_settings (void) const; - - QString get_settings_directory (void); - - QString get_settings_file (void); - - QString get_default_font_family (void); - - QStringList get_default_font (void); - - QPointer - create_tmp_file (const QString& extension = QString (), - const QString& contents = QString ()); - - void remove_tmp_file (QPointer tmp_file); - - void reload_settings (void); - -#if defined (HAVE_QSCINTILLA) - int get_valid_lexer_styles (QsciLexer *lexer, int *styles); - void read_lexer_settings (QsciLexer *lexer, gui_settings *settings, - int mode = 0, int def = 0); -#endif - - void set_settings (const QString& file); - - bool update_settings_key (const QString& new_key, const QString& old_key); - - bool is_first_run (void) const; - - void update_network_settings (void); - - QIcon icon (const QString& icon_name, bool octave_only = false, - const QString& icon_alt_name = QString ()); - - void get_codecs (QStringList *codecs); - - void combo_encoding (QComboBox *combo, const QString& current = QString ()); - -private: - - /*! - * Copys the attributes bold, italic and underline from QFont - * @p attr to the font @p base and returns the result without - * changing @p base, - * @param attr QFont with the desired attributes - * @param base QFont with desired family and size - */ - QFont copy_font_attributes (const QFont& attr, const QFont& base) const; - - QString m_settings_directory; - - QString m_settings_file; - - gui_settings *m_settings; - - gui_settings *m_default_settings; - - QList m_temporary_files; - - QStringList m_icon_fallbacks; -}; - -OCTAVE_END_NAMESPACE(octave) - -#endif diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/set-path-dialog.cc --- a/libgui/src/set-path-dialog.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/set-path-dialog.cc Fri May 12 08:03:14 2023 +0200 @@ -50,8 +50,7 @@ #include #include "gui-preferences-pd.h" -#include "octave-qobject.h" -#include "octave-qtutils.h" +#include "gui-settings.h" #include "set-path-dialog.h" #include "set-path-model.h" @@ -59,8 +58,8 @@ OCTAVE_BEGIN_NAMESPACE(octave) -set_path_dialog::set_path_dialog (QWidget *parent, base_qobject& oct_qobj) -: QDialog (parent), m_octave_qobj (oct_qobj) +set_path_dialog::set_path_dialog (QWidget *parent) + : QDialog (parent) { setWindowTitle (tr ("Set Path")); @@ -168,13 +167,12 @@ setLayout (main_layout); - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - restoreGeometry ( - settings->value(pd_geometry.key).toByteArray()); + gui_settings settings; + + restoreGeometry (settings.value(pd_geometry.settings_key ()).toByteArray()); } -void set_path_dialog::update_model (void) +void set_path_dialog::update_model () { set_path_model *m = static_cast (m_path_list->model ()); m->path_to_model (); @@ -205,17 +203,17 @@ } } -void set_path_dialog::add_dir(void) +void set_path_dialog::add_dir() { add_dir_common (false); } -void set_path_dialog::add_dir_subdirs (void) +void set_path_dialog::add_dir_subdirs () { add_dir_common (true); } -void set_path_dialog::rm_dir (void) +void set_path_dialog::rm_dir () { set_path_model *m = static_cast (m_path_list->model ()); QItemSelectionModel *selmodel = m_path_list->selectionModel (); @@ -225,7 +223,7 @@ selmodel->clearSelection (); } -void set_path_dialog::move_dir_up (void) +void set_path_dialog::move_dir_up () { set_path_model *m = static_cast (m_path_list->model ()); QItemSelectionModel *selmodel = m_path_list->selectionModel (); @@ -245,7 +243,7 @@ m_path_list->scrollTo (m->index (min_row)); } -void set_path_dialog::move_dir_down (void) +void set_path_dialog::move_dir_down () { set_path_model *m = static_cast (m_path_list->model ()); QItemSelectionModel *selmodel = m_path_list->selectionModel (); @@ -265,7 +263,7 @@ m_path_list->scrollTo (m->index (max_row)); } -void set_path_dialog::move_dir_top (void) +void set_path_dialog::move_dir_top () { set_path_model *m = static_cast (m_path_list->model ()); QItemSelectionModel *selmodel = m_path_list->selectionModel (); @@ -280,7 +278,7 @@ m_path_list->scrollTo (m->index (0)); } -void set_path_dialog::move_dir_bottom (void) +void set_path_dialog::move_dir_bottom () { set_path_model *m = static_cast (m_path_list->model ()); QItemSelectionModel *selmodel = m_path_list->selectionModel (); @@ -299,9 +297,9 @@ void set_path_dialog::save_settings () { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - settings->setValue (pd_geometry.key, saveGeometry ()); + gui_settings settings; + + settings.setValue (pd_geometry.settings_key (), saveGeometry ()); } void set_path_dialog::closeEvent (QCloseEvent *e) diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/set-path-dialog.h --- a/libgui/src/set-path-dialog.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/set-path-dialog.h Fri May 12 08:03:14 2023 +0200 @@ -41,8 +41,6 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; - class set_path_dialog : public QDialog { Q_OBJECT @@ -53,11 +51,11 @@ // in the dialog. That may only be done after the intepreter_event // signal connections are made to the Octave interpreter. - set_path_dialog (QWidget *parent, base_qobject& oct_qobj); + set_path_dialog (QWidget *parent); - virtual ~set_path_dialog (void) = default; + virtual ~set_path_dialog () = default; - void save_settings (void); + void save_settings (); signals: @@ -71,7 +69,7 @@ public slots: - void update_model (void); + void update_model (); protected: @@ -79,25 +77,23 @@ private slots: - void add_dir (void); - void add_dir_subdirs (void); + void add_dir (); + void add_dir_subdirs (); - void rm_dir (void); + void rm_dir (); - void move_dir_up (void); + void move_dir_up (); - void move_dir_down (void); + void move_dir_down (); - void move_dir_top (void); + void move_dir_top (); - void move_dir_bottom (void); + void move_dir_bottom (); private: void add_dir_common (bool subdirs); - base_qobject& m_octave_qobj; - QLabel *m_info_label; QPushButton *m_reload_button; QPushButton *m_save_button; diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/set-path-model.cc --- a/libgui/src/set-path-model.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/set-path-model.cc Fri May 12 08:03:14 2023 +0200 @@ -54,7 +54,7 @@ m_revertible = false; } -std::string set_path_model::to_string (void) +std::string set_path_model::to_string () { std::string path_sep = directory_path::path_sep_str (); @@ -73,7 +73,7 @@ return path_str; } -void set_path_model::model_to_path (void) +void set_path_model::model_to_path () { std::string path_str = to_string (); @@ -88,7 +88,7 @@ }); } -void set_path_model::clear (void) +void set_path_model::clear () { beginResetModel (); @@ -97,7 +97,7 @@ endResetModel (); } -void set_path_model::save (void) +void set_path_model::save () { model_to_path (); @@ -110,7 +110,7 @@ }); } -void set_path_model::revert (void) +void set_path_model::revert () { clear (); @@ -121,7 +121,7 @@ model_to_path (); } -void set_path_model::revert_last (void) +void set_path_model::revert_last () { clear (); @@ -281,7 +281,7 @@ return retval; } -void set_path_model::path_to_model (void) +void set_path_model::path_to_model () { // The interpreter_event callback function below emits a signal. // Because we don't control when that happens, use a guarded pointer diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/set-path-model.h --- a/libgui/src/set-path-model.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/set-path-model.h Fri May 12 08:03:14 2023 +0200 @@ -44,9 +44,9 @@ set_path_model (QObject *p = nullptr); - ~set_path_model (void) = default; + ~set_path_model () = default; - void clear (void); + void clear (); void add_dir (const QString& p); @@ -60,11 +60,11 @@ void move_dir_bottom (const QModelIndexList& indices); - std::string to_string (void); + std::string to_string (); // Overloaded Qt methods - void model_to_path (void); + void model_to_path (); int rowCount (const QModelIndex& p = QModelIndex ()) const; @@ -79,13 +79,13 @@ public slots: - void path_to_model (void); + void path_to_model (); - void save (void); + void save (); - void revert (void); + void revert (); - void revert_last (void); + void revert_last (); private slots: diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/settings-dialog.cc --- a/libgui/src/settings-dialog.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/settings-dialog.cc Fri May 12 08:03:14 2023 +0200 @@ -39,7 +39,7 @@ #include #include #include -#include +#include #include #if defined (HAVE_QSCINTILLA) @@ -64,48 +64,69 @@ #endif #include "gui-preferences-all.h" -#include "octave-qobject.h" -#include "octave-qtutils.h" +#include "gui-settings.h" #include "settings-dialog.h" +#include "shortcuts-tree-widget.h" #include "variable-editor.h" #include "workspace-model.h" OCTAVE_BEGIN_NAMESPACE(octave) -settings_dialog::settings_dialog (QWidget *p, base_qobject& oct_qobj, - const QString& desired_tab) -: QDialog (p), Ui::settings_dialog (), m_octave_qobj (oct_qobj) +settings_dialog::settings_dialog (QWidget *p, const QString& desired_tab) + : QDialog (p), Ui::settings_dialog () { setupUi (this); - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); + QMessageBox *info = wait_message_box ( + tr ("Loading current preferences ... "), this); + + read_settings (true); // it's the first read, prepare everything + + close_wait_message_box (info); + + // which tab is the desired one? + show_tab (desired_tab); + + // connect button box signal + connect (button_box, &QDialogButtonBox::clicked, + this, &settings_dialog::button_clicked); + + // restore last geometry + gui_settings settings; - if (! settings) + if (settings.contains (sd_geometry.settings_key ())) + restoreGeometry (settings.byte_array_value (sd_geometry)); + else + setGeometry (QRect (10, 50, 1000, 600)); + + // show as non-modal dialog + setModal (false); + setAttribute (Qt::WA_DeleteOnClose); + show (); +} + +void settings_dialog::read_settings (bool first) +{ + gui_settings settings; + + if (first) { - QMessageBox msgBox - (QMessageBox::Warning, tr ("Octave Preferences"), - tr ("Unable to save preferences. Missing preferences file or unknown directory.")); + // look for available language files and the actual settings + QString qm_dir_name = settings.get_gui_translation_dir (); - msgBox.exec (); + QDir qm_dir (qm_dir_name); + QFileInfoList qm_files = qm_dir.entryInfoList (QStringList ("*.qm"), + QDir::Files | QDir::Readable, QDir::Name); - return; + for (int i = 0; i < qm_files.length (); i++) // insert available languages + comboBox_language->addItem (qm_files.at (i).baseName ()); + // System at beginning + comboBox_language->insertItem (0, tr ("System setting")); + comboBox_language->insertSeparator (1); // separator after System } - // look for available language files and the actual settings - QString qm_dir_name = rmgr.get_gui_translation_dir (); - QDir qm_dir (qm_dir_name); - QFileInfoList qm_files = qm_dir.entryInfoList (QStringList ("*.qm"), - QDir::Files | QDir::Readable, QDir::Name); - - for (int i = 0; i < qm_files.length (); i++) // insert available languages - comboBox_language->addItem (qm_files.at (i).baseName ()); - // System at beginning - comboBox_language->insertItem (0, tr ("System setting")); - comboBox_language->insertSeparator (1); // separator after System - QString language = settings->value (global_language.key, - global_language.def).toString (); - if (language == global_language.def.toString ()) + QString language = settings.string_value (global_language); + if (language == global_language.def ().toString ()) language = tr ("System setting"); int selected = comboBox_language->findText (language); if (selected >= 0) @@ -113,238 +134,249 @@ else comboBox_language->setCurrentIndex (0); // System is default - // Global style - QStringList styles = QStyleFactory::keys(); - styles.append (global_extra_styles); - combo_styles->addItems (styles); - combo_styles->insertItem (0, global_style.def.toString ()); - combo_styles->insertSeparator (1); - QString current_style = settings->value (global_style).toString (); - if (current_style == global_style.def.toString ()) - current_style = global_style.def.toString (); + if (first) + { + // Global style + QStringList styles = QStyleFactory::keys(); + styles.append (global_extra_styles); + combo_styles->addItems (styles); + combo_styles->insertItem (0, global_style.def ().toString ()); + combo_styles->insertSeparator (1); + } + + QString current_style = settings.string_value (global_style); + if (current_style == global_style.def ().toString ()) + current_style = global_style.def ().toString (); selected = combo_styles->findText (current_style); if (selected >= 0) combo_styles->setCurrentIndex (selected); else combo_styles->setCurrentIndex (0); - // icon size and theme - QButtonGroup *icon_size_group = new QButtonGroup (this); - icon_size_group->addButton (icon_size_small); - icon_size_group->addButton (icon_size_normal); - icon_size_group->addButton (icon_size_large); - int icon_size = settings->value (global_icon_size).toInt (); + if (first) + { + // icon size and theme + QButtonGroup *icon_size_group = new QButtonGroup (this); + icon_size_group->addButton (icon_size_small); + icon_size_group->addButton (icon_size_normal); + icon_size_group->addButton (icon_size_large); + } + int icon_size = settings.int_value (global_icon_size); icon_size_normal->setChecked (true); // the default icon_size_small->setChecked (icon_size < 0); icon_size_large->setChecked (icon_size > 0); - combo_box_icon_theme->addItems (global_all_icon_theme_names); - int theme = settings->value (global_icon_theme_index.key).toInt (); + + if (first) + combo_box_icon_theme->addItems (global_all_icon_theme_names); + int theme = settings.value (global_icon_theme_index.settings_key ()).toInt (); combo_box_icon_theme->setCurrentIndex (theme); - // which icon has to be selected - QButtonGroup *icon_group = new QButtonGroup (this); - icon_group->addButton (general_icon_octave); - icon_group->addButton (general_icon_graphic); - icon_group->addButton (general_icon_letter); + if (first) + { + // which icon has to be selected + QButtonGroup *icon_group = new QButtonGroup (this); + icon_group->addButton (general_icon_octave); + icon_group->addButton (general_icon_graphic); + icon_group->addButton (general_icon_letter); + } QString widget_icon_set = - settings->value (dw_icon_set).toString (); + settings.string_value (dw_icon_set); general_icon_octave->setChecked (true); // the default (if invalid set) general_icon_octave->setChecked (widget_icon_set == "NONE"); general_icon_graphic->setChecked (widget_icon_set == "GRAPHIC"); general_icon_letter->setChecked (widget_icon_set == "LETTER"); - // custom title bar of dock widget - QColor bg_color = settings->value (dw_title_bg_color).value (); - m_widget_title_bg_color = new color_picker (bg_color); - m_widget_title_bg_color->setEnabled (false); - layout_widget_bgtitle->addWidget (m_widget_title_bg_color, 0); + if (first) + { + // custom title bar of dock widget + m_widget_title_bg_color = new color_picker (); + m_widget_title_bg_color->setEnabled (false); + layout_widget_bgtitle->addWidget (m_widget_title_bg_color, 0); - connect (cb_widget_custom_style, &QCheckBox::toggled, - m_widget_title_bg_color, &color_picker::setEnabled); + connect (cb_widget_custom_style, &QCheckBox::toggled, + m_widget_title_bg_color, &color_picker::setEnabled); - QColor bg_color_active = settings->value (dw_title_bg_color_active).value (); - m_widget_title_bg_color_active = new color_picker (bg_color_active); - m_widget_title_bg_color_active->setEnabled (false); - layout_widget_bgtitle_active->addWidget (m_widget_title_bg_color_active, 0); + m_widget_title_bg_color_active = new color_picker (); + m_widget_title_bg_color_active->setEnabled (false); + layout_widget_bgtitle_active->addWidget (m_widget_title_bg_color_active, 0); - connect (cb_widget_custom_style, &QCheckBox::toggled, - m_widget_title_bg_color_active, &color_picker::setEnabled); + connect (cb_widget_custom_style, &QCheckBox::toggled, + m_widget_title_bg_color_active, &color_picker::setEnabled); - QColor fg_color = settings->value (dw_title_fg_color).value (); - m_widget_title_fg_color = new color_picker (fg_color); - m_widget_title_fg_color->setEnabled (false); - layout_widget_fgtitle->addWidget (m_widget_title_fg_color, 0); + m_widget_title_fg_color = new color_picker (); + m_widget_title_fg_color->setEnabled (false); + layout_widget_fgtitle->addWidget (m_widget_title_fg_color, 0); - connect (cb_widget_custom_style, &QCheckBox::toggled, - m_widget_title_fg_color, &color_picker::setEnabled); + connect (cb_widget_custom_style, &QCheckBox::toggled, + m_widget_title_fg_color, &color_picker::setEnabled); + + m_widget_title_fg_color_active = new color_picker (); + m_widget_title_fg_color_active->setEnabled (false); + layout_widget_fgtitle_active->addWidget (m_widget_title_fg_color_active, 0); - QColor fg_color_active = settings->value (dw_title_fg_color_active).value (); - m_widget_title_fg_color_active = new color_picker (fg_color_active); - m_widget_title_fg_color_active->setEnabled (false); - layout_widget_fgtitle_active->addWidget (m_widget_title_fg_color_active, 0); + connect (cb_widget_custom_style, &QCheckBox::toggled, + m_widget_title_fg_color_active, &color_picker::setEnabled); + } - connect (cb_widget_custom_style, &QCheckBox::toggled, - m_widget_title_fg_color_active, &color_picker::setEnabled); + m_widget_title_bg_color->set_color (settings.color_value (dw_title_bg_color)); + m_widget_title_bg_color_active->set_color (settings.color_value (dw_title_bg_color_active)); + m_widget_title_fg_color->set_color (settings.color_value (dw_title_fg_color)); + m_widget_title_fg_color_active->set_color (settings.color_value (dw_title_fg_color_active)); - sb_3d_title->setValue (settings->value (dw_title_3d.key, - dw_title_3d.def).toInt ()); - cb_widget_custom_style->setChecked (settings->value (dw_title_custom_style).toBool ()); + sb_3d_title->setValue (settings.int_value (dw_title_3d)); + cb_widget_custom_style->setChecked (settings.bool_value (dw_title_custom_style)); // Native file dialogs. // FIXME: This preference can be deprecated / removed if all display // managers, especially KDE, run those dialogs without hangs or // delays from the start (bug #54607). - cb_use_native_file_dialogs->setChecked (settings->value (global_use_native_dialogs).toBool ()); + cb_use_native_file_dialogs->setChecked (settings.bool_value (global_use_native_dialogs)); // Cursor blinking: consider old terminal related setting if not yet set // FIXME: This pref. can be deprecated / removed if Qt adds support for // getting the cursor blink preferences from all OS environments - if (settings->contains (global_cursor_blinking.key)) + if (settings.contains (global_cursor_blinking.settings_key ())) { // Preference exists, read its value - cb_cursor_blinking->setChecked (settings->value - (global_cursor_blinking.key, global_cursor_blinking.def).toBool ()); + cb_cursor_blinking->setChecked (settings.bool_value (global_cursor_blinking)); } else { // Pref. does not exist, so take old terminal related pref. - cb_cursor_blinking->setChecked (settings->value - (cs_cursor_blinking.key, cs_cursor_blinking.def).toBool ()); + cb_cursor_blinking->setChecked (settings.bool_value (cs_cursor_blinking)); } // focus follows mouse - cb_focus_follows_mouse->setChecked ( - settings->value (dw_focus_follows_mouse).toBool ()); + cb_focus_follows_mouse->setChecked (settings.bool_value (dw_focus_follows_mouse)); // prompt on exit - cb_prompt_to_exit->setChecked ( - settings->value (global_prompt_to_exit.key, global_prompt_to_exit.def).toBool ()); + cb_prompt_to_exit->setChecked (settings.bool_value (global_prompt_to_exit)); // Main status bar - cb_status_bar->setChecked ( - settings->value (global_status_bar.key, global_status_bar.def).toBool ()); + cb_status_bar->setChecked (settings.bool_value (global_status_bar)); // Octave startup - cb_restore_octave_dir->setChecked ( - settings->value (global_restore_ov_dir.key, global_restore_ov_dir.def).toBool ()); - le_octave_dir->setText (settings->value (global_ov_startup_dir.key, - global_ov_startup_dir.def).toString ()); + cb_restore_octave_dir->setChecked (settings.bool_value (global_restore_ov_dir)); + le_octave_dir->setText (settings.string_value (global_ov_startup_dir)); - connect (pb_octave_dir, &QPushButton::pressed, - this, &settings_dialog::get_octave_dir); + if (first) + connect (pb_octave_dir, &QPushButton::pressed, + this, &settings_dialog::get_octave_dir); // // editor // - useCustomFileEditor->setChecked ( - settings->value (global_use_custom_editor.key, global_use_custom_editor.def).toBool ()); - customFileEditor->setText ( - settings->value (global_custom_editor.key, global_custom_editor.def).toString ()); - editor_showLineNumbers->setChecked (settings->value (ed_show_line_numbers).toBool ()); - editor_linenr_size->setValue (settings->value (ed_line_numbers_size).toInt ()); + useCustomFileEditor->setChecked (settings.bool_value (global_use_custom_editor)); + customFileEditor->setText (settings.string_value (global_custom_editor)); + editor_showLineNumbers->setChecked (settings.bool_value (ed_show_line_numbers)); + editor_linenr_size->setValue (settings.int_value (ed_line_numbers_size)); - rmgr.combo_encoding (editor_combo_encoding); + settings.combo_encoding (editor_combo_encoding); - editor_highlightCurrentLine->setChecked (settings->value (ed_highlight_current_line).toBool ()); - editor_long_line_marker->setChecked (settings->value (ed_long_line_marker).toBool ()); + editor_highlightCurrentLine->setChecked (settings.bool_value (ed_highlight_current_line)); + editor_long_line_marker->setChecked (settings.bool_value (ed_long_line_marker)); bool long_line = - settings->value (ed_long_line_marker_line).toBool (); + settings.bool_value (ed_long_line_marker_line); editor_long_line_marker_line->setChecked (long_line); bool long_back = - settings->value (ed_long_line_marker_background).toBool (); + settings.bool_value (ed_long_line_marker_background); editor_long_line_marker_background->setChecked (long_back); if (! (long_line || long_back)) editor_long_line_marker_line->setChecked (true); - editor_long_line_column->setValue (settings->value (ed_long_line_column).toInt ()); - editor_break_checkbox->setChecked (settings->value (ed_break_lines).toBool ()); - editor_break_comments_checkbox->setChecked (settings->value (ed_break_lines_comments).toBool ()); - editor_wrap_checkbox->setChecked (settings->value (ed_wrap_lines).toBool ()); - cb_edit_status_bar->setChecked (settings->value (ed_show_edit_status_bar).toBool ()); - cb_edit_tool_bar->setChecked (settings->value (ed_show_toolbar).toBool ()); - cb_code_folding->setChecked (settings->value (ed_code_folding).toBool ()); - editor_highlight_all_occurrences->setChecked (settings->value (ed_highlight_all_occurrences).toBool ()); + editor_long_line_column->setValue (settings.int_value (ed_long_line_column)); + editor_break_checkbox->setChecked (settings.bool_value (ed_break_lines)); + editor_break_comments_checkbox->setChecked (settings.bool_value (ed_break_lines_comments)); + editor_wrap_checkbox->setChecked (settings.bool_value (ed_wrap_lines)); + cb_edit_status_bar->setChecked (settings.bool_value (ed_show_edit_status_bar)); + cb_edit_tool_bar->setChecked (settings.bool_value (ed_show_toolbar)); + cb_code_folding->setChecked (settings.bool_value (ed_code_folding)); + editor_highlight_all_occurrences->setChecked (settings.bool_value (ed_highlight_all_occurrences)); - editor_auto_endif->setCurrentIndex (settings->value (ed_auto_endif).toInt () ); - editor_codeCompletion->setChecked (settings->value (ed_code_completion).toBool ()); - editor_spinbox_ac_threshold->setValue (settings->value (ed_code_completion_threshold).toInt ()); - editor_checkbox_ac_keywords->setChecked (settings->value (ed_code_completion_keywords).toBool ()); + editor_auto_endif->setCurrentIndex (settings.int_value (ed_auto_endif) ); + editor_codeCompletion->setChecked (settings.bool_value (ed_code_completion)); + editor_spinbox_ac_threshold->setValue (settings.int_value (ed_code_completion_threshold)); + editor_checkbox_ac_keywords->setChecked (settings.bool_value (ed_code_completion_keywords)); editor_checkbox_ac_builtins->setEnabled (editor_checkbox_ac_keywords->isChecked ()); editor_checkbox_ac_functions->setEnabled (editor_checkbox_ac_keywords->isChecked ()); - editor_checkbox_ac_builtins->setChecked (settings->value (ed_code_completion_octave_builtins).toBool ()); - editor_checkbox_ac_functions->setChecked (settings->value (ed_code_completion_octave_functions).toBool ()); - editor_checkbox_ac_document->setChecked (settings->value (ed_code_completion_document).toBool ()); - editor_checkbox_ac_case->setChecked (settings->value (ed_code_completion_case).toBool ()); - editor_checkbox_ac_replace->setChecked (settings->value (ed_code_completion_replace).toBool ()); - editor_ws_checkbox->setChecked (settings->value (ed_show_white_space).toBool ()); - editor_ws_indent_checkbox->setChecked (settings->value (ed_show_white_space_indent).toBool ()); - cb_show_eol->setChecked (settings->value (ed_show_eol_chars).toBool ()); - cb_show_hscrollbar->setChecked (settings->value (ed_show_hscroll_bar).toBool ()); + editor_checkbox_ac_builtins->setChecked (settings.bool_value (ed_code_completion_octave_builtins)); + editor_checkbox_ac_functions->setChecked (settings.bool_value (ed_code_completion_octave_functions)); + editor_checkbox_ac_document->setChecked (settings.bool_value (ed_code_completion_document)); + editor_checkbox_ac_case->setChecked (settings.bool_value (ed_code_completion_case)); + editor_checkbox_ac_replace->setChecked (settings.bool_value (ed_code_completion_replace)); + editor_ws_checkbox->setChecked (settings.bool_value (ed_show_white_space)); + editor_ws_indent_checkbox->setChecked (settings.bool_value (ed_show_white_space_indent)); + cb_show_eol->setChecked (settings.bool_value (ed_show_eol_chars)); + cb_show_hscrollbar->setChecked (settings.bool_value (ed_show_hscroll_bar)); - for (int i = 0; i < ed_tab_position_names.length (); i++) - editor_combox_tab_pos->insertItem (i, - tr (ed_tab_position_names.at (i).toStdString ().data ())); - editor_combox_tab_pos->setCurrentIndex - (settings->value (ed_tab_position).toInt ()); + if (first) + { + for (int i = 0; i < ed_tab_position_names.length (); i++) + editor_combox_tab_pos->insertItem (i, + tr (ed_tab_position_names.at (i).toStdString ().data ())); + } + editor_combox_tab_pos->setCurrentIndex (settings.int_value (ed_tab_position)); - editor_cb_tabs_rotated->setChecked (settings->value (ed_tabs_rotated).toBool ()); - editor_sb_tabs_max_width->setValue (settings->value (ed_tabs_max_width).toInt ()); + editor_cb_tabs_rotated->setChecked (settings.bool_value (ed_tabs_rotated)); + editor_sb_tabs_max_width->setValue (settings.int_value (ed_tabs_max_width)); int selected_comment_string, selected_uncomment_string; - if (settings->contains (ed_comment_str.key)) // new version (radio buttons) - selected_comment_string = settings->value (ed_comment_str).toInt (); + if (settings.contains (ed_comment_str.settings_key ())) // new version (radio buttons) + selected_comment_string = settings.int_value (ed_comment_str); else // old version (combo box) - selected_comment_string = settings->value (ed_comment_str_old.key, ed_comment_str.def).toInt (); + selected_comment_string = settings.value (ed_comment_str_old.settings_key (), ed_comment_str.def ()).toInt (); - selected_uncomment_string = settings->value (ed_uncomment_str).toInt (); + selected_uncomment_string = settings.int_value (ed_uncomment_str); for (int i = 0; i < ed_comment_strings_count; i++) { - m_rb_comment_strings[i] = new QRadioButton (); - m_rb_uncomment_strings[i] = new QCheckBox (); + if (first) + { + m_rb_comment_strings[i] = new QRadioButton (); + m_rb_uncomment_strings[i] = new QCheckBox (); + layout_comment_strings->addWidget (m_rb_comment_strings[i]); + layout_uncomment_strings->addWidget (m_rb_uncomment_strings[i]); - connect (m_rb_comment_strings[i], &QRadioButton::clicked, - m_rb_uncomment_strings[i], &QCheckBox::setChecked); - connect (m_rb_comment_strings[i], &QRadioButton::toggled, - m_rb_uncomment_strings[i], &QCheckBox::setDisabled); + connect (m_rb_comment_strings[i], &QRadioButton::clicked, + m_rb_uncomment_strings[i], &QCheckBox::setChecked); + connect (m_rb_comment_strings[i], &QRadioButton::toggled, + m_rb_uncomment_strings[i], &QCheckBox::setDisabled); + } m_rb_comment_strings[i]->setText (ed_comment_strings.at(i)); m_rb_comment_strings[i]->setChecked (i == selected_comment_string); - layout_comment_strings->addWidget (m_rb_comment_strings[i]); m_rb_uncomment_strings[i]->setText (ed_comment_strings.at(i)); m_rb_uncomment_strings[i]->setAutoExclusive (false); m_rb_uncomment_strings[i]->setChecked ( 1 << i & selected_uncomment_string); - layout_uncomment_strings->addWidget (m_rb_uncomment_strings[i]); } - combo_eol_mode->setCurrentIndex (settings->value (ed_default_eol_mode).toInt ()); - editor_auto_ind_checkbox->setChecked (settings->value (ed_auto_indent).toBool ()); - editor_tab_ind_checkbox->setChecked (settings->value (ed_tab_indents_line).toBool ()); - editor_bs_unind_checkbox->setChecked (settings->value (ed_backspace_unindents_line).toBool ()); - editor_ind_guides_checkbox->setChecked (settings->value (ed_show_indent_guides).toBool ()); - editor_ind_width_spinbox->setValue (settings->value (ed_indent_width).toInt ()); - editor_ind_uses_tabs_checkbox->setChecked (settings->value (ed_indent_uses_tabs).toBool ()); - editor_tab_width_spinbox->setValue (settings->value (ed_tab_width).toInt ()); - editor_restoreSession->setChecked (settings->value (ed_restore_session).toBool ()); - editor_create_new_file->setChecked (settings->value (ed_create_new_file).toBool ()); - editor_reload_changed_files->setChecked (settings->value (ed_always_reload_changed_files).toBool ()); - editor_force_newline->setChecked (settings->value (ed_force_newline).toBool ()); - editor_remove_trailing_spaces->setChecked (settings->value (ed_rm_trailing_spaces).toBool ()); - editor_hiding_closes_files->setChecked (settings->value (ed_hiding_closes_files).toBool ()); - editor_show_dbg_file->setChecked (settings->value (ed_show_dbg_file).toBool ()); + combo_eol_mode->setCurrentIndex (settings.int_value (ed_default_eol_mode)); + editor_auto_ind_checkbox->setChecked (settings.bool_value (ed_auto_indent)); + editor_tab_ind_checkbox->setChecked (settings.bool_value (ed_tab_indents_line)); + editor_bs_unind_checkbox->setChecked (settings.bool_value (ed_backspace_unindents_line)); + editor_ind_guides_checkbox->setChecked (settings.bool_value (ed_show_indent_guides)); + editor_ind_width_spinbox->setValue (settings.int_value (ed_indent_width)); + editor_ind_uses_tabs_checkbox->setChecked (settings.bool_value (ed_indent_uses_tabs)); + editor_tab_width_spinbox->setValue (settings.int_value (ed_tab_width)); + editor_restoreSession->setChecked (settings.bool_value (ed_restore_session)); + editor_create_new_file->setChecked (settings.bool_value (ed_create_new_file)); + editor_reload_changed_files->setChecked (settings.bool_value (ed_always_reload_changed_files)); + editor_force_newline->setChecked (settings.bool_value (ed_force_newline)); + editor_remove_trailing_spaces->setChecked (settings.bool_value (ed_rm_trailing_spaces)); + editor_hiding_closes_files->setChecked (settings.bool_value (ed_hiding_closes_files)); + editor_show_dbg_file->setChecked (settings.bool_value (ed_show_dbg_file)); // terminal - QString default_font = settings->value (global_mono_font).toString (); - terminal_fontName->setCurrentFont (QFont (settings->value (cs_font.key, default_font).toString ())); - terminal_fontSize->setValue (settings->value (cs_font_size).toInt ()); - terminal_history_buffer->setValue (settings->value (cs_hist_buffer).toInt ()); - terminal_cursorUseForegroundColor->setChecked (settings->value (cs_cursor_use_fgcol).toBool ()); - terminal_focus_command->setChecked (settings->value (cs_focus_cmd).toBool ()); - terminal_print_dbg_location->setChecked (settings->value (cs_dbg_location).toBool ()); + QString default_font = settings.string_value (global_mono_font); + terminal_fontName->setCurrentFont (QFont (settings.value (cs_font.settings_key (), default_font).toString ())); + terminal_fontSize->setValue (settings.int_value (cs_font_size)); + terminal_history_buffer->setValue (settings.int_value (cs_hist_buffer)); + terminal_cursorUseForegroundColor->setChecked (settings.bool_value (cs_cursor_use_fgcol)); + terminal_focus_command->setChecked (settings.bool_value (cs_focus_cmd)); + terminal_print_dbg_location->setChecked (settings.bool_value (cs_dbg_location)); - QString cursor_type - = settings->value (cs_cursor).toString (); + QString cursor_type = settings.string_value (cs_cursor); QStringList items; items << QString ("0") << QString ("1") << QString ("2"); @@ -362,29 +394,54 @@ } } - read_terminal_colors (settings); + if (first) + read_terminal_colors (); + else + { + QCheckBox *cb_color_mode + = terminal_colors_box->findChild (cs_color_mode.settings_key ()); + bool sec_color_mode = settings.bool_value (cs_color_mode); + if (cb_color_mode->isChecked () == sec_color_mode) + { + // color mode does not change, update colors manually + update_terminal_colors (); + } + else + { + // toggling check-state calls related slot updating colors + cb_color_mode->setChecked (sec_color_mode); + } + } // file browser - connect (sync_octave_directory, &QCheckBox::toggled, - this, &settings_dialog::set_disabled_pref_file_browser_dir); - - sync_octave_directory->setChecked (settings->value (fb_sync_octdir).toBool ()); - cb_restore_file_browser_dir->setChecked (settings->value (fb_restore_last_dir).toBool ()); - le_file_browser_dir->setText (settings->value (fb_startup_dir.key).toString ()); + if (first) + { + connect (sync_octave_directory, &QCheckBox::toggled, + this, &settings_dialog::set_disabled_pref_file_browser_dir); + connect (pb_file_browser_dir, &QPushButton::pressed, + this, &settings_dialog::get_file_browser_dir); + } - connect (pb_file_browser_dir, &QPushButton::pressed, - this, &settings_dialog::get_file_browser_dir); - - le_file_browser_extensions->setText (settings->value (fb_txt_file_ext).toString ()); - - checkbox_allow_web_connect->setChecked (settings->value (nr_allow_connection).toBool ()); + sync_octave_directory->setChecked (settings.bool_value (fb_sync_octdir)); + cb_restore_file_browser_dir->setChecked (settings.bool_value (fb_restore_last_dir)); + le_file_browser_dir->setText (settings.value (fb_startup_dir.settings_key ()).toString ()); + le_file_browser_extensions->setText (settings.string_value (fb_txt_file_ext)); + checkbox_allow_web_connect->setChecked (settings.bool_value (nr_allow_connection)); // Proxy - bool use_proxy = settings->value (global_use_proxy.key, global_use_proxy.def).toBool (); + bool use_proxy = settings.bool_value (global_use_proxy); use_proxy_server->setChecked (use_proxy); // Fill combo box and activate current one - QString proxy_type_string = settings->value (global_proxy_type.key, global_proxy_type.def).toString (); - proxy_type->addItems (global_proxy_all_types); + if (first) + { + proxy_type->addItems (global_proxy_all_types); + // Connect relevant signals for dis-/enabling some elements + connect (proxy_type, QOverload::of (&QComboBox::currentIndexChanged), + this, &settings_dialog::proxy_items_update); + connect (use_proxy_server, &QCheckBox::toggled, + this, &settings_dialog::proxy_items_update); + } + QString proxy_type_string = settings.string_value (global_proxy_type); for (int i = 0; i < global_proxy_all_types.length (); i++) { if (proxy_type->itemText (i) == proxy_type_string) @@ -394,134 +451,164 @@ } } // Fill all line edits - proxy_host_name->setText (settings->value (global_proxy_host.key, global_proxy_host.def).toString ()); - proxy_port->setText (settings->value (global_proxy_port.key, global_proxy_port.def).toString ()); - proxy_username->setText (settings->value (global_proxy_user.key, global_proxy_user.def).toString ()); - proxy_password->setText (settings->value (global_proxy_pass.key, global_proxy_pass.def).toString ()); - // Connect relevant signals for dis-/enabling some elements - connect (proxy_type, QOverload::of (&QComboBox::currentIndexChanged), - this, &settings_dialog::proxy_items_update); - connect (use_proxy_server, &QCheckBox::toggled, - this, &settings_dialog::proxy_items_update); + proxy_host_name->setText (settings.string_value (global_proxy_host)); + proxy_port->setText (settings.string_value (global_proxy_port)); + proxy_username->setText (settings.string_value (global_proxy_user)); + proxy_password->setText (settings.string_value (global_proxy_pass)); // Check whehter line edits have to be enabled proxy_items_update (); // Workspace - read_workspace_colors (settings); + if (first) + read_workspace_colors (); + else + { + m_ws_enable_colors->setChecked (settings.bool_value (ws_enable_colors)); + QCheckBox *cb_color_mode + = workspace_colors_box->findChild (ws_color_mode.settings_key ()); + bool sec_color_mode = settings.bool_value (ws_color_mode); + if (cb_color_mode->isChecked () == sec_color_mode) + { + // color mode does not change, update colors manually + update_workspace_colors (); + } + else + { + // toggling check-state calls related slot updating colors + cb_color_mode->setChecked (sec_color_mode); + } + } // variable editor - varedit_columnWidth->setValue (settings->value (ve_column_width).toInt ()); - varedit_rowHeight->setValue (settings->value (ve_row_height).toInt ()); - - varedit_font->setCurrentFont (QFont (settings->value (ve_font_name.key, - settings->value (cs_font.key, default_font)).toString ())); - varedit_fontSize->setValue (settings->value (ve_font_size).toInt ()); - connect (varedit_useTerminalFont, &QCheckBox::toggled, - varedit_font, &QFontComboBox::setDisabled); - connect (varedit_useTerminalFont, &QCheckBox::toggled, - varedit_fontSize, &QSpinBox::setDisabled); - varedit_useTerminalFont->setChecked (settings->value (ve_use_terminal_font).toBool ()); + if (first) + { + connect (varedit_useTerminalFont, &QCheckBox::toggled, + varedit_font, &QFontComboBox::setDisabled); + connect (varedit_useTerminalFont, &QCheckBox::toggled, + varedit_fontSize, &QSpinBox::setDisabled); + } + varedit_columnWidth->setValue (settings.int_value (ve_column_width)); + varedit_rowHeight->setValue (settings.int_value (ve_row_height)); + varedit_font->setCurrentFont (QFont (settings.value (ve_font_name.settings_key (), + settings.value (cs_font.settings_key (), default_font)).toString ())); + varedit_fontSize->setValue (settings.int_value (ve_font_size)); + varedit_useTerminalFont->setChecked (settings.bool_value (ve_use_terminal_font)); varedit_font->setDisabled (varedit_useTerminalFont->isChecked ()); varedit_fontSize->setDisabled (varedit_useTerminalFont->isChecked ()); - - varedit_alternate->setChecked (settings->value (ve_alternate_rows).toBool ()); + varedit_alternate->setChecked (settings.bool_value (ve_alternate_rows)); // variable editor colors - read_varedit_colors (settings); + if (first) + read_varedit_colors (); + else + { + QCheckBox *cb_color_mode + = varedit_colors_box->findChild (ve_color_mode.settings_key ()); + bool sec_color_mode = settings.bool_value (ve_color_mode); + if (cb_color_mode->isChecked () == sec_color_mode) + { + // color mode does not change, update colors manually + update_varedit_colors (); + } + else + { + // toggling check-state calls related slot updating colors + cb_color_mode->setChecked (sec_color_mode); + } + } // shortcuts - shortcut_manager& scmgr = m_octave_qobj.get_shortcut_manager (); - - cb_prevent_readline_conflicts->setChecked ( - settings->value (sc_prevent_rl_conflicts.key, - sc_prevent_rl_conflicts.def).toBool ()); - cb_prevent_readline_conflicts_menu->setChecked ( - settings->value (sc_prevent_rl_conflicts_menu.key, - sc_prevent_rl_conflicts_menu.def).toBool ()); - - // initialize the tree view with all shortcut data - scmgr.fill_treewidget (shortcuts_treewidget); + cb_prevent_readline_conflicts->setChecked (settings.bool_value (sc_prevent_rl_conflicts)); + cb_prevent_readline_conflicts_menu->setChecked (settings.bool_value (sc_prevent_rl_conflicts_menu)); // connect the buttons for import/export of the shortcut sets - connect (btn_import_shortcut_set, &QPushButton::clicked, - this, &settings_dialog::import_shortcut_set); + // FIXME: Should there also be a button to discard changes? + + if (first) + { + connect (btn_import_shortcut_set, &QPushButton::clicked, + this, &settings_dialog::import_shortcut_set); - connect (btn_export_shortcut_set, &QPushButton::clicked, - this, &settings_dialog::export_shortcut_set); + connect (btn_export_shortcut_set, &QPushButton::clicked, + this, &settings_dialog::export_shortcut_set); - connect (btn_default_shortcut_set, &QPushButton::clicked, - this, &settings_dialog::default_shortcut_set); + connect (btn_default_shortcut_set, &QPushButton::clicked, + this, &settings_dialog::default_shortcut_set); + } #if defined (HAVE_QSCINTILLA) - int mode = settings->value (ed_color_mode).toInt (); + if (first) + { + int mode = settings.int_value (ed_color_mode); - QCheckBox *cb_color_mode = new QCheckBox (tr (settings_color_modes.toStdString ().data ()), - group_box_editor_styles); - cb_color_mode->setToolTip (tr (settings_color_modes_tooltip.toStdString ().data ())); - cb_color_mode->setChecked (mode > 0); - cb_color_mode->setObjectName (ed_color_mode.key); + QCheckBox *cb_color_mode = new QCheckBox (tr (settings_color_modes.toStdString ().data ()), + group_box_editor_styles); + cb_color_mode->setToolTip (tr (settings_color_modes_tooltip.toStdString ().data ())); + cb_color_mode->setChecked (mode > 0); + cb_color_mode->setObjectName (ed_color_mode.settings_key ()); + + QPushButton *pb_reload_default_colors = new QPushButton (tr (settings_reload_styles.toStdString ().data ())); + pb_reload_default_colors->setToolTip (tr (settings_reload_styles_tooltip.toStdString ().data ())); - QPushButton *pb_reload_default_colors = new QPushButton (tr (settings_reload_styles.toStdString ().data ())); - pb_reload_default_colors->setToolTip (tr (settings_reload_styles_tooltip.toStdString ().data ())); + color_picker *current_line_color = new color_picker ( + settings.value (ed_highlight_current_line_color.settings_key () + + settings_color_modes_ext[mode], + ed_highlight_current_line_color.def ()).value ()); + current_line_color->setObjectName (ed_highlight_current_line_color.settings_key ()); - color_picker *current_line_color = new color_picker ( - settings->value (ed_highlight_current_line_color.key + - settings_color_modes_ext[mode], - ed_highlight_current_line_color.def).value (), this); - current_line_color->setObjectName (ed_highlight_current_line_color.key); - QLabel *current_line_color_label = new QLabel( - tr ("Color of highlighted current line (magenta (255,0,255) for automatic color)") - ); + QLabel *current_line_color_label + = new QLabel(tr ("Color of highlighted current line (magenta (255,0,255) for automatic color)")); + + QHBoxLayout *color_mode = new QHBoxLayout (); + color_mode->addWidget (cb_color_mode); + color_mode->addItem (new QSpacerItem (5, 5, QSizePolicy::Expanding)); + color_mode->addWidget (pb_reload_default_colors); - QHBoxLayout *color_mode = new QHBoxLayout (); - color_mode->addWidget (cb_color_mode); - color_mode->addItem (new QSpacerItem (5, 5, QSizePolicy::Expanding)); - color_mode->addWidget (pb_reload_default_colors); + QHBoxLayout *current_line = new QHBoxLayout (); + current_line->addWidget (current_line_color_label); + current_line->addWidget (current_line_color); + current_line->addItem (new QSpacerItem (5, 5, QSizePolicy::Expanding)); - QHBoxLayout *current_line = new QHBoxLayout (); - current_line->addWidget (current_line_color_label); - current_line->addWidget (current_line_color); - current_line->addItem (new QSpacerItem (5, 5, QSizePolicy::Expanding)); + editor_styles_layout->addLayout (color_mode); + editor_styles_layout->addLayout (current_line); + + // update colors depending on second theme selection + connect (cb_color_mode, &QCheckBox::stateChanged, + this, &settings_dialog::update_editor_lexers); + connect (pb_reload_default_colors, &QPushButton::clicked, + [=] () { update_editor_lexers (settings_reload_default_colors_flag); }); - editor_styles_layout->addLayout (color_mode); - editor_styles_layout->addLayout (current_line); - - // update colors depending on second theme selection - connect (cb_color_mode, &QCheckBox::stateChanged, - this, &settings_dialog::update_editor_lexers); - connect (pb_reload_default_colors, &QPushButton::clicked, - [=] () { update_editor_lexers (settings_reload_default_colors_flag); }); - - // finally read the lexer colors using the update slot - update_editor_lexers (); + // finally read the lexer colors using the update slot + update_editor_lexers (); + } + else + { + QCheckBox *cb_color_mode + = group_box_editor_styles->findChild (ed_color_mode.settings_key ()); + bool sec_color_mode = settings.bool_value (ed_color_mode); + if (cb_color_mode->isChecked () == sec_color_mode) + { + // color mode does not change, update colors manually + update_editor_lexers (); + } + else + { + // toggling check-state calls related slot updating colors + cb_color_mode->setChecked (sec_color_mode); + } + } #endif - - // which tab is the desired one? - show_tab (desired_tab); - - // connect button box signal - connect (button_box, &QDialogButtonBox::clicked, - this, &settings_dialog::button_clicked); - - // restore last geometry - if (settings->contains (sd_geometry.key)) - restoreGeometry (settings->value (sd_geometry).toByteArray ()); - else - setGeometry (QRect (10, 50, 1000, 600)); } void settings_dialog::show_tab (const QString& tab) { + gui_settings settings; + if (tab.isEmpty ()) - { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - if (settings) - tabWidget->setCurrentIndex (settings->value (sd_last_tab).toInt ()); - } + tabWidget->setCurrentIndex (settings.int_value (sd_last_tab)); else { QHash tab_hash; @@ -533,12 +620,12 @@ } } -void settings_dialog::get_octave_dir (void) +void settings_dialog::get_octave_dir () { get_dir (le_octave_dir, tr ("Set Octave Startup Directory")); } -void settings_dialog::get_file_browser_dir (void) +void settings_dialog::get_file_browser_dir () { get_dir (le_file_browser_dir, tr ("Set File Browser Startup Directory")); } @@ -547,9 +634,10 @@ { // FIXME: Remove, if for all common KDE versions (bug #54607) is resolved. int opts = QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks; - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - if (! settings->value (global_use_native_dialogs).toBool ()) + + gui_settings settings; + + if (! settings.bool_value (global_use_native_dialogs)) opts |= QFileDialog::DontUseNativeDialog; QString dir = QFileDialog::getExistingDirectory @@ -565,23 +653,33 @@ if (button_role == QDialogButtonBox::ApplyRole || button_role == QDialogButtonBox::AcceptRole) { - write_changed_settings (button_role == QDialogButtonBox::AcceptRole); + write_changed_settings (); + if (button_role == QDialogButtonBox::AcceptRole) + hide (); // already hide here, reloading settings takes some time + + QMessageBox *info = wait_message_box (tr ("Applying preferences ... "), this); emit apply_new_settings (); + close_wait_message_box (info); } if (button_role == QDialogButtonBox::RejectRole || button_role == QDialogButtonBox::AcceptRole) { // save last settings dialog's geometry and close - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); + + gui_settings settings; - settings->setValue (sd_last_tab.key, tabWidget->currentIndex ()); - settings->setValue (sd_geometry.key, saveGeometry ()); - settings->sync (); + settings.setValue (sd_last_tab.settings_key (), tabWidget->currentIndex ()); + settings.setValue (sd_geometry.settings_key (), saveGeometry ()); + settings.sync (); close (); } + + if (button_role == QDialogButtonBox::ResetRole) + { + read_settings (false); // not the first read, only update existing items + } } void settings_dialog::set_disabled_pref_file_browser_dir (bool disable) @@ -601,7 +699,7 @@ } // slot for updating enabled state of proxy settings -void settings_dialog::proxy_items_update (void) +void settings_dialog::proxy_items_update () { bool use_proxy = use_proxy_server->isChecked (); @@ -628,53 +726,85 @@ // slots for import/export of shortcut sets -void settings_dialog::import_shortcut_set (void) +// Prompt for file name and import shortcuts from it. Importing will +// change values in tree view but does not apply values to +// gui_settings_object so that the user may choose to apply or cancel +// the action. + +void settings_dialog::import_shortcut_set () { - shortcut_manager& scmgr = m_octave_qobj.get_shortcut_manager (); + if (! overwrite_all_shortcuts ()) + return; + + QString file = get_shortcuts_file_name (OSC_IMPORT); - scmgr.import_export (shortcut_manager::OSC_IMPORT); + gui_settings osc_settings (file, QSettings::IniFormat); + + if (osc_settings.status () == QSettings::NoError) + shortcuts_treewidget->import_shortcuts (osc_settings); + else + qWarning () << (tr ("Failed to open %1 as Octave shortcut file") + .arg (file)); } -void settings_dialog::export_shortcut_set (void) +// Prompt for file name and export shortcuts to it. + +// FIXME: Should exported settings values come from the gui_settings +// object or the tree view? If modified values in the tree view have +// not been applied, should we offer to apply them first? Offer a +// choice to save current application settings or the modified values +// in the dialog? + +void settings_dialog::export_shortcut_set () { - shortcut_manager& scmgr = m_octave_qobj.get_shortcut_manager (); + QString file = get_shortcuts_file_name (OSC_EXPORT); + + gui_settings osc_settings (file, QSettings::IniFormat); - scmgr.import_export (shortcut_manager::OSC_EXPORT); + if (osc_settings.status () == QSettings::NoError) + shortcuts_treewidget->export_shortcuts (osc_settings); + else + qWarning () << (tr ("Failed to open %1 as Octave shortcut file") + .arg (file)); } -void settings_dialog::default_shortcut_set (void) +// Reset the tree view to default values. Does not apply values to +// gui_settings object so that the user may choose to apply or cancel +// the action. + +void settings_dialog::default_shortcut_set () { - shortcut_manager& scmgr = m_octave_qobj.get_shortcut_manager (); + if (! overwrite_all_shortcuts ()) + return; - scmgr.import_export (shortcut_manager::OSC_DEFAULT); + shortcuts_treewidget->set_default_shortcuts (); } void settings_dialog::update_editor_lexers (int def) { #if defined (HAVE_QSCINTILLA) - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - QCheckBox *cb_color_mode - = group_box_editor_styles->findChild (ed_color_mode.key); + = group_box_editor_styles->findChild (ed_color_mode.settings_key ()); int m = 0; if (cb_color_mode && cb_color_mode->isChecked ()) m = 1; - color_picker *c_picker = findChild (ed_highlight_current_line_color.key); + color_picker *c_picker = findChild (ed_highlight_current_line_color.settings_key ()); if (c_picker) { + gui_settings settings; + if (def != settings_reload_default_colors_flag) { // Get current value from settings or the default - c_picker->set_color (settings->color_value (ed_highlight_current_line_color, m)); + c_picker->set_color (settings.color_value (ed_highlight_current_line_color, m)); } else { // Get the default value - c_picker->set_color (settings->get_color_value (ed_highlight_current_line_color.def, m)); + c_picker->set_color (settings.get_color_value (ed_highlight_current_line_color.def (), m)); } } @@ -684,40 +814,40 @@ # if defined (HAVE_LEXER_OCTAVE) lexer = new QsciLexerOctave (); - update_lexer (lexer, settings, m, def); + update_lexer (lexer, m, def); delete lexer; # elif defined (HAVE_LEXER_MATLAB) lexer = new QsciLexerMatlab (); - update_lexer (lexer, settings, m, def); + update_lexer (lexer, m, def); delete lexer; # endif lexer = new QsciLexerCPP (); - update_lexer (lexer, settings, m, def); + update_lexer (lexer, m, def); delete lexer; lexer = new QsciLexerJava (); - update_lexer (lexer, settings, m, def); + update_lexer (lexer, m, def); delete lexer; lexer = new QsciLexerPerl (); - update_lexer (lexer, settings, m, def); + update_lexer (lexer, m, def); delete lexer; lexer = new QsciLexerBatch (); - update_lexer (lexer, settings, m, def); + update_lexer (lexer, m, def); delete lexer; lexer = new QsciLexerDiff (); - update_lexer (lexer, settings, m, def); + update_lexer (lexer, m, def); delete lexer; lexer = new QsciLexerBash (); - update_lexer (lexer, settings, m, def); + update_lexer (lexer, m, def); delete lexer; lexer = new octave_txt_lexer (); - update_lexer (lexer, settings, m, def); + update_lexer (lexer, m, def); delete lexer; #else @@ -729,13 +859,12 @@ #if defined (HAVE_QSCINTILLA) -void settings_dialog::update_lexer (QsciLexer *lexer, gui_settings *settings, - int mode, int def) +void settings_dialog::update_lexer (QsciLexer *lexer, int mode, int def) { // Get lexer settings and copy from default settings if not yet // available in normal settings file - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - rmgr.read_lexer_settings (lexer, settings, mode, def); + gui_settings settings; + settings.read_lexer_settings (lexer, mode, def); // When reloading default styles, the style tabs do already exists. // Otherwise, check if they exist or not. @@ -755,13 +884,13 @@ { // This is not an update, call get_lexer_settings for building // the settings tab - get_lexer_settings (lexer, settings); + get_lexer_settings (lexer); return; } // Update the styles elements in all styles int styles[ed_max_lexer_styles]; // array for saving valid styles - int max_style = rmgr.get_valid_lexer_styles (lexer, styles); + int max_style = settings.get_valid_lexer_styles (lexer, styles); QWidget *tab = tabs_editor_lexers->widget (index); int default_size = 0; QString default_family; @@ -832,14 +961,13 @@ } -void settings_dialog::get_lexer_settings (QsciLexer *lexer, - gui_settings *settings) +void settings_dialog::get_lexer_settings (QsciLexer *lexer) { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); + gui_settings settings; int styles[ed_max_lexer_styles]; // array for saving valid styles // (enum is not continuous) - int max_style = rmgr.get_valid_lexer_styles (lexer, styles); + int max_style = settings.get_valid_lexer_styles (lexer, styles); QGridLayout *style_grid = new QGridLayout (); QVector description (max_style); QVector select_font (max_style); @@ -924,27 +1052,28 @@ scroll_area->setWidget (scroll_area_contents); tabs_editor_lexers->addTab (scroll_area, lexer->language ()); - tabs_editor_lexers->setCurrentIndex (settings->value (sd_last_editor_styles_tab).toInt ()); + tabs_editor_lexers->setCurrentIndex (settings.int_value (sd_last_editor_styles_tab)); } -void settings_dialog::write_lexer_settings (QsciLexer *lexer, - gui_settings *settings) +void settings_dialog::write_lexer_settings (QsciLexer *lexer) { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); + gui_settings settings; QCheckBox *cb_color_mode - = group_box_editor_styles->findChild (ed_color_mode.key); + = group_box_editor_styles->findChild (ed_color_mode.settings_key ()); int mode = 0; if (cb_color_mode && cb_color_mode->isChecked ()) mode = 1; - settings->setValue (ed_color_mode.key, mode); + settings.setValue (ed_color_mode.settings_key (), mode); QWidget *tab = tabs_editor_lexers-> findChild (QString (lexer->language ()) + "_styles"); int styles[ed_max_lexer_styles]; // array for saving valid styles // (enum is not continuous) - int max_style = rmgr.get_valid_lexer_styles (lexer, styles); + + int max_style = settings.get_valid_lexer_styles (lexer, styles); + QFontComboBox *select_font; QSpinBox *font_size; QCheckBox *attrib_font[3]; @@ -952,13 +1081,13 @@ color_picker *bg_color; int default_size = 10; - color = findChild (ed_highlight_current_line_color.key); + color = findChild (ed_highlight_current_line_color.settings_key ()); if (color) - settings->setValue (ed_highlight_current_line_color.key + settings.setValue (ed_highlight_current_line_color.settings_key () + settings_color_modes_ext[mode], color->color ()); QString default_font_name - = settings->value (global_mono_font).toString (); + = settings.string_value (global_mono_font); QFont default_font = QFont (default_font_name, 10, -1, 0); QColor default_color = QColor (); @@ -1023,19 +1152,19 @@ const std::string group = QString ("Scintilla" + settings_color_modes_ext[mode]).toStdString (); - lexer->writeSettings (*settings, group.c_str ()); + lexer->writeSettings (settings, group.c_str ()); - settings->setValue (sd_last_editor_styles_tab.key, - tabs_editor_lexers->currentIndex ()); - settings->sync (); + settings.setValue (sd_last_editor_styles_tab.settings_key (), + tabs_editor_lexers->currentIndex ()); + settings.sync (); } #endif -void settings_dialog::write_changed_settings (bool closing) +void settings_dialog::write_changed_settings () { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); + + gui_settings settings; // the icon set QString widget_icon_set = "NONE"; @@ -1043,87 +1172,87 @@ widget_icon_set = "LETTER"; else if (general_icon_graphic->isChecked ()) widget_icon_set = "GRAPHIC"; - settings->setValue (dw_icon_set.key, widget_icon_set); + settings.setValue (dw_icon_set.settings_key (), widget_icon_set); // language QString language = comboBox_language->currentText (); if (language == tr ("System setting")) - language = global_language.def.toString (); - settings->setValue (global_language.key, language); + language = global_language.def ().toString (); + settings.setValue (global_language.settings_key (), language); // style QString selected_style = combo_styles->currentText (); - if (selected_style == global_style.def.toString ()) - selected_style = global_style.def.toString (); - settings->setValue (global_style.key, selected_style); + if (selected_style == global_style.def ().toString ()) + selected_style = global_style.def ().toString (); + settings.setValue (global_style.settings_key (), selected_style); // dock widget title bar - settings->setValue (dw_title_custom_style.key, cb_widget_custom_style->isChecked ()); - settings->setValue (dw_title_3d.key, sb_3d_title->value ()); - settings->setValue (dw_title_bg_color.key, m_widget_title_bg_color->color ()); - settings->setValue (dw_title_bg_color_active.key, m_widget_title_bg_color_active->color ()); - settings->setValue (dw_title_fg_color.key, m_widget_title_fg_color->color ()); - settings->setValue (dw_title_fg_color_active.key, m_widget_title_fg_color_active->color ()); + settings.setValue (dw_title_custom_style.settings_key (), cb_widget_custom_style->isChecked ()); + settings.setValue (dw_title_3d.settings_key (), sb_3d_title->value ()); + settings.setValue (dw_title_bg_color.settings_key (), m_widget_title_bg_color->color ()); + settings.setValue (dw_title_bg_color_active.settings_key (), m_widget_title_bg_color_active->color ()); + settings.setValue (dw_title_fg_color.settings_key (), m_widget_title_fg_color->color ()); + settings.setValue (dw_title_fg_color_active.settings_key (), m_widget_title_fg_color_active->color ()); // icon size and theme int icon_size = icon_size_large->isChecked () - icon_size_small->isChecked (); - settings->setValue (global_icon_size.key, icon_size); - settings->setValue (global_icon_theme_index.key, combo_box_icon_theme->currentIndex ()); + settings.setValue (global_icon_size.settings_key (), icon_size); + settings.setValue (global_icon_theme_index.settings_key (), combo_box_icon_theme->currentIndex ()); // native file dialogs - settings->setValue (global_use_native_dialogs.key, cb_use_native_file_dialogs->isChecked ()); + settings.setValue (global_use_native_dialogs.settings_key (), cb_use_native_file_dialogs->isChecked ()); // cursor blinking - settings->setValue (global_cursor_blinking.key, cb_cursor_blinking->isChecked ()); + settings.setValue (global_cursor_blinking.settings_key (), cb_cursor_blinking->isChecked ()); // focus follows mouse - settings->setValue (dw_focus_follows_mouse.key, cb_focus_follows_mouse->isChecked ()); + settings.setValue (dw_focus_follows_mouse.settings_key (), cb_focus_follows_mouse->isChecked ()); // promp to exit - settings->setValue (global_prompt_to_exit.key, cb_prompt_to_exit->isChecked ()); + settings.setValue (global_prompt_to_exit.settings_key (), cb_prompt_to_exit->isChecked ()); // status bar - settings->setValue (global_status_bar.key, cb_status_bar->isChecked ()); + settings.setValue (global_status_bar.settings_key (), cb_status_bar->isChecked ()); // Octave startup - settings->setValue (global_restore_ov_dir.key, cb_restore_octave_dir->isChecked ()); - settings->setValue (global_ov_startup_dir.key, le_octave_dir->text ()); + settings.setValue (global_restore_ov_dir.settings_key (), cb_restore_octave_dir->isChecked ()); + settings.setValue (global_ov_startup_dir.settings_key (), le_octave_dir->text ()); //editor - settings->setValue (global_use_custom_editor.key, useCustomFileEditor->isChecked ()); - settings->setValue (global_custom_editor.key, customFileEditor->text ()); - settings->setValue (ed_show_line_numbers.key, editor_showLineNumbers->isChecked ()); - settings->setValue (ed_line_numbers_size.key, editor_linenr_size->value ()); - settings->setValue (ed_highlight_current_line.key, editor_highlightCurrentLine->isChecked ()); - settings->setValue (ed_long_line_marker.key, editor_long_line_marker->isChecked ()); - settings->setValue (ed_long_line_marker_line.key, editor_long_line_marker_line->isChecked ()); - settings->setValue (ed_long_line_marker_background.key, editor_long_line_marker_background->isChecked ()); - settings->setValue (ed_long_line_column.key, editor_long_line_column->value ()); - settings->setValue (ed_break_lines.key, editor_break_checkbox->isChecked ()); - settings->setValue (ed_break_lines_comments.key, editor_break_comments_checkbox->isChecked ()); - settings->setValue (ed_wrap_lines.key, editor_wrap_checkbox->isChecked ()); - settings->setValue (ed_code_folding.key, cb_code_folding->isChecked ()); - settings->setValue (ed_show_edit_status_bar.key, cb_edit_status_bar->isChecked ()); - settings->setValue (ed_show_toolbar.key, cb_edit_tool_bar->isChecked ()); - settings->setValue (ed_highlight_all_occurrences.key, editor_highlight_all_occurrences->isChecked ()); - settings->setValue (ed_code_completion.key, editor_codeCompletion->isChecked ()); - settings->setValue (ed_code_completion_threshold.key, editor_spinbox_ac_threshold->value ()); - settings->setValue (ed_code_completion_keywords.key, editor_checkbox_ac_keywords->isChecked ()); - settings->setValue (ed_code_completion_octave_builtins.key, editor_checkbox_ac_builtins->isChecked ()); - settings->setValue (ed_code_completion_octave_functions.key, editor_checkbox_ac_functions->isChecked ()); - settings->setValue (ed_code_completion_document.key, editor_checkbox_ac_document->isChecked ()); - settings->setValue (ed_code_completion_case.key, editor_checkbox_ac_case->isChecked ()); - settings->setValue (ed_code_completion_replace.key, editor_checkbox_ac_replace->isChecked ()); - settings->setValue (ed_auto_endif.key, editor_auto_endif->currentIndex ()); - settings->setValue (ed_show_white_space.key, editor_ws_checkbox->isChecked ()); - settings->setValue (ed_show_white_space_indent.key, editor_ws_indent_checkbox->isChecked ()); - settings->setValue (ed_show_eol_chars.key, cb_show_eol->isChecked ()); - settings->setValue (ed_show_hscroll_bar.key, cb_show_hscrollbar->isChecked ()); - settings->setValue (ed_default_eol_mode.key, combo_eol_mode->currentIndex ()); + settings.setValue (global_use_custom_editor.settings_key (), useCustomFileEditor->isChecked ()); + settings.setValue (global_custom_editor.settings_key (), customFileEditor->text ()); + settings.setValue (ed_show_line_numbers.settings_key (), editor_showLineNumbers->isChecked ()); + settings.setValue (ed_line_numbers_size.settings_key (), editor_linenr_size->value ()); + settings.setValue (ed_highlight_current_line.settings_key (), editor_highlightCurrentLine->isChecked ()); + settings.setValue (ed_long_line_marker.settings_key (), editor_long_line_marker->isChecked ()); + settings.setValue (ed_long_line_marker_line.settings_key (), editor_long_line_marker_line->isChecked ()); + settings.setValue (ed_long_line_marker_background.settings_key (), editor_long_line_marker_background->isChecked ()); + settings.setValue (ed_long_line_column.settings_key (), editor_long_line_column->value ()); + settings.setValue (ed_break_lines.settings_key (), editor_break_checkbox->isChecked ()); + settings.setValue (ed_break_lines_comments.settings_key (), editor_break_comments_checkbox->isChecked ()); + settings.setValue (ed_wrap_lines.settings_key (), editor_wrap_checkbox->isChecked ()); + settings.setValue (ed_code_folding.settings_key (), cb_code_folding->isChecked ()); + settings.setValue (ed_show_edit_status_bar.settings_key (), cb_edit_status_bar->isChecked ()); + settings.setValue (ed_show_toolbar.settings_key (), cb_edit_tool_bar->isChecked ()); + settings.setValue (ed_highlight_all_occurrences.settings_key (), editor_highlight_all_occurrences->isChecked ()); + settings.setValue (ed_code_completion.settings_key (), editor_codeCompletion->isChecked ()); + settings.setValue (ed_code_completion_threshold.settings_key (), editor_spinbox_ac_threshold->value ()); + settings.setValue (ed_code_completion_keywords.settings_key (), editor_checkbox_ac_keywords->isChecked ()); + settings.setValue (ed_code_completion_octave_builtins.settings_key (), editor_checkbox_ac_builtins->isChecked ()); + settings.setValue (ed_code_completion_octave_functions.settings_key (), editor_checkbox_ac_functions->isChecked ()); + settings.setValue (ed_code_completion_document.settings_key (), editor_checkbox_ac_document->isChecked ()); + settings.setValue (ed_code_completion_case.settings_key (), editor_checkbox_ac_case->isChecked ()); + settings.setValue (ed_code_completion_replace.settings_key (), editor_checkbox_ac_replace->isChecked ()); + settings.setValue (ed_auto_endif.settings_key (), editor_auto_endif->currentIndex ()); + settings.setValue (ed_show_white_space.settings_key (), editor_ws_checkbox->isChecked ()); + settings.setValue (ed_show_white_space_indent.settings_key (), editor_ws_indent_checkbox->isChecked ()); + settings.setValue (ed_show_eol_chars.settings_key (), cb_show_eol->isChecked ()); + settings.setValue (ed_show_hscroll_bar.settings_key (), cb_show_hscrollbar->isChecked ()); + settings.setValue (ed_default_eol_mode.settings_key (), combo_eol_mode->currentIndex ()); - settings->setValue (ed_tab_position.key, editor_combox_tab_pos->currentIndex ()); - settings->setValue (ed_tabs_rotated.key, editor_cb_tabs_rotated->isChecked ()); - settings->setValue (ed_tabs_max_width.key, editor_sb_tabs_max_width->value ()); + settings.setValue (ed_tab_position.settings_key (), editor_combox_tab_pos->currentIndex ()); + settings.setValue (ed_tabs_rotated.settings_key (), editor_cb_tabs_rotated->isChecked ()); + settings.setValue (ed_tabs_max_width.settings_key (), editor_sb_tabs_max_width->value ()); // Comment strings int rb_uncomment = 0; @@ -1131,56 +1260,56 @@ { if (m_rb_comment_strings[i]->isChecked ()) { - settings->setValue (ed_comment_str.key, i); + settings.setValue (ed_comment_str.settings_key (), i); if (i < 3) - settings->setValue (ed_comment_str_old.key, i); + settings.setValue (ed_comment_str_old.settings_key (), i); else - settings->setValue (ed_comment_str_old.key, ed_comment_str.def); + settings.setValue (ed_comment_str_old.settings_key (), ed_comment_str.def ()); } if (m_rb_uncomment_strings[i]->isChecked ()) rb_uncomment = rb_uncomment + (1 << i); } - settings->setValue (ed_uncomment_str.key, rb_uncomment); + settings.setValue (ed_uncomment_str.settings_key (), rb_uncomment); - settings->setValue (ed_default_enc.key, editor_combo_encoding->currentText ()); - settings->setValue (ed_auto_indent.key, editor_auto_ind_checkbox->isChecked ()); - settings->setValue (ed_tab_indents_line.key, editor_tab_ind_checkbox->isChecked ()); - settings->setValue (ed_backspace_unindents_line.key, editor_bs_unind_checkbox->isChecked ()); - settings->setValue (ed_show_indent_guides.key, editor_ind_guides_checkbox->isChecked ()); - settings->setValue (ed_indent_width.key, editor_ind_width_spinbox->value ()); - settings->setValue (ed_indent_uses_tabs.key, editor_ind_uses_tabs_checkbox->isChecked ()); - settings->setValue (ed_tab_width.key, editor_tab_width_spinbox->value ()); - settings->setValue (ed_restore_session.key, editor_restoreSession->isChecked ()); - settings->setValue (ed_create_new_file.key, editor_create_new_file->isChecked ()); - settings->setValue (ed_hiding_closes_files.key, editor_hiding_closes_files->isChecked ()); - settings->setValue (ed_always_reload_changed_files.key, editor_reload_changed_files->isChecked ()); - settings->setValue (ed_force_newline.key, editor_force_newline->isChecked ()); - settings->setValue (ed_rm_trailing_spaces.key, editor_remove_trailing_spaces->isChecked ()); - settings->setValue (ed_show_dbg_file.key, editor_show_dbg_file->isChecked ()); + settings.setValue (ed_default_enc.settings_key (), editor_combo_encoding->currentText ()); + settings.setValue (ed_auto_indent.settings_key (), editor_auto_ind_checkbox->isChecked ()); + settings.setValue (ed_tab_indents_line.settings_key (), editor_tab_ind_checkbox->isChecked ()); + settings.setValue (ed_backspace_unindents_line.settings_key (), editor_bs_unind_checkbox->isChecked ()); + settings.setValue (ed_show_indent_guides.settings_key (), editor_ind_guides_checkbox->isChecked ()); + settings.setValue (ed_indent_width.settings_key (), editor_ind_width_spinbox->value ()); + settings.setValue (ed_indent_uses_tabs.settings_key (), editor_ind_uses_tabs_checkbox->isChecked ()); + settings.setValue (ed_tab_width.settings_key (), editor_tab_width_spinbox->value ()); + settings.setValue (ed_restore_session.settings_key (), editor_restoreSession->isChecked ()); + settings.setValue (ed_create_new_file.settings_key (), editor_create_new_file->isChecked ()); + settings.setValue (ed_hiding_closes_files.settings_key (), editor_hiding_closes_files->isChecked ()); + settings.setValue (ed_always_reload_changed_files.settings_key (), editor_reload_changed_files->isChecked ()); + settings.setValue (ed_force_newline.settings_key (), editor_force_newline->isChecked ()); + settings.setValue (ed_rm_trailing_spaces.settings_key (), editor_remove_trailing_spaces->isChecked ()); + settings.setValue (ed_show_dbg_file.settings_key (), editor_show_dbg_file->isChecked ()); // file browser - settings->setValue (fb_sync_octdir.key, sync_octave_directory->isChecked ()); - settings->setValue (fb_restore_last_dir.key, cb_restore_file_browser_dir->isChecked ()); - settings->setValue (fb_startup_dir.key, le_file_browser_dir->text ()); - settings->setValue (fb_txt_file_ext.key, le_file_browser_extensions->text ()); + settings.setValue (fb_sync_octdir.settings_key (), sync_octave_directory->isChecked ()); + settings.setValue (fb_restore_last_dir.settings_key (), cb_restore_file_browser_dir->isChecked ()); + settings.setValue (fb_startup_dir.settings_key (), le_file_browser_dir->text ()); + settings.setValue (fb_txt_file_ext.settings_key (), le_file_browser_extensions->text ()); // network - settings->setValue (nr_allow_connection.key, checkbox_allow_web_connect->isChecked ()); - settings->setValue (global_use_proxy.key, use_proxy_server->isChecked ()); - settings->setValue (global_proxy_type.key, proxy_type->currentText ()); - settings->setValue (global_proxy_host.key, proxy_host_name->text ()); - settings->setValue (global_proxy_port.key, proxy_port->text ()); - settings->setValue (global_proxy_user.key, proxy_username->text ()); - settings->setValue (global_proxy_pass.key, proxy_password->text ()); + settings.setValue (nr_allow_connection.settings_key (), checkbox_allow_web_connect->isChecked ()); + settings.setValue (global_use_proxy.settings_key (), use_proxy_server->isChecked ()); + settings.setValue (global_proxy_type.settings_key (), proxy_type->currentText ()); + settings.setValue (global_proxy_host.settings_key (), proxy_host_name->text ()); + settings.setValue (global_proxy_port.settings_key (), proxy_port->text ()); + settings.setValue (global_proxy_user.settings_key (), proxy_username->text ()); + settings.setValue (global_proxy_pass.settings_key (), proxy_password->text ()); // command window - settings->setValue (cs_font_size.key, terminal_fontSize->value ()); - settings->setValue (cs_font.key, terminal_fontName->currentFont ().family ()); - settings->setValue (cs_cursor_use_fgcol.key, terminal_cursorUseForegroundColor->isChecked ()); - settings->setValue (cs_focus_cmd.key, terminal_focus_command->isChecked ()); - settings->setValue (cs_dbg_location.key, terminal_print_dbg_location->isChecked ()); - settings->setValue (cs_hist_buffer.key, terminal_history_buffer->value ()); - write_terminal_colors (settings); + settings.setValue (cs_font_size.settings_key (), terminal_fontSize->value ()); + settings.setValue (cs_font.settings_key (), terminal_fontName->currentFont ().family ()); + settings.setValue (cs_cursor_use_fgcol.settings_key (), terminal_cursorUseForegroundColor->isChecked ()); + settings.setValue (cs_focus_cmd.settings_key (), terminal_focus_command->isChecked ()); + settings.setValue (cs_dbg_location.settings_key (), terminal_print_dbg_location->isChecked ()); + settings.setValue (cs_hist_buffer.settings_key (), terminal_history_buffer->value ()); + write_terminal_colors (); // the cursor QString cursor_type; @@ -1188,9 +1317,9 @@ if ((cursor_int > 0) && (cursor_int < cs_cursor_types.size ())) cursor_type = QString (cs_cursor_types[cursor_int].data ()); else - cursor_type = cs_cursor.def.toString (); + cursor_type = cs_cursor.def ().toString (); - settings->setValue (cs_cursor.key, cursor_type); + settings.setValue (cs_cursor.settings_key (), cursor_type); #if defined (HAVE_QSCINTILLA) // editor styles: create lexer, get dialog contents, and write settings @@ -1199,71 +1328,73 @@ #if defined (HAVE_LEXER_OCTAVE) lexer = new QsciLexerOctave (); - write_lexer_settings (lexer, settings); + write_lexer_settings (lexer); delete lexer; #elif defined (HAVE_LEXER_MATLAB) lexer = new QsciLexerMatlab (); - write_lexer_settings (lexer, settings); + write_lexer_settings (lexer); delete lexer; #endif lexer = new QsciLexerCPP (); - write_lexer_settings (lexer, settings); + write_lexer_settings (lexer); delete lexer; lexer = new QsciLexerJava (); - write_lexer_settings (lexer, settings); + write_lexer_settings (lexer); delete lexer; lexer = new QsciLexerPerl (); - write_lexer_settings (lexer, settings); + write_lexer_settings (lexer); delete lexer; lexer = new QsciLexerBatch (); - write_lexer_settings (lexer, settings); + write_lexer_settings (lexer); delete lexer; lexer = new QsciLexerDiff (); - write_lexer_settings (lexer, settings); + write_lexer_settings (lexer); delete lexer; lexer = new QsciLexerBash (); - write_lexer_settings (lexer, settings); + write_lexer_settings (lexer); delete lexer; lexer = new octave_txt_lexer (); - write_lexer_settings (lexer, settings); + write_lexer_settings (lexer); delete lexer; #endif // Workspace - write_workspace_colors (settings); + write_workspace_colors (); // Variable editor - settings->setValue (ve_column_width.key, varedit_columnWidth->value ()); - settings->setValue (ve_row_height.key, varedit_rowHeight->value ()); - settings->setValue (ve_use_terminal_font.key, varedit_useTerminalFont->isChecked ()); - settings->setValue (ve_alternate_rows.key, varedit_alternate->isChecked ()); - settings->setValue (ve_font_name.key, varedit_font->currentFont ().family ()); - settings->setValue (ve_font_size.key, varedit_fontSize->value ()); - write_varedit_colors (settings); + settings.setValue (ve_column_width.settings_key (), varedit_columnWidth->value ()); + settings.setValue (ve_row_height.settings_key (), varedit_rowHeight->value ()); + settings.setValue (ve_use_terminal_font.settings_key (), varedit_useTerminalFont->isChecked ()); + settings.setValue (ve_alternate_rows.settings_key (), varedit_alternate->isChecked ()); + settings.setValue (ve_font_name.settings_key (), varedit_font->currentFont ().family ()); + settings.setValue (ve_font_size.settings_key (), varedit_fontSize->value ()); + write_varedit_colors (); // shortcuts - settings->setValue (sc_prevent_rl_conflicts.key, cb_prevent_readline_conflicts->isChecked ()); - settings->setValue (sc_prevent_rl_conflicts_menu.key, cb_prevent_readline_conflicts_menu->isChecked ()); - shortcut_manager& scmgr = m_octave_qobj.get_shortcut_manager (); - scmgr.write_shortcuts (settings, closing); + settings.setValue (sc_prevent_rl_conflicts.settings_key (), cb_prevent_readline_conflicts->isChecked ()); + settings.setValue (sc_prevent_rl_conflicts_menu.settings_key (), cb_prevent_readline_conflicts_menu->isChecked ()); - settings->sync (); + shortcuts_treewidget->write_settings (); + + settings.sync (); } -void settings_dialog::read_workspace_colors (gui_settings *settings) +void settings_dialog::read_workspace_colors () { + gui_settings settings; + // Construct the grid with all color related settings QGridLayout *style_grid = new QGridLayout (); QVector description (ws_colors_count); @@ -1272,7 +1403,7 @@ int column = 0; const int color_columns = 3; // place colors in so many columns int row = 0; - int mode = settings->value (ws_color_mode).toInt (); + int mode = settings.int_value (ws_color_mode); m_ws_enable_colors = new QCheckBox (tr ("Enable attribute colors")); style_grid->addWidget (m_ws_enable_colors, row++, column, 1, 4); @@ -1282,12 +1413,12 @@ connect (m_ws_enable_colors, &QCheckBox::toggled, m_ws_hide_tool_tips, &QCheckBox::setEnabled); m_ws_hide_tool_tips->setChecked - (settings->value (ws_hide_tool_tips).toBool ()); + (settings.bool_value (ws_hide_tool_tips)); QCheckBox *cb_color_mode = new QCheckBox (tr (settings_color_modes.toStdString ().data ())); cb_color_mode->setToolTip (tr (settings_color_modes_tooltip.toStdString ().data ())); cb_color_mode->setChecked (mode == 1); - cb_color_mode->setObjectName (ws_color_mode.key); + cb_color_mode->setObjectName (ws_color_mode.settings_key ()); connect (m_ws_enable_colors, &QCheckBox::toggled, cb_color_mode, &QCheckBox::setEnabled); style_grid->addWidget (cb_color_mode, row, column); @@ -1298,20 +1429,20 @@ pb_reload_default_colors, &QPushButton::setEnabled); style_grid->addWidget (pb_reload_default_colors, row+1, column++); - bool colors_enabled = settings->value (ws_enable_colors).toBool (); + bool colors_enabled = settings.bool_value (ws_enable_colors); for (int i = 0; i < ws_colors_count; i++) { description[i] = new QLabel (" " - + tr (ws_color_names.at (i).toStdString ().data ())); + + tr (ws_color_names.at (i).toStdString ().data ())); description[i]->setAlignment (Qt::AlignRight); description[i]->setEnabled (colors_enabled); connect (m_ws_enable_colors, &QCheckBox::toggled, description[i], &QLabel::setEnabled); - QColor setting_color = settings->color_value (ws_colors[i], mode); + QColor setting_color = settings.color_value (ws_colors[i], mode); color[i] = new color_picker (setting_color); - color[i]->setObjectName (ws_colors[i].key); + color[i]->setObjectName (ws_colors[i].settings_key ()); color[i]->setMinimumSize (30, 10); color[i]->setEnabled (colors_enabled); connect (m_ws_enable_colors, &QCheckBox::toggled, @@ -1347,43 +1478,44 @@ void settings_dialog::update_workspace_colors (int def) { QCheckBox *cb_color_mode - = workspace_colors_box->findChild (ws_color_mode.key); + = workspace_colors_box->findChild (ws_color_mode.settings_key ()); int m = 0; if (cb_color_mode && cb_color_mode->isChecked ()) m = 1; - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); + gui_settings settings; color_picker *c_picker; for (unsigned int i = 0; i < ws_colors_count; i++) { - c_picker = workspace_colors_box->findChild (ws_colors[i].key); + c_picker = workspace_colors_box->findChild (ws_colors[i].settings_key ()); if (c_picker) { if (def != settings_reload_default_colors_flag) { // Get current value from settings or the default - c_picker->set_color (settings->color_value (ws_colors[i], m)); + c_picker->set_color (settings.color_value (ws_colors[i], m)); } else { // Get the default value - c_picker->set_color (settings->get_color_value (ws_colors[i].def, m)); + c_picker->set_color (settings.get_color_value (ws_colors[i].def (), m)); } } } } -void settings_dialog::write_workspace_colors (gui_settings *settings) +void settings_dialog::write_workspace_colors () { - settings->setValue (ws_enable_colors.key, m_ws_enable_colors->isChecked ()); - settings->setValue (ws_hide_tool_tips.key, m_ws_hide_tool_tips->isChecked ()); + gui_settings settings; + + settings.setValue (ws_enable_colors.settings_key (), m_ws_enable_colors->isChecked ()); + settings.setValue (ws_hide_tool_tips.settings_key (), m_ws_hide_tool_tips->isChecked ()); QCheckBox *cb_color_mode - = workspace_colors_box->findChild (ws_color_mode.key); + = workspace_colors_box->findChild (ws_color_mode.settings_key ()); int mode = 0; if (cb_color_mode && cb_color_mode->isChecked ()) @@ -1393,28 +1525,30 @@ for (int i = 0; i < ws_colors_count; i++) { - color = workspace_colors_box->findChild (ws_colors[i].key); + color = workspace_colors_box->findChild (ws_colors[i].settings_key ()); if (color) - settings->set_color_value (ws_colors[i], color->color (), mode); + settings.set_color_value (ws_colors[i], color->color (), mode); } - settings->setValue (ws_color_mode.key, mode); + settings.setValue (ws_color_mode.settings_key (), mode); - settings->sync (); + settings.sync (); } -void settings_dialog::read_terminal_colors (gui_settings *settings) +void settings_dialog::read_terminal_colors () { + gui_settings settings; + QGridLayout *style_grid = new QGridLayout (); QVector description (cs_colors_count); QVector color (cs_colors_count); - int mode = settings->value (cs_color_mode).toInt (); + int mode = settings.int_value (cs_color_mode); QCheckBox *cb_color_mode = new QCheckBox (tr (settings_color_modes.toStdString ().data ())); cb_color_mode->setToolTip (tr (settings_color_modes_tooltip.toStdString ().data ())); cb_color_mode->setChecked (mode == 1); - cb_color_mode->setObjectName (cs_color_mode.key); + cb_color_mode->setObjectName (cs_color_mode.settings_key ()); style_grid->addWidget (cb_color_mode, 0, 0); QPushButton *pb_reload_default_colors = new QPushButton (tr (settings_reload_colors.toStdString ().data ())); @@ -1427,11 +1561,11 @@ for (unsigned int i = 0; i < cs_colors_count; i++) { description[i] = new QLabel (" " - + tr (cs_color_names.at (i).toStdString ().data ())); + + tr (cs_color_names.at (i).toStdString ().data ())); description[i]->setAlignment (Qt::AlignRight); - QColor setting_color = settings->color_value (cs_colors[i], mode); + QColor setting_color = settings.color_value (cs_colors[i], mode); color[i] = new color_picker (setting_color); - color[i]->setObjectName (cs_colors[i].key); + color[i]->setObjectName (cs_colors[i].settings_key ()); color[i]->setMinimumSize (30, 10); style_grid->addWidget (description[i], row, 2*column); style_grid->addWidget (color[i], row, 2*column+1); @@ -1456,71 +1590,74 @@ void settings_dialog::update_terminal_colors (int def) { QCheckBox *cb_color_mode - = terminal_colors_box->findChild (cs_color_mode.key); + = terminal_colors_box->findChild (cs_color_mode.settings_key ()); int m = 0; if (cb_color_mode && cb_color_mode->isChecked ()) m = 1; - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); + gui_settings settings; color_picker *c_picker; for (unsigned int i = 0; i < cs_colors_count; i++) { - c_picker = terminal_colors_box->findChild (cs_colors[i].key); + c_picker = terminal_colors_box->findChild (cs_colors[i].settings_key ()); if (c_picker) { if (def != settings_reload_default_colors_flag) { // Get current value from settings or the default - c_picker->set_color (settings->color_value (cs_colors[i], m)); + c_picker->set_color (settings.color_value (cs_colors[i], m)); } else { // Get the default value - c_picker->set_color (settings->get_color_value (cs_colors[i].def, m)); + c_picker->set_color (settings.get_color_value (cs_colors[i].def (), m)); } } } } -void settings_dialog::write_terminal_colors (gui_settings *settings) +void settings_dialog::write_terminal_colors () { QCheckBox *cb_color_mode - = terminal_colors_box->findChild (cs_color_mode.key); + = terminal_colors_box->findChild (cs_color_mode.settings_key ()); int mode = 0; if (cb_color_mode && cb_color_mode->isChecked ()) mode = 1; + gui_settings settings; + color_picker *color; for (int i = 0; i < cs_color_names.size (); i++) { - color = terminal_colors_box->findChild (cs_colors[i].key); + color = terminal_colors_box->findChild (cs_colors[i].settings_key ()); if (color) - settings->set_color_value (cs_colors[i], color->color (), mode); + settings.set_color_value (cs_colors[i], color->color (), mode); } - settings->setValue (cs_color_mode.key, mode); + settings.setValue (cs_color_mode.settings_key (), mode); - settings->sync (); + settings.sync (); } -void settings_dialog::read_varedit_colors (gui_settings *settings) +void settings_dialog::read_varedit_colors () { + gui_settings settings; + QGridLayout *style_grid = new QGridLayout (); QVector description (ve_colors_count); QVector color (ve_colors_count); - int mode = settings->value (ve_color_mode).toInt (); + int mode = settings.int_value (ve_color_mode); QCheckBox *cb_color_mode = new QCheckBox (tr (settings_color_modes.toStdString ().data ())); cb_color_mode->setToolTip (tr (settings_color_modes_tooltip.toStdString ().data ())); cb_color_mode->setChecked (mode == 1); - cb_color_mode->setObjectName (ve_color_mode.key); + cb_color_mode->setObjectName (ve_color_mode.settings_key ()); style_grid->addWidget (cb_color_mode, 0, 0); QPushButton *pb_reload_default_colors = new QPushButton (tr (settings_reload_colors.toStdString ().data ())); @@ -1533,12 +1670,12 @@ for (int i = 0; i < ve_colors_count; i++) { description[i] = new QLabel (" " - + tr (ve_color_names.at (i).toStdString ().data ())); + + tr (ve_color_names.at (i).toStdString ().data ())); description[i]->setAlignment (Qt::AlignRight); - QColor setting_color = settings->color_value (ve_colors[i], mode); + QColor setting_color = settings.color_value (ve_colors[i], mode); color[i] = new color_picker (setting_color); - color[i]->setObjectName (ve_colors[i].key); + color[i]->setObjectName (ve_colors[i].settings_key ()); color[i]->setMinimumSize (30, 10); style_grid->addWidget (description[i], row, 2*column); style_grid->addWidget (color[i], row, 2*column+1); @@ -1563,57 +1700,170 @@ void settings_dialog::update_varedit_colors (int def) { QCheckBox *cb_color_mode - = varedit_colors_box->findChild (ve_color_mode.key); + = varedit_colors_box->findChild (ve_color_mode.settings_key ()); int m = 0; if (cb_color_mode && cb_color_mode->isChecked ()) m = 1; - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); + gui_settings settings; color_picker *c_picker; for (unsigned int i = 0; i < ve_colors_count; i++) { - c_picker = varedit_colors_box->findChild (ve_colors[i].key); + c_picker = varedit_colors_box->findChild (ve_colors[i].settings_key ()); if (c_picker) { if (def != settings_reload_default_colors_flag) { // Get current value from settings or the default - c_picker->set_color (settings->color_value (ve_colors[i], m)); + c_picker->set_color (settings.color_value (ve_colors[i], m)); } else { // Get the default value - c_picker->set_color (settings->get_color_value (ve_colors[i].def, m)); + c_picker->set_color (settings.get_color_value (ve_colors[i].def (), m)); } } } } -void settings_dialog::write_varedit_colors (gui_settings *settings) +void settings_dialog::write_varedit_colors () { QCheckBox *cb_color_mode - = varedit_colors_box->findChild (ve_color_mode.key); + = varedit_colors_box->findChild (ve_color_mode.settings_key ()); int mode = 0; if (cb_color_mode && cb_color_mode->isChecked ()) mode = 1; + gui_settings settings; + color_picker *color; for (int i = 0; i < ve_colors_count; i++) { - color = varedit_colors_box->findChild (ve_colors[i].key); + color = varedit_colors_box->findChild (ve_colors[i].settings_key ()); if (color) - settings->set_color_value (ve_colors[i], color->color (), mode); + settings.set_color_value (ve_colors[i], color->color (), mode); } - settings->setValue (ve_color_mode.key, mode); + settings.setValue (ve_color_mode.settings_key (), mode); + + settings.sync (); +} + +QString settings_dialog::get_shortcuts_file_name (import_export_action action) +{ + QString file; + + // FIXME: Remove, if for all common KDE versions (bug #54607) is resolved. + int opts = 0; // No options by default. + + gui_settings settings; + + if (! settings.bool_value (global_use_native_dialogs)) + opts = QFileDialog::DontUseNativeDialog; + + if (action == OSC_IMPORT) + file = QFileDialog::getOpenFileName + (this, tr ("Import shortcuts from file..."), QString (), + tr ("Octave Shortcut Files (*.osc);;All Files (*)"), + nullptr, QFileDialog::Option (opts)); + + else + file = QFileDialog::getSaveFileName + (this, tr ("Export shortcuts to file..."), QString (), + tr ("Octave Shortcut Files (*.osc);;All Files (*)"), + nullptr, QFileDialog::Option (opts)); + + return file; +} + +// Ask whether to overwrite current shortcuts with settings from an +// imported file. Optionally allow current shortcuts to be saved to a +// file. + +// FIXME: If the tree view contains changes that have not yet been +// saved to the application settings object, should we +// +// * allow the user to choose whether to +// - cancel the operation (X) +// - save the modified settings (X) +// - save the current application settings (XX) +// +// * unconditionally display an error dialog and cancel the +// export operation +// +// (X) - already an option, but not based on whether the tree view +// contains unsaved changes +// (XX) - already possible (cancel operation, cancel settings +// dialog, re-open settings dialog and export changes). + +bool settings_dialog::overwrite_all_shortcuts () +{ + QMessageBox msg_box; - settings->sync (); + msg_box.setWindowTitle (tr ("Overwriting Shortcuts")); + msg_box.setIcon (QMessageBox::Warning); + msg_box.setText (tr ("You are about to overwrite all shortcuts.\n" + "Would you like to save the current shortcut set or cancel the action?")); + msg_box.setStandardButtons (QMessageBox::Save | QMessageBox::Cancel); + + QPushButton *discard + = msg_box.addButton (tr ("Don't save"), QMessageBox::DestructiveRole); + + msg_box.setDefaultButton (QMessageBox::Save); + + int ret = msg_box.exec (); + + if (msg_box.clickedButton () == discard) + return true; + + if (ret == QMessageBox::Save) + { + QString file = get_shortcuts_file_name (OSC_EXPORT); + + gui_settings osc_settings (file, QSettings::IniFormat); + + if (osc_settings.status () == QSettings::NoError) + { + shortcuts_treewidget->export_shortcuts (osc_settings); + return true; + } + else + qWarning () << (tr ("Failed to open %1 as Octave shortcut file") + .arg (file)); + } + + return false; +} + +QMessageBox* settings_dialog::wait_message_box (const QString& text, QWidget *p) +{ + QMessageBox *info = new QMessageBox (p); + + info->setIcon (QMessageBox::Information); + info->setWindowTitle (tr ("Octave GUI preferences")); + info->setText (text); + info->setStandardButtons (QMessageBox::Ok); + info->setAttribute (Qt::WA_DeleteOnClose); + info->setWindowModality (Qt::NonModal); + + info->show (); + QThread::msleep (100); + QCoreApplication::processEvents (); + + QApplication::setOverrideCursor (Qt::WaitCursor); + + return info; +} + +void settings_dialog::close_wait_message_box (QMessageBox *mbox) +{ + QApplication::restoreOverrideCursor (); + mbox->close (); } OCTAVE_END_NAMESPACE(octave) diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/settings-dialog.h --- a/libgui/src/settings-dialog.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/settings-dialog.h Fri May 12 08:03:14 2023 +0200 @@ -29,43 +29,43 @@ #include #include #include +#include #include #include "color-picker.h" #include "gui-preferences-ed.h" -#include "gui-settings.h" #include "ui-settings-dialog.h" class QsciLexer; OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; - // Ui::settings_dialog is a generated class. class settings_dialog : public QDialog, private Ui::settings_dialog { - Q_OBJECT public: + Q_OBJECT - explicit settings_dialog (QWidget *parent, base_qobject& octave_qobj, +public: + + explicit settings_dialog (QWidget *parent, const QString& desired_tab = QString ()); - ~settings_dialog (void) = default; + ~settings_dialog () = default; void show_tab (const QString&); signals: - void apply_new_settings (void); + void apply_new_settings (); private slots: - void get_octave_dir (void); - void get_file_browser_dir (void); + void get_octave_dir (); + void get_file_browser_dir (); void get_dir (QLineEdit *, const QString&); void set_disabled_pref_file_browser_dir (bool disable); - void proxy_items_update (void); + void proxy_items_update (); // slots updating colors depending on theme void update_terminal_colors (int def = 0); @@ -77,30 +77,43 @@ void button_clicked (QAbstractButton *button); // slots for import/export-buttons of shortcut sets - void import_shortcut_set (void); - void export_shortcut_set (void); - void default_shortcut_set (void); + void import_shortcut_set (); + void export_shortcut_set (); + void default_shortcut_set (); private: + enum import_export_action + { + OSC_IMPORT, + OSC_EXPORT + }; + #if defined (HAVE_QSCINTILLA) - void update_lexer (QsciLexer *lexer, gui_settings *settings, int mode, int def = 0); - void get_lexer_settings (QsciLexer *lexer, gui_settings *settings); - void write_lexer_settings (QsciLexer *lexer, gui_settings *settings); + void update_lexer (QsciLexer *lexer, int mode, int def = 0); + void get_lexer_settings (QsciLexer *lexer); + void write_lexer_settings (QsciLexer *lexer); #endif - void write_changed_settings (bool closing); + void read_settings (bool first); + + void write_changed_settings (); - void read_workspace_colors (gui_settings *settings); - void write_workspace_colors (gui_settings *settings); + void read_workspace_colors (); + void write_workspace_colors (); + + void read_terminal_colors (); + void write_terminal_colors (); - void read_terminal_colors (gui_settings *settings); - void write_terminal_colors (gui_settings *settings); + void read_varedit_colors (); + void write_varedit_colors (); + + QString get_shortcuts_file_name (import_export_action action); - void read_varedit_colors (gui_settings *settings); - void write_varedit_colors (gui_settings *settings); + QMessageBox* wait_message_box (const QString& test, QWidget *p); + void close_wait_message_box (QMessageBox *mbox); - base_qobject& m_octave_qobj; + bool overwrite_all_shortcuts (); color_picker *m_widget_title_bg_color; color_picker *m_widget_title_bg_color_active; diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/settings-dialog.ui --- a/libgui/src/settings-dialog.ui Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/settings-dialog.ui Fri May 12 08:03:14 2023 +0200 @@ -55,8 +55,8 @@ 0 0 - 1021 - 584 + 1035 + 573 @@ -869,7 +869,7 @@ 0 0 1021 - 1427 + 1404 @@ -2681,7 +2681,7 @@ 0 - + 0 @@ -2951,14 +2951,47 @@ - - - QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + <html><head/><body><p><span style=" font-weight:600;">Ok</span> - close dialog and apply settings<br><span style=" font-weight:600;">Apply - </span>apply settings but leave dialog open<br><span style=" font-weight:600;">Cancel - </span>close dialog and discard changes not yet applied<br><span style=" font-weight:600;">Reset -</span> reload settings discarding changes not yet applied</body></html> + + + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::Reset + + + + + + + octave::shortcuts_tree_widget + QTreeWidget +
shortcuts-tree-widget.h
+
+
diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/shortcut-manager.cc --- a/libgui/src/shortcut-manager.cc Fri May 12 08:00:41 2023 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,798 +0,0 @@ -//////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2014-2023 The Octave Project Developers -// -// See the file COPYRIGHT.md in the top-level directory of this -// distribution or . -// -// 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 -// . -// -//////////////////////////////////////////////////////////////////////// - -#if defined (HAVE_CONFIG_H) -# include "config.h" -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "octave-qobject.h" -#include "shortcut-manager.h" -#include "gui-preferences-global.h" -#include "gui-preferences-sc.h" -#include "error.h" - -OCTAVE_BEGIN_NAMESPACE(octave) - -// enter_shortcut: -// class derived from QLineEdit for directly entering key sequences which - -enter_shortcut::enter_shortcut (QWidget *p) : QLineEdit (p) -{ - m_direct_shortcut = true; // the shortcut is directly entered - m_shift_modifier = false; // the shift modifier is not added -} - -// new keyPressEvent -void enter_shortcut::keyPressEvent (QKeyEvent *e) -{ - if (! m_direct_shortcut) - { - QLineEdit::keyPressEvent (e); - return; - } - - if (e->type () == QEvent::KeyPress) - { - int key = e->key (); - - if (key == Qt::Key_unknown || key == 0) - return; - - Qt::KeyboardModifiers modifiers = QGuiApplication::keyboardModifiers (); //e->modifiers (); - - if (m_shift_modifier || (modifiers & Qt::ShiftModifier)) - key += Qt::SHIFT; - if (modifiers & Qt::ControlModifier) - key += Qt::CTRL; - if (modifiers & Qt::AltModifier) - key += Qt::ALT; - if (modifiers & Qt::MetaModifier) - key += Qt::META; - - setText (QKeySequence (key).toString ()); - } -} - -// slot for checkbox whether the shortcut is directly entered or not -void enter_shortcut::handle_direct_shortcut (int state) -{ - if (state) - m_direct_shortcut = true; // the shortcut is directly entered - else - m_direct_shortcut = false; // the shortcut has to be written as text -} - -// slot for checkbox whether the shift modifier should be added -void enter_shortcut::handle_shift_modifier (int state) -{ - if (state) - m_shift_modifier = true; // the shortcut is directly entered - else - m_shift_modifier = false; // the shortcut has to be written as text -} - -shortcut_manager::shortcut_manager (base_qobject& oct_qobj) - : m_octave_qobj (oct_qobj) -{ - setObjectName ("Shortcut_Manager"); - - // Mac: don't let Qt interpret CMD key ("Meta" in Qt terminology) as Ctrl -#if defined (Q_OS_MAC) - QCoreApplication::setAttribute (Qt::AA_MacDontSwapCtrlAndMeta, true); -#endif -} - -void shortcut_manager::init_data (void) -{ - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - - settings->setValue (sc_main_ctrld.key, false); // reset use fo ctrl-d - - // actions not related to specific menus or widgets - - // dock widgets - init (tr ("Undock/Dock Widget"), sc_dock_widget_dock); - init (tr ("Close Widget"), sc_dock_widget_close); - - // actions of the main window - - // file - init (tr ("New File"), sc_main_file_new_file); - init (tr ("New Function"), sc_main_file_new_function); - init (tr ("New Figure"), sc_main_file_new_figure); - init (tr ("Open File"), sc_main_file_open_file); - init (tr ("Load Workspace"), sc_main_file_load_workspace); - init (tr ("Save Workspace As"), sc_main_file_save_workspace); - init (tr ("Exit Octave"), sc_main_file_exit); - - // edit - init (tr ("Copy"), sc_main_edit_copy); - init (tr ("Paste"), sc_main_edit_paste); - init (tr ("Undo"), sc_main_edit_undo); - init (tr ("Select All"), sc_main_edit_select_all); - init (tr ("Clear Clipboard"), sc_main_edit_clear_clipboard); - init (tr ("Find in Files"), sc_main_edit_find_in_files); - init (tr ("Clear Command Window"), sc_main_edit_clear_command_window); - init (tr ("Clear Command History"), sc_main_edit_clear_history); - init (tr ("Clear Workspace"), sc_main_edit_clear_workspace); - init (tr ("Set Path"), sc_main_edit_set_path); - init (tr ("Preferences"), sc_main_edit_preferences); - - // debug - init (tr ("Step"), sc_main_debug_step_over); - init (tr ("Step Into"), sc_main_debug_step_into); - init (tr ("Step Out"), sc_main_debug_step_out); - init (tr ("Continue"), sc_main_debug_continue); - init (tr ("Quit Debug Mode"), sc_main_debug_quit); - - // tools - init (tr ("Start/Stop Profiler Session"), sc_main_tools_start_profiler); - init (tr ("Resume Profiler Session"), sc_main_tools_resume_profiler); - init (tr ("Show Profile Data"), sc_main_tools_show_profiler); - - // window - init (tr ("Show Command Window"), sc_main_window_show_command); - init (tr ("Show Command History"), sc_main_window_show_history); - init (tr ("Show File Browser"), sc_main_window_show_file_browser); - init (tr ("Show Workspace"), sc_main_window_show_workspace); - init (tr ("Show Editor"), sc_main_window_show_editor); - init (tr ("Show Documentation"), sc_main_window_show_doc); - init (tr ("Show Variable Editor"), sc_main_window_show_variable_editor); - init (tr ("Command Window"), sc_main_window_command); - init (tr ("Command History"), sc_main_window_history); - init (tr ("File Browser"), sc_main_window_file_browser); - init (tr ("Workspace"), sc_main_window_workspace); - init (tr ("Editor"), sc_main_window_editor); - init (tr ("Documentation"), sc_main_window_doc); - init (tr ("Variable Editor"), sc_main_window_variable_editor); - init (tr ("Previous Widget"), sc_main_window_previous_dock); - init (tr ("Reset Default Window Layout"), sc_main_window_reset); - - // help - init (tr ("Show On-disk Documentation"), sc_main_help_ondisk_doc); - init (tr ("Show Online Documentation"), sc_main_help_online_doc); - init (tr ("Report Bug"), sc_main_help_report_bug); - init (tr ("Octave Packages"), sc_main_help_packages); - init (tr ("Contribute to Octave"), sc_main_help_contribute); - init (tr ("Octave Developer Resources"), sc_main_help_developer); - init (tr ("About Octave"), sc_main_help_about); - - // news - init (tr ("Release Notes"), sc_main_news_release_notes); - init (tr ("Community News"), sc_main_news_community_news); - - // Tab handling - // The following shortcuts are moved into a separate tab. The key names - // are not changed, to preserve compatibility with older versions. - init (tr ("Close Tab"), sc_edit_file_close); - init (tr ("Close All Tabs"), sc_edit_file_close_all); - init (tr ("Close Other Tabs"), sc_edit_file_close_other); - init (tr ("Switch to Left Tab"), sc_edit_tabs_switch_left_tab); - init (tr ("Switch to Right Tab"), sc_edit_tabs_switch_right_tab); - init (tr ("Move Tab Left"), sc_edit_tabs_move_tab_left); - init (tr ("Move Tab Right"), sc_edit_tabs_move_tab_right); - - // Zooming - init (tr ("Zoom In"), sc_edit_view_zoom_in); - init (tr ("Zoom Out"), sc_edit_view_zoom_out); -#if defined (Q_OS_MAC) - init (tr ("Zoom Normal"), sc_edit_view_zoom_normal); -#else - init (tr ("Zoom Normal"), sc_edit_view_zoom_normal); -#endif - - // actions of the editor - - // file - init (tr ("Edit Function"), sc_edit_file_edit_function); - init (tr ("Save File"), sc_edit_file_save); - init (tr ("Save File As"), sc_edit_file_save_as); - init (tr ("Print"), sc_edit_file_print); - - // edit - init (tr ("Redo"), sc_edit_edit_redo); - init (tr ("Cut"), sc_edit_edit_cut); - init (tr ("Find and Replace"), sc_edit_edit_find_replace); - init (tr ("Find Next"), sc_edit_edit_find_next); - init (tr ("Find Previous"), sc_edit_edit_find_previous); - init (tr ("Delete to Start of Word"), sc_edit_edit_delete_start_word); - init (tr ("Delete to End of Word"), sc_edit_edit_delete_end_word); - init (tr ("Delete to Start of Line"), sc_edit_edit_delete_start_line); - init (tr ("Delete to End of Line"), sc_edit_edit_delete_end_line); - init (tr ("Delete Line"), sc_edit_edit_delete_line); - init (tr ("Copy Line"), sc_edit_edit_copy_line); - init (tr ("Cut Line"), sc_edit_edit_cut_line); - init (tr ("Duplicate Selection/Line"), sc_edit_edit_duplicate_selection); - init (tr ("Transpose Line"), sc_edit_edit_transpose_line); - init (tr ("Show Completion List"), sc_edit_edit_completion_list); - - init (tr ("Comment Selection"), sc_edit_edit_comment_selection); - init (tr ("Uncomment Selection"), sc_edit_edit_uncomment_selection); - init (tr ("Comment Selection (Choosing String)"), sc_edit_edit_comment_var_selection); - init (tr ("Uppercase Selection"), sc_edit_edit_upper_case); - init (tr ("Lowercase Selection"), sc_edit_edit_lower_case); - -#if defined (Q_OS_MAC) - init (tr ("Indent Selection Rigidly"), sc_edit_edit_indent_selection); - init (tr ("Unindent Selection Rigidly"), sc_edit_edit_unindent_selection); -#else - init (tr ("Indent Selection Rigidly"), sc_edit_edit_indent_selection); - init (tr ("Unindent Selection Rigidly"), sc_edit_edit_unindent_selection); -#endif - init (tr ("Indent Code"), sc_edit_edit_smart_indent_line_or_selection); - - init (tr ("Convert Line Endings to Windows"), sc_edit_edit_conv_eol_winows); - init (tr ("Convert Line Endings to Unix"), sc_edit_edit_conv_eol_unix); - init (tr ("Convert Line Endings to Mac"), sc_edit_edit_conv_eol_mac); - - init (tr ("Goto Line"), sc_edit_edit_goto_line); - init (tr ("Move to Matching Brace"), sc_edit_edit_move_to_brace); - init (tr ("Select to Matching Brace"), sc_edit_edit_select_to_brace); - init (tr ("Toggle Bookmark"), sc_edit_edit_toggle_bookmark); - init (tr ("Next Bookmark"), sc_edit_edit_next_bookmark); - init (tr ("Previous Bookmark"), sc_edit_edit_previous_bookmark); - init (tr ("Remove All Bookmark"), sc_edit_edit_remove_bookmark); - - init (tr ("Preferences"), sc_edit_edit_preferences); - init (tr ("Styles Preferences"), sc_edit_edit_styles_preferences); - - // view - init (tr ("Show Line Numbers"), sc_edit_view_show_line_numbers); - init (tr ("Show Whitespace Characters"), sc_edit_view_show_white_spaces); - init (tr ("Show Line Endings"), sc_edit_view_show_eol_chars); - init (tr ("Show Indentation Guides"), sc_edit_view_show_ind_guides); - init (tr ("Show Long Line Marker"), sc_edit_view_show_long_line); - init (tr ("Show Toolbar"), sc_edit_view_show_toolbar); - init (tr ("Show Statusbar"), sc_edit_view_show_statusbar); - init (tr ("Show Horizontal Scrollbar"), sc_edit_view_show_hscrollbar); - init (tr ("Sort Tabs Alphabetically"), sc_edit_view_sort_tabs); - - // debug - init (tr ("Toggle Breakpoint"), sc_edit_debug_toggle_breakpoint); - init (tr ("Next Breakpoint"), sc_edit_debug_next_breakpoint); - init (tr ("Previous Breakpoint"), sc_edit_debug_previous_breakpoint); - init (tr ("Remove All Breakpoints"), sc_edit_debug_remove_breakpoints); - - // run - init (tr ("Run File"), sc_edit_run_run_file); - init (tr ("Run Selection"), sc_edit_run_run_selection); - - // help - init (tr ("Help on Keyword"), sc_edit_help_help_keyword); - init (tr ("Document on Keyword"), sc_edit_help_doc_keyword); - - // Documentation browser - init (tr ("Go to Homepage"), sc_doc_go_home); - init (tr ("Go Back one Page"), sc_doc_go_back); - init (tr ("Go Forward one Page"), sc_doc_go_next); - init (tr ("Bookmark this Page"), sc_doc_bookmark); -} - -// write one or all actual shortcut set(s) into a settings file -void shortcut_manager::write_shortcuts (gui_settings *settings, - bool closing) -{ - bool sc_ctrld = false; - - QString sc_main = sc_main_file.mid (0, sc_main_file.indexOf ('_') + 1); - - for (int i = 0; i < m_sc.count (); i++) // loop over all shortcuts - { - settings->setValue (sc_group + "/" + m_sc.at (i).m_settings_key, - m_sc.at (i).m_actual_sc.toString ()); - // special: check main-window for Ctrl-D (Terminal) - if (m_sc.at (i).m_settings_key.startsWith (sc_main) - && m_sc.at (i).m_actual_sc == QKeySequence (Qt::ControlModifier+Qt::Key_D)) - sc_ctrld = true; - } - - settings->setValue (sc_main_ctrld.key, sc_ctrld); - - if (closing) - { - delete m_dialog; // the dialog for key sequences can be removed now - m_dialog = nullptr; // make sure it is zero again - } - - settings->sync (); // sync the settings file -} - -void shortcut_manager::set_shortcut (QAction *action, const sc_pref& scpref, - bool enable) -{ - if (! enable) - { - // Disable => remove existing shortcut from the action - action->setShortcut (QKeySequence ()); - return; - } - - // Enable: Is the given key known? If yes, get the value from the - // settings file and set it to the action - int index; - - index = m_action_hash[scpref.key] - 1; - - if (index > -1 && index < m_sc.count ()) - { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - action->setShortcut (QKeySequence (settings->sc_value (scpref))); - } - else - qDebug () << "Key: " << scpref.key << " not found in m_action_hash"; -} - -void shortcut_manager::shortcut (QShortcut *sc, const sc_pref& scpref) -{ - int index; - - index = m_action_hash[scpref.key] - 1; - - if (index > -1 && index < m_sc.count ()) - { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - sc->setKey (QKeySequence (settings->sc_value (scpref))); - } - else - qDebug () << "Key: " << scpref.key << " not found in m_action_hash"; -} - -void shortcut_manager::fill_treewidget (QTreeWidget *tree_view) -{ - m_dialog = nullptr; - m_level_hash.clear (); - - tree_view->header ()->setSectionResizeMode (QHeaderView::ResizeToContents); - - QTreeWidgetItem *main = new QTreeWidgetItem (tree_view); - main->setText (0, tr ("Global")); - main->setExpanded (true); - QTreeWidgetItem *main_file = new QTreeWidgetItem (main); - main_file->setText (0, tr ("File Menu")); - QTreeWidgetItem *main_edit = new QTreeWidgetItem (main); - main_edit->setText (0, tr ("Edit Menu")); - QTreeWidgetItem *main_debug = new QTreeWidgetItem (main); - main_debug->setText (0, tr ("Debug Menu")); - QTreeWidgetItem *main_tools = new QTreeWidgetItem (main); - main_tools->setText (0, tr ("Tools Menu")); - QTreeWidgetItem *main_window = new QTreeWidgetItem (main); - main_window->setText (0, tr ("Window Menu")); - QTreeWidgetItem *main_help = new QTreeWidgetItem (main); - main_help->setText (0, tr ("Help Menu")); - QTreeWidgetItem *main_news = new QTreeWidgetItem (main); - main_news->setText (0, tr ("News Menu")); - QTreeWidgetItem *main_dock_widgets = new QTreeWidgetItem (main); - main_dock_widgets->setText (0, tr ("Handling of Dock Widgets")); - QTreeWidgetItem *main_tabs = new QTreeWidgetItem (main); - main_tabs->setText (0, tr ("Tab Handling in Dock Widgets")); - QTreeWidgetItem *main_find = new QTreeWidgetItem (main); - main_find->setText (0, tr ("Find & Replace in Dock Widgets")); - QTreeWidgetItem *main_zoom = new QTreeWidgetItem (main); - main_zoom->setText (0, tr ("Zooming in Editor and Documentation")); - - m_level_hash[sc_main_file] = main_file; - m_level_hash[sc_main_edit] = main_edit; - m_level_hash[sc_main_debug] = main_debug; - m_level_hash[sc_main_tools] = main_tools; - m_level_hash[sc_main_window] = main_window; - m_level_hash[sc_main_help] = main_help; - m_level_hash[sc_main_news] = main_news; - m_level_hash[sc_dock_widget] = main_dock_widgets; - m_level_hash[sc_edit_tabs] = main_tabs; - m_level_hash[sc_edit_find] = main_find; - m_level_hash[sc_edit_zoom] = main_zoom; - - QTreeWidgetItem *editor = new QTreeWidgetItem (tree_view); - editor->setText (0, tr ("Editor")); - editor->setExpanded (true); - QTreeWidgetItem *editor_file = new QTreeWidgetItem (editor); - editor_file->setText (0, tr ("File Menu")); - QTreeWidgetItem *editor_edit = new QTreeWidgetItem (editor); - editor_edit->setText (0, tr ("Edit Menu")); - QTreeWidgetItem *editor_view = new QTreeWidgetItem (editor); - editor_view->setText (0, tr ("View Menu")); - QTreeWidgetItem *editor_debug = new QTreeWidgetItem (editor); - editor_debug->setText (0, tr ("Debug Menu")); - QTreeWidgetItem *editor_run = new QTreeWidgetItem (editor); - editor_run->setText (0, tr ("Run Menu")); - QTreeWidgetItem *editor_help = new QTreeWidgetItem (editor); - editor_help->setText (0, tr ("Help Menu")); - - m_level_hash[sc_edit_file] = editor_file; - m_level_hash[sc_edit_edit] = editor_edit; - m_level_hash[sc_edit_view] = editor_view; - m_level_hash[sc_edit_debug] = editor_debug; - m_level_hash[sc_edit_run] = editor_run; - m_level_hash[sc_edit_help] = editor_help; - - QTreeWidgetItem *doc = new QTreeWidgetItem (tree_view); - doc->setText (0, tr ("Documentation Viewer")); - doc->setExpanded (true); - - QTreeWidgetItem *doc_browser = new QTreeWidgetItem (doc); - doc_browser->setText (0, tr ("Browser")); - - m_level_hash[sc_doc] = doc_browser; - - connect (tree_view, &QTreeWidget::itemDoubleClicked, - this, &shortcut_manager::handle_double_clicked); - - for (int i = 0; i < m_sc.count (); i++) - { - shortcut_t sc = m_sc.at (i); - - QTreeWidgetItem *section = m_level_hash[sc.m_settings_key.section (':', 0, 0)]; - - // handle sections which have changed and do not correspond to the - // previously defined keyname - if (section == editor_file) - { - // Closing tabs now in global tab handling section - if (sc.m_settings_key.contains (sc_edit_file_cl)) - section = main_tabs; - } - if (section == editor_edit) - { - // Find & replace now in global file & replace handling section - if (sc.m_settings_key.contains (sc_edit_edit_find)) - section = main_find; - } - if (section == editor_view) - { - // Zooming now in global zoom handling section - if (sc.m_settings_key.contains (sc_edit_view_zoom)) - section = main_zoom; - } - - QTreeWidgetItem *tree_item = new QTreeWidgetItem (section); - - // set a slightly transparent foreground for default columns - QColor fg = QColor (tree_item->foreground (1).color ()); - fg.setAlpha (128); - tree_item->setForeground (1, QBrush (fg)); - - // write the shortcuts - tree_item->setText (0, sc.m_description); - tree_item->setText (1, sc.m_default_sc.toString ()); - tree_item->setText (2, sc.m_actual_sc.toString ()); - - m_item_index_hash[tree_item] = i + 1; // index+1 to avoid 0 - m_index_item_hash[i] = tree_item; - } -} - -// import or export of shortcut sets, -// called from settings dialog when related buttons are clicked; -// returns true on success, false otherwise -bool -shortcut_manager::import_export (int action) -{ - // ask to save the current shortcuts, maybe abort import - if (action == OSC_DEFAULT || action == OSC_IMPORT) - { - if (! overwrite_all_shortcuts ()) - return false; - } - - // get the filename to read or write the shortcuts, - // the default extension is .osc (octave shortcuts) - if (action != OSC_DEFAULT) - { - QString file; - - // FIXME: Remove, if for all common KDE versions (bug #54607) is resolved. - int opts = 0; // No options by default. - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - if (! settings->value (global_use_native_dialogs).toBool ()) - opts = QFileDialog::DontUseNativeDialog; - - if (action == OSC_IMPORT) - file = QFileDialog::getOpenFileName (this, - tr ("Import shortcuts from file..."), QString (), - tr ("Octave Shortcut Files (*.osc);;All Files (*)"), - nullptr, QFileDialog::Option (opts)); - else if (action == OSC_EXPORT) - file = QFileDialog::getSaveFileName (this, - tr ("Export shortcuts to file..."), QString (), - tr ("Octave Shortcut Files (*.osc);;All Files (*)"), - nullptr, QFileDialog::Option (opts)); - - if (file.isEmpty ()) - return false; - - gui_settings osc_settings (file, QSettings::IniFormat); - - if (osc_settings.status () != QSettings::NoError) - { - qWarning () << tr ("Failed to open %1 as Octave shortcut file") - .arg (file); - return false; - } - else - { - if (action == OSC_IMPORT) - import_shortcuts (&osc_settings); // import (special action) - else if (action == OSC_EXPORT) - write_shortcuts (&osc_settings, false); // export, (save settings) - } - } - else - { - import_shortcuts (nullptr); - } - - return true; -} - -void shortcut_manager::handle_double_clicked (QTreeWidgetItem *item, int col) -{ - if (col != 2) - return; - - int i = m_item_index_hash[item]; - if (i == 0) - return; // top-level-item clicked - - shortcut_dialog (i-1); // correct to index starting at 0 -} - -void shortcut_manager::shortcut_dialog_finished (int result) -{ - if (result == QDialog::Rejected) - return; - - // check for duplicate - int double_index = m_shortcut_hash[m_edit_actual->text ()] - 1; - - if (double_index >= 0 && double_index != m_handled_index) - { - int ret = QMessageBox::warning (this, tr ("Double Shortcut"), - tr ("The chosen shortcut\n \"%1\"\n" - "is already used for the action\n \"%2\".\n" - "Do you want to use the shortcut anyhow removing it " - "from the previous action?") - .arg (m_edit_actual->text ()) - .arg (m_sc.at (double_index).m_description), - QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); - - if (ret == QMessageBox::Yes) - { - shortcut_t double_shortcut = m_sc.at (double_index); - double_shortcut.m_actual_sc = QKeySequence (); - m_sc.replace (double_index, double_shortcut); - m_index_item_hash[double_index]->setText (2, QString ()); - } - else - return; - } - - shortcut_t shortcut = m_sc.at (m_handled_index); - if (! shortcut.m_actual_sc.isEmpty ()) - m_shortcut_hash.remove (shortcut.m_actual_sc.toString ()); - shortcut.m_actual_sc = m_edit_actual->text (); - m_sc.replace (m_handled_index, shortcut); - - m_index_item_hash[m_handled_index]->setText (2, shortcut.m_actual_sc.toString ()); - - if (! shortcut.m_actual_sc.isEmpty ()) - m_shortcut_hash[shortcut.m_actual_sc.toString ()] = m_handled_index + 1; -} - -void shortcut_manager::shortcut_dialog_set_default (void) -{ - m_edit_actual->setText (m_label_default->text ()); -} - -void shortcut_manager::init (const QString& description, const sc_pref& sc) -{ - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - - QKeySequence actual = QKeySequence (settings->sc_value (sc)); - - // append the new shortcut to the list - shortcut_t shortcut_info; - shortcut_info.m_description = description; - shortcut_info.m_settings_key = sc.key; - shortcut_info.m_actual_sc = actual; - shortcut_info.m_default_sc = settings->sc_def_value (sc); - m_sc << shortcut_info; - - // insert shortcut in order to check for duplicates later - if (! actual.isEmpty ()) - m_shortcut_hash[actual.toString ()] = m_sc.count (); - m_action_hash[sc.key] = m_sc.count (); - - // check whether ctrl+d is used from main window, i.e. is a global shortcut - QString main_group_prefix - = sc_main_file.mid (0, sc_main_file.indexOf ('_') + 1); - if (sc.key.startsWith (main_group_prefix) - && actual == QKeySequence (Qt::ControlModifier+Qt::Key_D)) - settings->setValue (sc_main_ctrld.key, true); -} - -void shortcut_manager::shortcut_dialog (int index) -{ - if (! m_dialog) - { - m_dialog = new QDialog (this); - - m_dialog->setWindowTitle (tr ("Enter new Shortcut")); - - QVBoxLayout *box = new QVBoxLayout (m_dialog); - box->setSpacing (2); - box->setContentsMargins (12, 12, 12, 12); - - QLabel *help = new QLabel (tr ("Apply the desired shortcut or click " - "on the right button to reset the " - "shortcut to its default.")); - help->setWordWrap (true); - box->addWidget (help); - - QCheckBox *direct - = new QCheckBox (tr ("Enter shortcut directly by performing it")); - - QCheckBox *shift - = new QCheckBox (tr ("Add Shift modifier\n" - "(allows one to enter number keys)")); - - shift->setStyleSheet - ("QCheckBox::indicator { subcontrol-position: left top; }"); - - connect (direct, &QCheckBox::clicked, shift, &QCheckBox::setEnabled); - - direct->setCheckState (Qt::Checked); - - box->addWidget (direct); - box->addWidget (shift); - - box->addSpacing (15); - - QGridLayout *grid = new QGridLayout (); - - QLabel *actual = new QLabel (tr ("Actual shortcut")); - m_edit_actual = new enter_shortcut (m_dialog); - m_edit_actual->setAlignment (Qt::AlignHCenter); - grid->addWidget (actual, 0, 0); - grid->addWidget (m_edit_actual, 0, 1); - - QLabel *def = new QLabel (tr ("Default shortcut")); - m_label_default = new QLabel (m_dialog); - m_label_default->setAlignment (Qt::AlignHCenter); - grid->addWidget (def, 1, 0); - grid->addWidget (m_label_default, 1, 1); - - QPushButton *set_default = new QPushButton (tr ("Set to default")); - grid->addWidget (set_default, 0, 2); - connect (set_default, &QPushButton::clicked, - this, &shortcut_manager::shortcut_dialog_set_default); - - box->addLayout (grid); - - box->addSpacing (18); - - QDialogButtonBox *button_box = new QDialogButtonBox (QDialogButtonBox::Ok - | QDialogButtonBox::Cancel); - QList buttons = button_box->buttons (); - for (int i = 0; i < buttons.count (); i++) - buttons.at (i)->setShortcut (QKeySequence ()); - connect (button_box, &QDialogButtonBox::accepted, - m_dialog, &QDialog::accept); - connect (button_box, &QDialogButtonBox::rejected, - m_dialog, &QDialog::reject); - box->addWidget (button_box); - - m_dialog->setLayout (box); - - connect (direct, &QCheckBox::stateChanged, - m_edit_actual, &enter_shortcut::handle_direct_shortcut); - connect (shift, &QCheckBox::stateChanged, - m_edit_actual, &enter_shortcut::handle_shift_modifier); - connect (m_dialog, &QDialog::finished, - this, &shortcut_manager::shortcut_dialog_finished); - - } - - m_edit_actual->setText (m_sc.at (index).m_actual_sc.toString ()); - m_label_default->setText (m_sc.at (index).m_default_sc.toString ()); - m_handled_index = index; - - m_edit_actual->setFocus (); - m_dialog->setFocusProxy (m_edit_actual); - m_dialog->exec (); -} - -// import a shortcut set from a given settings file or reset to -// the defaults (settings = 0) and refresh the tree view -void shortcut_manager::import_shortcuts (gui_settings *settings) -{ - for (int i = 0; i < m_sc.count (); i++) - { - // update the list of all shortcuts - shortcut_t sc = m_sc.at (i); // make a copy - - if (settings) - sc.m_actual_sc = QKeySequence ( // get new shortcut from settings - settings->value (sc_group + sc.m_settings_key,sc.m_actual_sc). - toString ()); // and use the old one as default - else - sc.m_actual_sc = QKeySequence (sc.m_default_sc); // get default shortcut - - m_sc.replace (i, sc); // replace the old with the new one - - // update the tree view - QTreeWidgetItem *tree_item = m_index_item_hash[i]; // get related tree item - tree_item->setText (2, sc.m_actual_sc.toString ()); // display new shortcut - } -} - -// ask the user whether to save the current shortcut set; -// returns true to proceed with import action, false to abort it -bool shortcut_manager::overwrite_all_shortcuts (void) -{ - QMessageBox msg_box; - msg_box.setWindowTitle (tr ("Overwriting Shortcuts")); - msg_box.setIcon (QMessageBox::Warning); - msg_box.setText (tr ("You are about to overwrite all shortcuts.\n" - "Would you like to save the current shortcut set or cancel the action?")); - msg_box.setStandardButtons (QMessageBox::Save | QMessageBox::Cancel); - QPushButton *discard = msg_box.addButton (tr ("Don't save"), - QMessageBox::DestructiveRole); - msg_box.setDefaultButton (QMessageBox::Save); - - int ret = msg_box.exec (); - - if (msg_box.clickedButton () == discard) - return true; // do not save and go ahead - - if (ret == QMessageBox::Save) - { - if (import_export (OSC_EXPORT)) - return true; // go ahead - } - - return false; // abort the import -} - -OCTAVE_END_NAMESPACE(octave) diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/shortcut-manager.h --- a/libgui/src/shortcut-manager.h Fri May 12 08:00:41 2023 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,175 +0,0 @@ -//////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2014-2023 The Octave Project Developers -// -// See the file COPYRIGHT.md in the top-level directory of this -// distribution or . -// -// 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 -// . -// -//////////////////////////////////////////////////////////////////////// - -#if ! defined (octave_shortcut_manager_h) -#define octave_shortcut_manager_h 1 - -#include -#include -#include -#include -#include -#include - -#include "gui-settings.h" - -OCTAVE_BEGIN_NAMESPACE(octave) - -class enter_shortcut : public QLineEdit -{ - Q_OBJECT - -public: - - enter_shortcut (QWidget *p = nullptr); - - ~enter_shortcut (void) = default; - - virtual void keyPressEvent (QKeyEvent *e); - -public slots: - - void handle_direct_shortcut (int); - void handle_shift_modifier (int); - -private: - - bool m_direct_shortcut; - bool m_shift_modifier; - -}; - -class base_qobject; - -class shortcut_manager : public QWidget -{ - Q_OBJECT - -public: - - enum - { - OSC_IMPORT = 0, - OSC_EXPORT = 1, - OSC_DEFAULT = 2 - }; - - shortcut_manager (base_qobject& oct_qobj); - - // No copying! - - shortcut_manager (const shortcut_manager&) = delete; - - shortcut_manager& operator = (const shortcut_manager&) = delete; - - ~shortcut_manager (void) = default; - - void init_data (void); - - void write_shortcuts (gui_settings *settings, bool closing); - - void set_shortcut (QAction *action, const sc_pref& scpref, bool enable = true); - - void shortcut (QShortcut *sc, const sc_pref& scpref); - - void fill_treewidget (QTreeWidget *tree_view); - - bool import_export (int action); - -protected slots: - - void handle_double_clicked (QTreeWidgetItem *, int); - void shortcut_dialog_finished (int); - void shortcut_dialog_set_default (); - -private: - - void init (const QString&, const sc_pref& scpref); - void shortcut_dialog (int); - void import_shortcuts (gui_settings *settings); - bool overwrite_all_shortcuts (void); - - class shortcut_t - { - public: - - shortcut_t (void) - : m_tree_item (nullptr), m_description (), m_settings_key (), - m_actual_sc (QKeySequence ()), m_default_sc (QKeySequence ()) - { } - - shortcut_t (const shortcut_t& x) - : m_tree_item (x.m_tree_item), m_description (x.m_description), - m_settings_key (x.m_settings_key) - { - m_actual_sc = x.m_actual_sc; - m_default_sc = x.m_default_sc; - } - - shortcut_t& operator = (const shortcut_t& x) - { - if (&x != this) - { - m_tree_item = x.m_tree_item; - m_description = x.m_description; - m_settings_key = x.m_settings_key; - - m_actual_sc = QKeySequence (); - m_default_sc = QKeySequence (); - - m_actual_sc = x.m_actual_sc; - m_default_sc = x.m_default_sc; - } - - return *this; - } - - ~shortcut_t (void) = default; - - QTreeWidgetItem *m_tree_item; - QString m_description; - QString m_settings_key; - QKeySequence m_actual_sc; - QKeySequence m_default_sc; - }; - - base_qobject& m_octave_qobj; - - QList m_sc; - QHash m_shortcut_hash; - QHash m_action_hash; - QHash m_level_hash; - QHash m_index_item_hash; - QHash m_item_index_hash; - - QDialog *m_dialog; - enter_shortcut *m_edit_actual; - QLabel *m_label_default; - int m_handled_index; -}; - -OCTAVE_END_NAMESPACE(octave) - -#endif diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/shortcuts-tree-widget.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/shortcuts-tree-widget.cc Fri May 12 08:03:14 2023 +0200 @@ -0,0 +1,712 @@ +//////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2014-2023 The Octave Project Developers +// +// See the file COPYRIGHT.md in the top-level directory of this +// distribution or . +// +// 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 +// . +// +//////////////////////////////////////////////////////////////////////// + +#if defined (HAVE_CONFIG_H) +# include "config.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "gui-preferences-sc.h" +#include "gui-settings.h" +#include "shortcuts-tree-widget.h" + +OCTAVE_BEGIN_NAMESPACE(octave) + +// enter_shortcut: +// class derived from QLineEdit for directly entering key sequences which + +enter_shortcut::enter_shortcut (QWidget *p) : QLineEdit (p) +{ + m_direct_shortcut = true; // the shortcut is directly entered + m_shift_modifier = false; // the shift modifier is not added +} + +// new keyPressEvent +void enter_shortcut::keyPressEvent (QKeyEvent *e) +{ + if (! m_direct_shortcut) + { + QLineEdit::keyPressEvent (e); + return; + } + + if (e->type () == QEvent::KeyPress) + { + int key = e->key (); + + if (key == Qt::Key_unknown || key == 0) + return; + + Qt::KeyboardModifiers modifiers = QGuiApplication::keyboardModifiers (); //e->modifiers (); + + if (m_shift_modifier || (modifiers & Qt::ShiftModifier)) + key |= Qt::SHIFT; + if (modifiers & Qt::ControlModifier) + key |= Qt::CTRL; + if (modifiers & Qt::AltModifier) + key |= Qt::ALT; + if (modifiers & Qt::MetaModifier) + key |= Qt::META; + + setText (QKeySequence (key).toString ()); + } +} + +// slot for checkbox whether the shortcut is directly entered or not +void enter_shortcut::handle_direct_shortcut (int state) +{ + if (state) + m_direct_shortcut = true; // the shortcut is directly entered + else + m_direct_shortcut = false; // the shortcut has to be written as text +} + +// slot for checkbox whether the shift modifier should be added +void enter_shortcut::handle_shift_modifier (int state) +{ + if (state) + m_shift_modifier = true; // the shortcut is directly entered + else + m_shift_modifier = false; // the shortcut has to be written as text +} + +tree_widget_shortcut_item::tree_widget_shortcut_item +(QTreeWidgetItem *parent, const sc_pref& scpref, const QString& actual_text) + : QTreeWidgetItem (parent), m_settings_key (scpref.settings_key ()) +{ + // set a slightly transparent foreground for default columns + QColor fg = QColor (foreground (DEFAULT_COLUMN).color ()); + fg.setAlpha (128); + setForeground (DEFAULT_COLUMN, QBrush (fg)); + + // write the shortcuts + set_description (scpref.description ()); + set_default_text (scpref.def_text ()); + set_actual_text (actual_text); +} + +QString tree_widget_shortcut_item::settings_key () const +{ + return m_settings_key; +} + +QString tree_widget_shortcut_item::description () const +{ + return text (DESCRIPTION_COLUMN); +} + +void tree_widget_shortcut_item::set_description (const QString& text) +{ + setText (DESCRIPTION_COLUMN, text); +} + +QString tree_widget_shortcut_item::default_text () const +{ + return text (DEFAULT_COLUMN); +} + +void tree_widget_shortcut_item::set_default_text (const QString& text) +{ + setText (DEFAULT_COLUMN, text); +} + +QString tree_widget_shortcut_item::actual_text () const +{ + return text (ACTUAL_COLUMN); +} + +void tree_widget_shortcut_item::set_actual_text (const QString& text) +{ + setText (ACTUAL_COLUMN, text); +} + +shortcut_edit_dialog::shortcut_edit_dialog + (tree_widget_shortcut_item *shortcut_item, QWidget *parent) + : QDialog (parent), m_shortcut_item (shortcut_item), + m_settings_key (shortcut_item->settings_key ()) +{ + setAttribute (Qt::WA_DeleteOnClose); + + setWindowTitle (tr ("Enter new Shortcut")); + + QVBoxLayout *box = new QVBoxLayout (this); + + box->setSpacing (2); + box->setContentsMargins (12, 12, 12, 12); + + QLabel *help = new QLabel (tr ("Apply the desired shortcut or click " + "on the right button to reset the " + "shortcut to its default. (%1)") + .arg (m_settings_key)); + + help->setWordWrap (true); + + box->addWidget (help); + + QCheckBox *direct + = new QCheckBox (tr ("Enter shortcut directly by performing it")); + + QCheckBox *shift + = new QCheckBox (tr ("Add Shift modifier\n" + "(allows one to enter number keys)")); + + shift->setStyleSheet + ("QCheckBox::indicator { subcontrol-position: left top; }"); + + connect (direct, &QCheckBox::clicked, shift, &QCheckBox::setEnabled); + + direct->setCheckState (Qt::Checked); + + box->addWidget (direct); + box->addWidget (shift); + + box->addSpacing (15); + + QGridLayout *grid = new QGridLayout (); + + QLabel *actual = new QLabel (tr ("Actual shortcut")); + + m_edit_actual = new enter_shortcut (this); + m_edit_actual->setAlignment (Qt::AlignHCenter); + + grid->addWidget (actual, 0, 0); + grid->addWidget (m_edit_actual, 0, 1); + + QLabel *def = new QLabel (tr ("Default shortcut")); + + QLabel *label_default = new QLabel (this); + label_default->setAlignment (Qt::AlignHCenter); + + grid->addWidget (def, 1, 0); + grid->addWidget (label_default, 1, 1); + + QPushButton *set_default = new QPushButton (tr ("Set to default")); + + connect (set_default, &QPushButton::clicked, + this, &shortcut_edit_dialog::set_default_shortcut); + + grid->addWidget (set_default, 0, 2); + + box->addLayout (grid); + box->addSpacing (18); + + QDialogButtonBox *button_box = new QDialogButtonBox (QDialogButtonBox::Ok + | QDialogButtonBox::Cancel); + QList buttons = button_box->buttons (); + for (int i = 0; i < buttons.count (); i++) + buttons.at (i)->setShortcut (QKeySequence ()); + + connect (button_box, &QDialogButtonBox::accepted, + this, &QDialog::accept); + + connect (button_box, &QDialogButtonBox::rejected, + this, &QDialog::reject); + + box->addWidget (button_box); + + setLayout (box); + + connect (direct, &QCheckBox::stateChanged, + m_edit_actual, &enter_shortcut::handle_direct_shortcut); + + connect (shift, &QCheckBox::stateChanged, + m_edit_actual, &enter_shortcut::handle_shift_modifier); + + connect (this, &QDialog::finished, + this, &shortcut_edit_dialog::finished); + + gui_settings settings; + + const sc_pref scpref = all_shortcut_preferences::value (m_settings_key); + + QString actual_text = settings.sc_value (scpref); + + m_default_text = scpref.def_text (); + + m_edit_actual->setText (actual_text); + label_default->setText (m_default_text); + + m_edit_actual->setFocus (); + + setFocusProxy (m_edit_actual); +} + +void shortcut_edit_dialog::finished (int result) +{ + if (result == QDialog::Rejected) + return; + + // Check whether the chosen shortcut is already in use either in the + // current context (section of the shortcut settings) or as a global + // (main_) shortcut. This job might have been easier if we had + // organized the sections as child groups instead of using a colon in + // the settings key to separate the section from the shortcut name. + + // Note that m_settings_key doesn't begin with the sc_group prefix. + + QString my_section = get_shortcut_section (m_settings_key); + QString actual_text = m_edit_actual->text (); + + bool conflict = false; + QString other_settings_key; + + gui_settings settings; + + settings.beginGroup (sc_group); + const QStringList shortcut_settings_keys = settings.allKeys (); + settings.endGroup (); + + for (const auto& settings_key : shortcut_settings_keys) + { + if (settings_key == m_settings_key) + continue; + + QString section = get_shortcut_section (settings_key); + + if (section == my_section || section.startsWith ("main_")) + { + QString shortcut_text + = settings.value (sc_group + "/" + settings_key).toString (); + + if (shortcut_text == actual_text) + { + other_settings_key = settings_key; + conflict = true; + } + } + } + + if (conflict) + { + // We only need the description of the other shortcut, not the + // complete sc_pref info. + + const sc_pref other_scpref + = all_shortcut_preferences::value (other_settings_key); + + int ret = QMessageBox::warning (this, tr ("Double Shortcut"), + tr ("The chosen shortcut\n \"%1\"\n" + "is already used for the action\n \"%2\".\n" + "Do you want to use the shortcut and remove it " + "from the previous action?") + .arg (actual_text) + .arg (other_scpref.description ()), + QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); + + if (ret == QMessageBox::Yes) + emit set_shortcut (other_settings_key, ""); + else + return; + } + + m_shortcut_item->set_actual_text (actual_text); +} + +void shortcut_edit_dialog::set_default_shortcut () +{ + // Just remove user-set value so that the default will be used. + m_edit_actual->setText (""); +} + +shortcuts_tree_widget::shortcuts_tree_widget (QWidget *parent) + : QTreeWidget (parent) +{ + QHash level_hash; + + header ()->setSectionResizeMode (QHeaderView::ResizeToContents); + + int dsc_col = tree_widget_shortcut_item::DESCRIPTION_COLUMN; + + QTreeWidgetItem *main = new QTreeWidgetItem (this); + main->setText (dsc_col, tr ("Global")); + main->setExpanded (true); + + QTreeWidgetItem *main_file = new QTreeWidgetItem (main); + main_file->setText (dsc_col, tr ("File Menu")); + + QTreeWidgetItem *main_edit = new QTreeWidgetItem (main); + main_edit->setText (dsc_col, tr ("Edit Menu")); + + QTreeWidgetItem *main_debug = new QTreeWidgetItem (main); + main_debug->setText (dsc_col, tr ("Debug Menu")); + + QTreeWidgetItem *main_tools = new QTreeWidgetItem (main); + main_tools->setText (dsc_col, tr ("Tools Menu")); + + QTreeWidgetItem *main_window = new QTreeWidgetItem (main); + main_window->setText (dsc_col, tr ("Window Menu")); + + QTreeWidgetItem *main_help = new QTreeWidgetItem (main); + main_help->setText (dsc_col, tr ("Help Menu")); + + QTreeWidgetItem *main_news = new QTreeWidgetItem (main); + main_news->setText (dsc_col, tr ("News Menu")); + + QTreeWidgetItem *main_dock_widgets = new QTreeWidgetItem (main); + main_dock_widgets->setText (dsc_col, tr ("Handling of Dock Widgets")); + + QTreeWidgetItem *main_tabs = new QTreeWidgetItem (main); + main_tabs->setText (dsc_col, tr ("Tab Handling in Dock Widgets")); + + QTreeWidgetItem *main_find = new QTreeWidgetItem (main); + main_find->setText (dsc_col, tr ("Find & Replace in Dock Widgets")); + + QTreeWidgetItem *main_zoom = new QTreeWidgetItem (main); + main_zoom->setText (dsc_col, tr ("Zooming in Editor and Documentation")); + + level_hash[sc_main_file] = main_file; + level_hash[sc_main_edit] = main_edit; + level_hash[sc_main_debug] = main_debug; + level_hash[sc_main_tools] = main_tools; + level_hash[sc_main_window] = main_window; + level_hash[sc_main_help] = main_help; + level_hash[sc_main_news] = main_news; + level_hash[sc_dock_widget] = main_dock_widgets; + level_hash[sc_edit_tabs] = main_tabs; + level_hash[sc_edit_find] = main_find; + level_hash[sc_edit_zoom] = main_zoom; + + QTreeWidgetItem *editor = new QTreeWidgetItem (this); + editor->setText (dsc_col, tr ("Editor")); + editor->setExpanded (true); + + QTreeWidgetItem *editor_file = new QTreeWidgetItem (editor); + editor_file->setText (dsc_col, tr ("File Menu")); + + QTreeWidgetItem *editor_edit = new QTreeWidgetItem (editor); + editor_edit->setText (dsc_col, tr ("Edit Menu")); + + QTreeWidgetItem *editor_view = new QTreeWidgetItem (editor); + editor_view->setText (dsc_col, tr ("View Menu")); + + QTreeWidgetItem *editor_debug = new QTreeWidgetItem (editor); + editor_debug->setText (dsc_col, tr ("Debug Menu")); + + QTreeWidgetItem *editor_run = new QTreeWidgetItem (editor); + editor_run->setText (dsc_col, tr ("Run Menu")); + + QTreeWidgetItem *editor_help = new QTreeWidgetItem (editor); + editor_help->setText (dsc_col, tr ("Help Menu")); + + level_hash[sc_edit_file] = editor_file; + level_hash[sc_edit_edit] = editor_edit; + level_hash[sc_edit_view] = editor_view; + level_hash[sc_edit_debug] = editor_debug; + level_hash[sc_edit_run] = editor_run; + level_hash[sc_edit_help] = editor_help; + + QTreeWidgetItem *doc = new QTreeWidgetItem (this); + doc->setText (dsc_col, tr ("Documentation Viewer")); + doc->setExpanded (true); + + QTreeWidgetItem *doc_browser = new QTreeWidgetItem (doc); + doc_browser->setText (dsc_col, tr ("Browser")); + + level_hash[sc_doc] = doc_browser; + + connect (this, &QTreeWidget::itemDoubleClicked, + this, &shortcuts_tree_widget::edit_selection); + + const QList shortcut_settings_keys + = all_shortcut_preferences::keys (); + + gui_settings settings; + + settings.beginGroup (sc_group); + + for (const auto& settings_key : shortcut_settings_keys) + { + QTreeWidgetItem *section = level_hash[settings_key.section (':', 0, 0)]; + + // handle sections which have changed and do not correspond to the + // previously defined keyname + if (section == editor_file) + { + // Closing tabs now in global tab handling section + if (settings_key.contains (sc_edit_file_cl)) + section = main_tabs; + } + else if (section == editor_edit) + { + // Find & replace now in global file & replace handling section + if (settings_key.contains (sc_edit_edit_find)) + section = main_find; + } + else if (section == editor_view) + { + // Zooming now in global zoom handling section + if (settings_key.contains (sc_edit_view_zoom)) + section = main_zoom; + } + + // We don't want to apply default value here. + QString actual_text = settings.value (settings_key).toString (); + + const sc_pref scpref = all_shortcut_preferences::value (settings_key); + + // Inserts itself in the tree widget in SECTION. The parent + // object will delete it. + new tree_widget_shortcut_item (section, scpref, actual_text); + } + + settings.endGroup (); +} + +void +shortcuts_tree_widget::edit_selection (QTreeWidgetItem *item, int col) +{ + if (col != 2) + return; + + tree_widget_shortcut_item *shortcut_item + = dynamic_cast (item); + + if (! shortcut_item) + return; // top-level-item clicked + + shortcut_edit_dialog *dialog + = new shortcut_edit_dialog (shortcut_item); + + connect (dialog, &shortcut_edit_dialog::set_shortcut, + this, &shortcuts_tree_widget::update_widget_value); + + dialog->show (); +} + +void shortcuts_tree_widget::update_widget_value (const QString& settings_key, + const QString& sc_text) +{ + tree_widget_shortcut_item *item = get_item (settings_key); + + if (item) + item->set_actual_text (sc_text); +} + +tree_widget_shortcut_item * +shortcuts_tree_widget::get_item (const QString& settings_key) +{ + // There aren't many shortcuts so iterating over all of them to find + // an individual item isn't a big performance issue. If we had many + // more items we could use a QHash data member. + + tree_widget_shortcut_item *item = nullptr; + + QTreeWidgetItemIterator it (this, QTreeWidgetItemIterator::NoChildren); + while (*it) + { + tree_widget_shortcut_item *shortcut_item + = dynamic_cast (*it); + + if (settings_key == shortcut_item->settings_key ()) + { + item = shortcut_item; + break; + } + + it++; + } + + // FIXME: Should it be an error to not find a match? + + if (! item) + qWarning () << (tr ("item %1 not found in shortcut settings dialog") + .arg (settings_key)); + + return item; +} + +void shortcuts_tree_widget::update_settings_value (gui_settings& settings, + const QString& settings_key) +{ + tree_widget_shortcut_item *item = get_item (settings_key); + + if (item) + settings.setValue (settings_key, item->actual_text ()); +} + +// Refresh the tree view with values from the settings object. + +void shortcuts_tree_widget::import_shortcuts (gui_settings& settings) +{ + settings.beginGroup (sc_group); + + const QStringList shortcut_settings_keys = settings.allKeys (); + + for (const auto& settings_key : shortcut_settings_keys) + { + // We don't want to apply default value here. + QString sc_text = settings.value (settings_key).toString (); + + update_widget_value (settings_key, sc_text); + } + + settings.endGroup (); + + bool sc_ctrld = false; + + QTreeWidgetItemIterator it (this, QTreeWidgetItemIterator::NoChildren); + while (*it) + { + tree_widget_shortcut_item *shortcut_item + = dynamic_cast (*it); + + if (! shortcut_item) + continue; + + QString settings_key = shortcut_item->settings_key (); + QString sc_text = shortcut_item->actual_text (); + + if (sc_text.isEmpty ()) + sc_text = shortcut_item->default_text (); + + QString section = get_shortcut_section (settings_key); + + // special: check main-window for Ctrl-D (Terminal) + if (section.startsWith ("main_") + && QKeySequence (sc_text) + == QKeySequence (Qt::ControlModifier | Qt::Key_D)) + + sc_ctrld = true; + + it++; + } + + settings.setValue (sc_main_ctrld.settings_key (), sc_ctrld); + + settings.sync (); +} + +// Export all shortcuts from the tree view to the settings object. + +void shortcuts_tree_widget::export_shortcuts (gui_settings& settings) +{ + settings.beginGroup (sc_group); + + bool sc_ctrld = false; + + QTreeWidgetItemIterator it (this, QTreeWidgetItemIterator::NoChildren); + while (*it) + { + tree_widget_shortcut_item *shortcut_item + = dynamic_cast (*it); + + if (! shortcut_item) + continue; + + QString settings_key = shortcut_item->settings_key (); + QString sc_text = shortcut_item->actual_text (); + + if (sc_text.isEmpty ()) + sc_text = shortcut_item->default_text (); + else + settings.setValue (settings_key, sc_text); + + QString section = get_shortcut_section (settings_key); + + // special: check main-window for Ctrl-D (Terminal) + if (section.startsWith ("main_") + && QKeySequence (sc_text) + == QKeySequence (Qt::ControlModifier | Qt::Key_D)) + + sc_ctrld = true; + + it++; + } + + settings.endGroup (); + + settings.setValue (sc_main_ctrld.settings_key (), sc_ctrld); + + settings.sync (); +} + +// Clear all user-defined settings from the tree widget and the +// application settings. + +void shortcuts_tree_widget::set_default_shortcuts () +{ + gui_settings settings; + + settings.beginGroup (sc_group); + + settings.remove (""); + + settings.endGroup (); + + bool sc_ctrld = false; + + QTreeWidgetItemIterator it (this, QTreeWidgetItemIterator::NoChildren); + while (*it) + { + tree_widget_shortcut_item *shortcut_item + = dynamic_cast (*it); + + if (! shortcut_item) + continue; + + QString settings_key = shortcut_item->settings_key (); + + shortcut_item->set_actual_text (""); + + QString sc_text = shortcut_item->default_text (); + + QString section = get_shortcut_section (settings_key); + + // special: check main-window for Ctrl-D (Terminal) + if (section.startsWith ("main_") + && QKeySequence (sc_text) + == QKeySequence (Qt::ControlModifier | Qt::Key_D)) + + sc_ctrld = true; + + it++; + } + + settings.setValue (sc_main_ctrld.settings_key (), sc_ctrld); + + settings.sync (); +} + +// For each key found in application settings object, transfer +// corresponding setting to the application settings object. + +void shortcuts_tree_widget::write_settings () +{ + gui_settings settings; + + export_shortcuts (settings); +} + +OCTAVE_END_NAMESPACE(octave) diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/shortcuts-tree-widget.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/shortcuts-tree-widget.h Fri May 12 08:03:14 2023 +0200 @@ -0,0 +1,158 @@ +//////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2014-2023 The Octave Project Developers +// +// See the file COPYRIGHT.md in the top-level directory of this +// distribution or . +// +// 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 +// . +// +//////////////////////////////////////////////////////////////////////// + +#if ! defined (octave_shortcuts_tree_widget_h) +#define octave_shortcuts_tree_widget_h 1 + +#include +#include +#include +#include +#include +#include +#include + +#include "gui-preferences.h" +#include "gui-settings.h" + +OCTAVE_BEGIN_NAMESPACE(octave) + +class enter_shortcut : public QLineEdit +{ + Q_OBJECT + +public: + + enter_shortcut (QWidget *p = nullptr); + + ~enter_shortcut () = default; + + virtual void keyPressEvent (QKeyEvent *e); + +public slots: + + void handle_direct_shortcut (int); + void handle_shift_modifier (int); + +private: + + bool m_direct_shortcut; + bool m_shift_modifier; +}; + +class tree_widget_shortcut_item : public QTreeWidgetItem +{ +public: + + enum + { + DESCRIPTION_COLUMN = 0, + DEFAULT_COLUMN, + ACTUAL_COLUMN + }; + + tree_widget_shortcut_item (QTreeWidgetItem *parent, const sc_pref& scpref, + const QString& actual_text); + + QString settings_key () const; + + QString description () const; + void set_description (const QString& text); + + QString default_text () const; + void set_default_text (const QString& text); + + QString actual_text () const; + void set_actual_text (const QString& text); + +private: + + QString m_settings_key; +}; + +class shortcut_edit_dialog : public QDialog +{ + Q_OBJECT + +public: + + shortcut_edit_dialog (tree_widget_shortcut_item *shortcut_item, + QWidget *parent = nullptr); + +public slots: + + void finished (int result); + + void set_default_shortcut (); + +signals: + + void set_shortcut (const QString& settings_key, + const QString& settings_value); + +private: + + tree_widget_shortcut_item *m_shortcut_item; + + enter_shortcut *m_edit_actual; + + QString m_settings_key; + QString m_default_text; +}; + +class shortcuts_tree_widget : public QTreeWidget +{ + Q_OBJECT + +public: + + shortcuts_tree_widget (QWidget *parent); + + void import_shortcuts (gui_settings& settings); + + void export_shortcuts (gui_settings& settings); + + void set_default_shortcuts (); + + void write_settings (); + +public slots: + + void edit_selection (QTreeWidgetItem *item, int col); + + void update_widget_value (const QString& settings_key, + const QString& sc_text); + +private: + + tree_widget_shortcut_item * get_item (const QString& settings_key); + + void update_settings_value (gui_settings& settings, + const QString& settings_key); +}; + +OCTAVE_END_NAMESPACE(octave) + +#endif diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/tab-bar.cc --- a/libgui/src/tab-bar.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/tab-bar.cc Fri May 12 08:03:14 2023 +0200 @@ -48,22 +48,22 @@ } // slots for tab navigation -void tab_bar::switch_left_tab (void) +void tab_bar::switch_left_tab () { switch_tab (-1); } -void tab_bar::switch_right_tab (void) +void tab_bar::switch_right_tab () { switch_tab (1); } -void tab_bar::move_tab_left (void) +void tab_bar::move_tab_left () { switch_tab (-1, true); } -void tab_bar::move_tab_right (void) +void tab_bar::move_tab_right () { switch_tab (1, true); } @@ -91,7 +91,7 @@ setCurrentIndex (new_pos); } -void tab_bar::sort_tabs_alph (void) +void tab_bar::sort_tabs_alph () { QString current_title = tabText (currentIndex ()); int tab_with_focus = 0; diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/tab-bar.h --- a/libgui/src/tab-bar.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/tab-bar.h Fri May 12 08:03:14 2023 +0200 @@ -49,10 +49,10 @@ tab_bar (QWidget *p); - ~tab_bar (void) = default; + ~tab_bar () = default; void set_rotated (int rotated); - QMenu * get_context_menu (void) { return m_context_menu; }; + QMenu * get_context_menu () { return m_context_menu; }; QSize tabSizeHint (int idx) const; signals: @@ -61,11 +61,11 @@ public slots: - void switch_left_tab (void); - void switch_right_tab (void); - void move_tab_left (void); - void move_tab_right (void); - void sort_tabs_alph (void); + void switch_left_tab (); + void switch_right_tab (); + void move_tab_left (); + void move_tab_right (); + void sort_tabs_alph (); private slots: diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/terminal-dock-widget.cc --- a/libgui/src/terminal-dock-widget.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/terminal-dock-widget.cc Fri May 12 08:03:14 2023 +0200 @@ -27,6 +27,7 @@ # include "config.h" #endif +#include #include // This header is only needed for the new terminal widget. @@ -39,23 +40,26 @@ #include "gui-preferences-cs.h" #include "gui-preferences-global.h" +#include "gui-preferences-sc.h" +#include "gui-settings.h" -#include "octave-qobject.h" #include "terminal-dock-widget.h" OCTAVE_BEGIN_NAMESPACE(octave) terminal_dock_widget::terminal_dock_widget (QWidget *p, - base_qobject& oct_qobj) -: octave_dock_widget ("TerminalDockWidget", p, oct_qobj), - m_experimental_terminal_widget (oct_qobj.experimental_terminal_widget ()) + bool experimental_terminal_widget) + : octave_dock_widget ("TerminalDockWidget", p), + m_experimental_terminal_widget (experimental_terminal_widget) { + init_control_d_shortcut_behavior (); + // FIXME: we could do this in a better way, but improving it doesn't // matter much if we will eventually be removing the old terminal. if (m_experimental_terminal_widget) { #if defined (HAVE_QSCINTILLA) - command_widget *widget = new command_widget (oct_qobj, this); + command_widget *widget = new command_widget (this); console *con = widget->get_console (); connect (this, &terminal_dock_widget::settings_changed, @@ -68,17 +72,17 @@ widget, &command_widget::insert_interpreter_output); connect (this, &terminal_dock_widget::execute_command_signal, - con, &console::execute_command); + con, &console::execute_command); connect (this, &terminal_dock_widget::new_command_line_signal, - con, &console::new_command_line); + con, &console::new_command_line); m_terminal = widget; #endif } else { - QTerminal *widget = QTerminal::create (oct_qobj, this); + QTerminal *widget = QTerminal::create (this); connect (this, &terminal_dock_widget::settings_changed, widget, &QTerminal::notice_settings); @@ -88,6 +92,12 @@ connect (this, &terminal_dock_widget::visibilityChanged, widget, &QTerminal::handle_visibility_changed); + connect (widget, QOverload::of (&QTerminal::interpreter_event), + this, QOverload::of (&terminal_dock_widget::interpreter_event)); + + connect (widget, QOverload::of (&QTerminal::interpreter_event), + this, QOverload::of (&terminal_dock_widget::interpreter_event)); + m_terminal = widget; } @@ -101,16 +111,16 @@ // Chose a reasonable size at startup in order to avoid truncated // startup messages - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); + + gui_settings settings; QFont font = QFont (); font.setStyleHint (QFont::TypeWriter); - QString default_font = settings->value (global_mono_font).toString (); + QString default_font = settings.string_value (global_mono_font); font.setFamily - (settings->value (cs_font.key, default_font).toString ()); + (settings.value (cs_font.settings_key (), default_font).toString ()); font.setPointSize - (settings->value (cs_font_size).toInt ()); + (settings.int_value (cs_font_size)); QFontMetrics metrics(font); @@ -131,29 +141,29 @@ make_window (); } -bool terminal_dock_widget::has_focus (void) const +bool terminal_dock_widget::has_focus () const { QWidget *w = widget (); return w->hasFocus (); } -QTerminal * terminal_dock_widget::get_qterminal (void) +QTerminal * terminal_dock_widget::get_qterminal () { return (m_experimental_terminal_widget ? nullptr : dynamic_cast (m_terminal)); } #if defined (HAVE_QSCINTILLA) -command_widget * terminal_dock_widget::get_command_widget (void) +command_widget * terminal_dock_widget::get_command_widget () { return (m_experimental_terminal_widget ? dynamic_cast (m_terminal) : nullptr); } #endif -void terminal_dock_widget::notice_settings (const gui_settings *settings) +void terminal_dock_widget::notice_settings () { - emit settings_changed (settings); + emit settings_changed (); } void terminal_dock_widget::init_command_prompt () @@ -168,4 +178,39 @@ } } +void terminal_dock_widget::init_control_d_shortcut_behavior () +{ + gui_settings settings; + + // Reset use of Ctrl-D. Do this before the call to beginGroup + // because sc_main_ctrld.key already begins with the sc_group + // prefix. + settings.setValue (sc_main_ctrld.settings_key (), false); + + settings.beginGroup (sc_group); + const QStringList shortcut_settings_keys = settings.allKeys (); + settings.endGroup (); + + for (const auto& settings_key : shortcut_settings_keys) + { + // Check whether Ctrl+D is used from main window, i.e. is a + // global shortcut. + + QString section = get_shortcut_section (settings_key); + + if (section.startsWith ("main_")) + { + sc_pref scpref = all_shortcut_preferences::value (settings_key); + + QKeySequence actual = QKeySequence (settings.sc_value (scpref)); + + if (actual == QKeySequence (Qt::ControlModifier | Qt::Key_D)) + { + settings.setValue (sc_main_ctrld.settings_key (), true); + break; + } + } + } +} + OCTAVE_END_NAMESPACE(octave) diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/terminal-dock-widget.h --- a/libgui/src/terminal-dock-widget.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/terminal-dock-widget.h Fri May 12 08:03:14 2023 +0200 @@ -35,7 +35,6 @@ OCTAVE_BEGIN_NAMESPACE(octave) class command_widget; -class base_qobject; class terminal_dock_widget : public octave_dock_widget { @@ -43,29 +42,32 @@ public: - terminal_dock_widget (QWidget *parent, base_qobject& oct_qobj); + terminal_dock_widget (QWidget *parent, + bool experimental_terminal_widget = false); - ~terminal_dock_widget (void) = default; + ~terminal_dock_widget () = default; - bool has_focus (void) const; + bool has_focus () const; void init_command_prompt (); + void init_control_d_shortcut_behavior (); + // FIXME: The next two functions could be eliminated (or combined) // if we had a common interface for the old and new terminal // widgets. // Only valid if using the old terminal widget. - QTerminal * get_qterminal (void); + QTerminal * get_qterminal (); #if defined (HAVE_QSCINTILLA) // Only valid if using the new terminal widget. - command_widget * get_command_widget (void); + command_widget * get_command_widget (); #endif signals: - void settings_changed (const gui_settings *settings); + void settings_changed (); // Note: the following four signals are // currently only used by the new experimental terminal widget. @@ -78,9 +80,12 @@ void execute_command_signal (const QString&); + void interpreter_event (const fcn_callback& fcn); + void interpreter_event (const meth_callback& meth); + public slots: - void notice_settings (const gui_settings *settings); + void notice_settings (); private: diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/variable-editor-model.cc --- a/libgui/src/variable-editor-model.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/variable-editor-model.cc Fri May 12 08:03:14 2023 +0200 @@ -104,7 +104,7 @@ { } std::string -base_ve_model::name (void) const +base_ve_model::name () const { return m_name; } @@ -125,7 +125,7 @@ } int -base_ve_model::column_width (void) const +base_ve_model::column_width () const { int width = 0; @@ -257,7 +257,7 @@ } void -base_ve_model::clear_update_pending (void) +base_ve_model::clear_update_pending () { return m_update_pending.clear (); } @@ -285,7 +285,7 @@ } QString -base_ve_model::make_description_text (void) const +base_ve_model::make_description_text () const { QString lbl_txt = QString::fromStdString (m_name); @@ -330,13 +330,9 @@ maybe_resize_columns (m_data_cols + 16); } - ~numeric_model (void) = default; - - // No copying! + ~numeric_model () = default; - numeric_model (const numeric_model&) = delete; - - numeric_model& operator = (const numeric_model&) = delete; + OCTAVE_DISABLE_COPY_MOVE (numeric_model) void maybe_resize_rows (int rows) { @@ -394,13 +390,9 @@ m_display_cols = 1; } - ~string_model (void) = default; - - // No copying! + ~string_model () = default; - string_model (const string_model&) = delete; - - string_model& operator = (const string_model&) = delete; + OCTAVE_DISABLE_COPY_MOVE (string_model) QVariant edit_display (const QModelIndex&, int) const { @@ -431,13 +423,9 @@ maybe_resize_columns (m_data_cols + 16); } - ~cell_model (void) = default; - - // No copying! + ~cell_model () = default; - cell_model (const cell_model&) = delete; - - cell_model& operator = (const cell_model&) = delete; + OCTAVE_DISABLE_COPY_MOVE (cell_model) void maybe_resize_rows (int rows) { @@ -532,13 +520,9 @@ m_display_cols = 1; } - ~scalar_struct_model (void) = default; - - // No copying! + ~scalar_struct_model () = default; - scalar_struct_model (const scalar_struct_model&) = delete; - - scalar_struct_model& operator = (const scalar_struct_model&) = delete; + OCTAVE_DISABLE_COPY_MOVE (scalar_struct_model) QVariant edit_display (const QModelIndex& idx, int role) const { @@ -655,15 +639,11 @@ m_display_cols = m_data_cols; } - ~display_only_model (void) = default; - - // No copying! + ~display_only_model () = default; - display_only_model (const display_only_model&) = delete; + OCTAVE_DISABLE_COPY_MOVE (display_only_model) - display_only_model& operator = (const display_only_model&) = delete; - - bool is_editable (void) const { return false; } + bool is_editable () const { return false; } QVariant edit_display (const QModelIndex&, int) const { @@ -679,7 +659,7 @@ return QString::fromStdString (buf.str ()); } - QString make_description_text (void) const + QString make_description_text () const { return (QString ("unable to edit %1") .arg (base_ve_model::make_description_text ())); @@ -706,13 +686,9 @@ m_display_cols = m_data_cols; } - ~vector_struct_model (void) = default; - - // No copying! + ~vector_struct_model () = default; - vector_struct_model (const vector_struct_model&) = delete; - - vector_struct_model& operator = (const vector_struct_model&) = delete; + OCTAVE_DISABLE_COPY_MOVE (vector_struct_model) void maybe_resize_rows (int rows) { @@ -839,13 +815,9 @@ maybe_resize_columns (m_data_cols + 16); } - ~struct_model (void) = default; - - // No copying! + ~struct_model () = default; - struct_model (const struct_model&) = delete; - - struct_model& operator = (const struct_model&) = delete; + OCTAVE_DISABLE_COPY_MOVE (struct_model) void maybe_resize_rows (int rows) { @@ -951,7 +923,7 @@ variable_editor_model::variable_editor_model (const QString& expr, const octave_value& val, QObject *parent) - : QAbstractTableModel (parent), rep (create (expr, val)) + : QAbstractTableModel (parent), m_rep (create (expr, val)) { update_description (); @@ -1255,7 +1227,7 @@ } void -variable_editor_model::update_data_cache (void) +variable_editor_model::update_data_cache () { emit interpreter_event ([=] (interpreter& interp) @@ -1336,7 +1308,7 @@ int old_rows = display_rows (); int old_cols = display_columns (); - rep->maybe_resize_rows (rows); + m_rep->maybe_resize_rows (rows); int new_rows = display_rows (); int new_cols = display_columns (); @@ -1351,7 +1323,7 @@ int old_rows = display_rows (); int old_cols = display_columns (); - rep->maybe_resize_columns (cols); + m_rep->maybe_resize_columns (cols); int new_rows = display_rows (); int new_cols = display_columns (); @@ -1371,9 +1343,9 @@ void variable_editor_model::reset (const octave_value& val) { - base_ve_model *old_rep = rep; + base_ve_model *old_rep = m_rep; - rep = create (QString::fromStdString (name ()), val); + m_rep = create (QString::fromStdString (name ()), val); delete old_rep; @@ -1383,7 +1355,7 @@ } void -variable_editor_model::invalidate (void) +variable_editor_model::invalidate () { beginResetModel (); @@ -1404,7 +1376,7 @@ { if (requires_sub_editor (idx)) { - QString name = QString::fromStdString(rep->name ()); + QString name = QString::fromStdString(m_rep->name ()); emit edit_variable_signal (name + subscript_expression (idx), value_at (idx)); } diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/variable-editor-model.h --- a/libgui/src/variable-editor-model.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/variable-editor-model.h Fri May 12 08:03:14 2023 +0200 @@ -26,6 +26,8 @@ #if ! defined (octave_variable_editor_model_h) #define octave_variable_editor_model_h 1 +#include "octave-config.h" + #include #include #include @@ -45,27 +47,23 @@ base_ve_model (const QString& expr, const octave_value& val); - virtual ~base_ve_model (void) = default; - - // No copying! + virtual ~base_ve_model () = default; - base_ve_model (const base_ve_model&) = delete; - - base_ve_model& operator = (const base_ve_model&) = delete; + OCTAVE_DISABLE_COPY_MOVE (base_ve_model) virtual void maybe_resize_rows (int) { } virtual void maybe_resize_columns (int) { } - std::string name (void) const; + std::string name () const; bool index_ok (const QModelIndex& idx, int& row, int& col) const; - virtual bool is_editable (void) const { return true; } + virtual bool is_editable () const { return true; } virtual octave_value value_at (const QModelIndex& idx) const; - int column_width (void) const; + int column_width () const; int rowCount (const QModelIndex& = QModelIndex ()) const; @@ -85,7 +83,7 @@ QString update_pending_data (const QModelIndex& idx) const; - void clear_update_pending (void); + void clear_update_pending (); virtual char quote_char (const QModelIndex& idx) const; @@ -98,17 +96,17 @@ virtual QString subscript_expression (const QModelIndex& idx) const; - bool is_valid (void) const { return m_valid; } + bool is_valid () const { return m_valid; } - octave_idx_type data_rows (void) const { return m_data_rows; } + octave_idx_type data_rows () const { return m_data_rows; } - octave_idx_type data_columns (void) const { return m_data_cols; } + octave_idx_type data_columns () const { return m_data_cols; } - int display_rows (void) const { return m_display_rows; } + int display_rows () const { return m_display_rows; } - int display_columns (void) const { return m_display_cols; } + int display_columns () const { return m_display_cols; } - virtual QString make_description_text (void) const; + virtual QString make_description_text () const; void reset (const octave_value& val); @@ -145,51 +143,47 @@ variable_editor_model (const QString& expr, const octave_value& val, QObject *parent = nullptr); - ~variable_editor_model (void) + ~variable_editor_model () { - delete rep; + delete m_rep; } - // No copying! - - variable_editor_model (const variable_editor_model&) = delete; + OCTAVE_DISABLE_COPY_MOVE (variable_editor_model) - variable_editor_model& operator = (const variable_editor_model&) = delete; - - std::string name (void) const + std::string name () const { - return rep->name (); + return m_rep->name (); } - bool is_editable (void) const + bool is_editable () const { - return rep->is_editable (); + return m_rep->is_editable (); } octave_value value_at (const QModelIndex& idx) const { - return rep->value_at (idx); + return m_rep->value_at (idx); } - int column_width (void) const + int column_width () const { - return rep->column_width (); + return m_rep->column_width (); } int rowCount (const QModelIndex& idx = QModelIndex ()) const { - return rep->rowCount (idx); + return m_rep->rowCount (idx); } int columnCount (const QModelIndex& idx = QModelIndex ()) const { - return rep->columnCount (idx); + return m_rep->columnCount (idx); } QVariant data (const QModelIndex& idx = QModelIndex (), int role = Qt::DisplayRole) const { - return rep->data (idx, role); + return m_rep->data (idx, role); } bool setData (const QModelIndex& idx, const QVariant& v, @@ -215,38 +209,38 @@ bool requires_sub_editor (const QModelIndex& idx) const { - return rep->requires_sub_editor (idx); + return m_rep->requires_sub_editor (idx); } void set_update_pending (const QModelIndex& idx, const QString& str) { - rep->set_update_pending (idx, str); + m_rep->set_update_pending (idx, str); } bool update_pending (const QModelIndex& idx) const { - return rep->update_pending (idx); + return m_rep->update_pending (idx); } QString update_pending_data (const QModelIndex& idx) const { - return rep->update_pending_data (idx); + return m_rep->update_pending_data (idx); } - void clear_update_pending (void) + void clear_update_pending () { - rep->clear_update_pending (); + m_rep->clear_update_pending (); } char quote_char (const QModelIndex& idx) const { - return rep->quote_char (idx); + return m_rep->quote_char (idx); } QVariant headerData (int section, Qt::Orientation orientation, int role) const { - return rep->header_data (section, orientation, role); + return m_rep->header_data (section, orientation, role); } // Return a subscript expression as a string that can be used to @@ -255,27 +249,27 @@ QString subscript_expression (const QModelIndex& idx) const { - return rep->subscript_expression (idx); + return m_rep->subscript_expression (idx); } - int display_rows (void) const + int display_rows () const { - return rep->display_rows (); + return m_rep->display_rows (); } - octave_idx_type data_rows (void) const + octave_idx_type data_rows () const { - return rep->data_rows (); + return m_rep->data_rows (); } - int display_columns (void) const + int display_columns () const { - return rep->display_columns (); + return m_rep->display_columns (); } - octave_idx_type data_columns (void) const + octave_idx_type data_columns () const { - return rep->data_columns (); + return m_rep->data_columns (); } void maybe_resize_rows (int rows); @@ -303,7 +297,7 @@ void update_data (const octave_value& val); - void update_data_cache (void); + void update_data_cache (); void double_click (const QModelIndex& idx); @@ -315,7 +309,7 @@ private: - base_ve_model *rep; + base_ve_model *m_rep; void init_from_oct (interpreter& interp); @@ -323,22 +317,22 @@ octave_value retrieve_variable (interpreter&, const std::string& name); - bool is_valid (void) const + bool is_valid () const { - return rep->is_valid (); + return m_rep->is_valid (); } void change_display_size (int old_rows, int old_cols, int new_rows, int new_cols); - QString make_description_text (void) const + QString make_description_text () const { - return rep->make_description_text (); + return m_rep->make_description_text (); } void reset (const octave_value& val); - void invalidate (void); + void invalidate (); void update_description (const QString& description = QString ()); diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/variable-editor.cc --- a/libgui/src/variable-editor.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/variable-editor.cc Fri May 12 08:03:14 2023 +0200 @@ -38,6 +38,8 @@ #include #include #include +#include +#include #include #include #include @@ -55,11 +57,9 @@ #include "gui-preferences-global.h" #include "gui-preferences-sc.h" #include "gui-preferences-ve.h" -#include "octave-qobject.h" -#include "octave-qtutils.h" +#include "gui-settings.h" #include "ovl.h" #include "qt-utils.h" -#include "shortcut-manager.h" #include "variable-editor-model.h" #include "variable-editor.h" @@ -84,13 +84,12 @@ // Variable dock widget -variable_dock_widget::variable_dock_widget (QWidget *p, - base_qobject& oct_qobj) - : label_dock_widget (p, oct_qobj) - // See Octave bug #53807 and https://bugreports.qt.io/browse/QTBUG-44813 +variable_dock_widget::variable_dock_widget (QWidget *p) + : label_dock_widget (p) +// See Octave bug #53807 and https://bugreports.qt.io/browse/QTBUG-44813 #if (QT_VERSION >= 0x050302) && (QT_VERSION <= QTBUG_44813_FIX_VERSION) - , m_waiting_for_mouse_move (false) - , m_waiting_for_mouse_button_release (false) + , m_waiting_for_mouse_move (false) + , m_waiting_for_mouse_button_release (false) #endif { setFocusPolicy (Qt::StrongFocus); @@ -113,9 +112,10 @@ m_prev_geom = QRect (0, 0, 0, 0); QHBoxLayout *h_layout = m_title_widget->findChild (); - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); + + gui_settings settings; m_fullscreen_action - = new QAction (rmgr.icon ("view-fullscreen", false), "", this); + = new QAction (settings.icon ("view-fullscreen", false), "", this); m_fullscreen_action->setToolTip (tr (DOCKED_FULLSCREEN_BUTTON_TOOLTIP)); QToolButton *fullscreen_button = new QToolButton (m_title_widget); fullscreen_button->setDefaultAction (m_fullscreen_action); @@ -148,8 +148,8 @@ if (m_full_screen) { setGeometry (m_prev_geom); - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - m_fullscreen_action->setIcon (rmgr.icon ("view-fullscreen", false)); + gui_settings settings; + m_fullscreen_action->setIcon (settings.icon ("view-fullscreen", false)); m_full_screen = false; } m_fullscreen_action->setToolTip (tr (DOCKED_FULLSCREEN_BUTTON_TOOLTIP)); @@ -183,7 +183,7 @@ activateWindow (); setFocus (); - // See Octave bug #53807 and https://bugreports.qt.io/browse/QTBUG-44813 +// See Octave bug #53807 and https://bugreports.qt.io/browse/QTBUG-44813 #if (QT_VERSION >= 0x050302) && (QT_VERSION <= QTBUG_44813_FIX_VERSION) m_waiting_for_mouse_move = true; #endif @@ -196,7 +196,7 @@ setFocus (); - // See Octave bug #53807 and https://bugreports.qt.io/browse/QTBUG-44813 +// See Octave bug #53807 and https://bugreports.qt.io/browse/QTBUG-44813 #if (QT_VERSION >= 0x050302) && (QT_VERSION <= QTBUG_44813_FIX_VERSION) m_waiting_for_mouse_move = false; m_waiting_for_mouse_button_release = false; @@ -205,14 +205,14 @@ } void -variable_dock_widget::change_fullscreen (void) +variable_dock_widget::change_fullscreen () { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); + gui_settings settings; if (! m_full_screen) { m_prev_floating = isFloating (); - m_fullscreen_action->setIcon (rmgr.icon ("view-restore", false)); + m_fullscreen_action->setIcon (settings.icon ("view-restore", false)); if (m_prev_floating) m_fullscreen_action->setToolTip (tr ("Restore geometry")); else @@ -232,7 +232,7 @@ } else { - m_fullscreen_action->setIcon (rmgr.icon ("view-fullscreen", false)); + m_fullscreen_action->setIcon (settings.icon ("view-fullscreen", false)); setGeometry (m_prev_geom); if (m_prev_floating) m_fullscreen_action->setToolTip (tr (UNDOCKED_FULLSCREEN_BUTTON_TOOLTIP)); @@ -329,7 +329,7 @@ } void -variable_dock_widget::unfloat_float (void) +variable_dock_widget::unfloat_float () { hide (); setFloating (false); @@ -340,7 +340,7 @@ } void -variable_dock_widget::refloat (void) +variable_dock_widget::refloat () { setFloating (true); m_waiting_for_mouse_move = false; @@ -353,21 +353,19 @@ #else void -variable_dock_widget::unfloat_float (void) +variable_dock_widget::unfloat_float () { } void -variable_dock_widget::refloat (void) +variable_dock_widget::refloat () { } #endif // Variable editor stack -variable_editor_stack::variable_editor_stack (QWidget *p, - base_qobject& oct_qobj) - : QStackedWidget (p), m_octave_qobj (oct_qobj), - m_edit_view (new variable_editor_view (this, m_octave_qobj)) +variable_editor_stack::variable_editor_stack (QWidget *p) + : QStackedWidget (p), m_edit_view (new variable_editor_view (this)) { setFocusPolicy (Qt::StrongFocus); @@ -426,7 +424,7 @@ } void -variable_editor_stack::levelUp (void) +variable_editor_stack::levelUp () { if (! hasFocus ()) return; @@ -437,7 +435,7 @@ if (name.endsWith (')') || name.endsWith ('}')) { - name.remove ( QRegExp ("[({][^({]*[)}]$)") ); + name.remove (QRegularExpression {"[({][^({]*[)}]$)"}); emit edit_variable_signal (name, octave_value ()); } } @@ -467,24 +465,24 @@ // No format given, test save default options emit interpreter_event ([=] (interpreter& interp) - { - // INTERPRETER THREAD + { + // INTERPRETER THREAD - // We can skip the entire callback function because it does not - // make any changes to the interpreter state. + // We can skip the entire callback function because it does + // not make any changes to the interpreter state. - if (this_ves.isNull ()) - return; + if (this_ves.isNull ()) + return; - octave_value_list argout - = Fsave_default_options (interp, octave_value_list (), 1); - QString save_opts = QString::fromStdString (argout(0).string_value ()); + octave_value_list argout + = Fsave_default_options (interp, octave_value_list (), 1); + QString save_opts = QString::fromStdString (argout(0).string_value ()); - connect (this, &variable_editor_stack::do_save_signal, - this, &variable_editor_stack::do_save); + connect (this, &variable_editor_stack::do_save_signal, + this, &variable_editor_stack::do_save); - emit (do_save_signal (format_string, save_opts)); - }); + emit do_save_signal (format_string, save_opts); + }); } // Perform saving the variable after desired format is determined @@ -503,9 +501,10 @@ // FIXME: Remove, if for all common KDE versions (bug #54607) is resolved. int opts = 0; // No options by default. - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - if (! settings->value (global_use_native_dialogs).toBool ()) + + gui_settings settings; + + if (! settings.bool_value (global_use_native_dialogs)) opts = QFileDialog::DontUseNativeDialog; QString name = objectName (); @@ -521,25 +520,24 @@ // Let the interpreter thread do the saving emit interpreter_event ([=] (interpreter& interp) - { - // INTERPRETER THREAD + { + // INTERPRETER THREAD - octave_value_list ovl; - std::list str_list - = {octave_value (file.toStdString ()), - octave_value (name.toStdString ())}; - if (! format.isEmpty ()) - str_list.push_front (octave_value (format.toStdString ())); + octave_value_list ovl; + std::list str_list + = {octave_value (file.toStdString ()), + octave_value (name.toStdString ())}; + if (! format.isEmpty ()) + str_list.push_front (octave_value (format.toStdString ())); - Fsave (interp, octave_value_list (str_list)); - }); + Fsave (interp, octave_value_list (str_list)); + }); } // Custom editable variable table view -variable_editor_view::variable_editor_view (QWidget *p, - base_qobject& oct_qobj) - : QTableView (p), m_octave_qobj (oct_qobj), m_var_model (nullptr) +variable_editor_view::variable_editor_view (QWidget *p) + : QTableView (p), m_var_model (nullptr) { setWordWrap (false); setContextMenuPolicy (Qt::CustomContextMenu); @@ -576,7 +574,7 @@ } QList -variable_editor_view::range_selected (void) +variable_editor_view::range_selected () { QItemSelectionModel *sel = selectionModel (); @@ -632,9 +630,9 @@ // Variable with desired range as string QString variable = QString ("%1(%2:%3,%4:%5)") - .arg (objectName ()) - .arg (range.at (0)).arg (s1) - .arg (range.at (2)).arg (s2); + .arg (objectName ()) + .arg (range.at (0)).arg (s1) + .arg (range.at (2)).arg (s2); // Desired command as string QString command; @@ -642,7 +640,7 @@ command = QString ("unnamed = %1;").arg (variable); else command = QString ("figure (); %1 (%2); title ('%2');") - .arg (cmd).arg (variable); + .arg (cmd).arg (variable); emit command_signal (command); } @@ -651,31 +649,31 @@ variable_editor_view::add_edit_actions (QMenu *menu, const QString& qualifier_string) { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); + gui_settings settings; - menu->addAction (rmgr.icon ("edit-cut"), + menu->addAction (settings.icon ("edit-cut"), tr ("Cut") + qualifier_string, this, &variable_editor_view::cutClipboard); - menu->addAction (rmgr.icon ("edit-copy"), + menu->addAction (settings.icon ("edit-copy"), tr ("Copy") + qualifier_string, this, &variable_editor_view::copyClipboard); - menu->addAction (rmgr.icon ("edit-paste"), + menu->addAction (settings.icon ("edit-paste"), tr ("Paste"), this, &variable_editor_view::pasteClipboard); menu->addSeparator (); - menu->addAction (rmgr.icon ("edit-delete"), + menu->addAction (settings.icon ("edit-delete"), tr ("Clear") + qualifier_string, this, &variable_editor_view::clearContent); - menu->addAction (rmgr.icon ("edit-delete"), + menu->addAction (settings.icon ("edit-delete"), tr ("Delete") + qualifier_string, this, &variable_editor_view::delete_selected); - menu->addAction (rmgr.icon ("document-new"), + menu->addAction (settings.icon ("document-new"), tr ("Variable from Selection"), this, &variable_editor_view::createVariable); } @@ -816,7 +814,7 @@ } void -variable_editor_view::createVariable (void) +variable_editor_view::createVariable () { // FIXME: Create unnamed1..n if exist ('unnamed', 'var') is true. @@ -824,7 +822,7 @@ } void -variable_editor_view::transposeContent (void) +variable_editor_view::transposeContent () { if (! hasFocus ()) return; @@ -833,7 +831,7 @@ } void -variable_editor_view::delete_selected (void) +variable_editor_view::delete_selected () { if (! hasFocus ()) return; @@ -863,7 +861,7 @@ } void -variable_editor_view::clearContent (void) +variable_editor_view::clearContent () { if (! hasFocus ()) return; @@ -881,7 +879,7 @@ } void -variable_editor_view::cutClipboard (void) +variable_editor_view::cutClipboard () { copyClipboard (); @@ -889,7 +887,7 @@ } void -variable_editor_view::copyClipboard (void) +variable_editor_view::copyClipboard () { if (! hasFocus ()) return; @@ -920,7 +918,7 @@ } void -variable_editor_view::pasteClipboard (void) +variable_editor_view::pasteClipboard () { if (! hasFocus ()) return; @@ -1103,9 +1101,9 @@ // Variable editor. -variable_editor::variable_editor (QWidget *p, base_qobject& oct_qobj) - : octave_dock_widget ("VariableEditor", p, oct_qobj), - m_main (new dw_main_window (oct_qobj)), +variable_editor::variable_editor (QWidget *p) + : octave_dock_widget ("VariableEditor", p), + m_main (new dw_main_window ()), m_tool_bar (new QToolBar (m_main)), m_default_width (30), m_default_height (100), @@ -1127,7 +1125,7 @@ setAttribute (Qt::WA_AlwaysShowToolTips); m_main->setParent (this); - // See Octave bug #53409 and https://bugreports.qt.io/browse/QTBUG-55357 +// See Octave bug #53409 and https://bugreports.qt.io/browse/QTBUG-55357 #if (QT_VERSION < 0x050601) || (QT_VERSION >= 0x050701) m_main->setDockOptions (QMainWindow::AnimatedDocks | QMainWindow::AllowNestedDocks | @@ -1196,7 +1194,7 @@ } } -variable_editor::~variable_editor (void) +variable_editor::~variable_editor () { // FIXME: Maybe toolbar actions could be handled with signals and // slots so that deleting the toolbar here would disconnect all @@ -1211,13 +1209,8 @@ void variable_editor::edit_variable (const QString& name, const octave_value& val) { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - if (m_stylesheet.isEmpty ()) - { - gui_settings *settings = rmgr.get_settings (); - notice_settings (settings); - } + notice_settings (); QDockWidget *existing_qdw = m_main->findChild (name); if (existing_qdw) @@ -1242,8 +1235,7 @@ return; } - variable_dock_widget *page - = new variable_dock_widget (this, m_octave_qobj); + variable_dock_widget *page = new variable_dock_widget (this); page->setObjectName (name); m_main->addDockWidget (Qt::LeftDockWidgetArea, page); @@ -1270,8 +1262,7 @@ page, SLOT (refloat ()), Qt::QueuedConnection); #endif - variable_editor_stack *stack - = new variable_editor_stack (page, m_octave_qobj); + variable_editor_stack *stack = new variable_editor_stack (page); stack->setObjectName (name); page->setWidget (stack); @@ -1388,7 +1379,7 @@ } void -variable_editor::tab_to_front (void) +variable_editor::tab_to_front () { QWidget *parent = parentWidget (); @@ -1413,7 +1404,7 @@ } void -variable_editor::refresh (void) +variable_editor::refresh () { emit refresh_signal (); } @@ -1425,31 +1416,33 @@ } void -variable_editor::notice_settings (const gui_settings *settings) +variable_editor::notice_settings () { - m_main->notice_settings (settings); // update settings in parent main win + gui_settings settings; - m_default_width = settings->value (ve_column_width).toInt (); + m_main->notice_settings (); // update settings in parent main win - m_default_height = settings->value (ve_row_height).toInt (); + m_default_width = settings.int_value (ve_column_width); + + m_default_height = settings.int_value (ve_row_height); - m_alternate_rows = settings->value (ve_alternate_rows).toBool (); + m_alternate_rows = settings.bool_value (ve_alternate_rows); - m_use_terminal_font = settings->value (ve_use_terminal_font).toBool (); + m_use_terminal_font = settings.bool_value (ve_use_terminal_font); QString font_name; int font_size; - QString default_font = settings->value (global_mono_font).toString (); + QString default_font = settings.string_value (global_mono_font); if (m_use_terminal_font) { - font_name = settings->value (cs_font.key, default_font).toString (); - font_size = settings->value (cs_font_size).toInt (); + font_name = settings.value (cs_font.settings_key (), default_font).toString (); + font_size = settings.int_value (cs_font_size); } else { - font_name = settings->value (ve_font_name.key, default_font).toString (); - font_size = settings->value (ve_font_size).toInt (); + font_name = settings.value (ve_font_name.settings_key (), default_font).toString (); + font_size = settings.int_value (ve_font_size); } m_font = QFont (font_name, font_size); @@ -1458,11 +1451,11 @@ m_add_font_height = fm.height (); - int mode = settings->value (ve_color_mode).toInt (); + int mode = settings.int_value (ve_color_mode); for (int i = 0; i < ve_colors_count; i++) { - QColor setting_color = settings->color_value (ve_colors[i], mode); + QColor setting_color = settings.color_value (ve_colors[i], mode); m_table_colors.replace (i, setting_color); } @@ -1472,7 +1465,7 @@ if (m_tool_bar) { - int size_idx = settings->value (global_icon_size).toInt (); + int size_idx = settings.int_value (global_icon_size); size_idx = (size_idx > 0) - (size_idx < 0) + 1; // Make valid index from 0 to 2 QStyle *st = style (); @@ -1481,8 +1474,7 @@ } // Shortcuts (same as file editor) - shortcut_manager& scmgr = m_octave_qobj.get_shortcut_manager (); - scmgr.set_shortcut (m_save_action, sc_edit_file_save); + settings.set_shortcut (m_save_action, sc_edit_file_save); } void @@ -1543,13 +1535,13 @@ } void -variable_editor::record_hovered_focus_variable (void) +variable_editor::record_hovered_focus_variable () { m_hovered_focus_vname = m_current_focus_vname; } void -variable_editor::restore_hovered_focus_variable (void) +variable_editor::restore_hovered_focus_variable () { variable_dock_widget *tofocus = findChild (m_hovered_focus_vname); if (tofocus != nullptr) @@ -1566,13 +1558,13 @@ } void -variable_editor::save (void) +variable_editor::save () { emit save_signal (); } void -variable_editor::cutClipboard (void) +variable_editor::cutClipboard () { copyClipboard (); @@ -1580,13 +1572,13 @@ } void -variable_editor::copyClipboard (void) +variable_editor::copyClipboard () { emit copy_clipboard_signal (); } void -variable_editor::pasteClipboard (void) +variable_editor::pasteClipboard () { emit paste_clipboard_signal (); @@ -1594,40 +1586,40 @@ } void -variable_editor::levelUp (void) +variable_editor::levelUp () { emit level_up_signal (); } // Also updates the font. -void variable_editor::update_colors (void) +void variable_editor::update_colors () { m_stylesheet = ""; if (m_table_colors.length () > 0) m_stylesheet += "QTableView::item{ color: " - + m_table_colors[0].name () +" }"; + + m_table_colors[0].name () +" }"; if (m_table_colors.length () > 1) m_stylesheet += "QTableView::item{ background-color: " - + m_table_colors[1].name () +" }"; + + m_table_colors[1].name () +" }"; if (m_table_colors.length () > 2) m_stylesheet += "QTableView::item{ selection-color: " - + m_table_colors[2].name () +" }"; + + m_table_colors[2].name () +" }"; if (m_table_colors.length () > 3) m_stylesheet += "QTableView::item:selected{ background-color: " - + m_table_colors[3].name () +" }"; + + m_table_colors[3].name () +" }"; if (m_table_colors.length () > 4 && m_alternate_rows) { m_stylesheet += "QTableView::item:alternate{ background-color: " - + m_table_colors[4].name () +" }"; + + m_table_colors[4].name () +" }"; m_stylesheet += "QTableView::item:alternate:selected{ background-color: " - + m_table_colors[3].name () +" }"; + + m_table_colors[3].name () +" }"; } QList viewlist = findChildren (); @@ -1664,7 +1656,7 @@ } void -variable_editor::construct_tool_bar (void) +variable_editor::construct_tool_bar () { m_tool_bar->setAllowedAreas (Qt::TopToolBarArea); @@ -1672,22 +1664,23 @@ m_tool_bar->setWindowTitle (tr ("Variable Editor Toolbar")); - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); + gui_settings settings; - m_save_action = add_tool_bar_button (rmgr.icon ("document-save"), tr ("Save"), - this, SLOT (save ())); + m_save_action = add_tool_bar_button (settings.icon ("document-save"), + tr ("Save"), this, SLOT (save ())); addAction (m_save_action); m_save_action->setShortcutContext (Qt::WidgetWithChildrenShortcut); m_save_action->setStatusTip(tr("Save variable to a file")); - QAction *action = new QAction (rmgr.icon ("document-save-as"), tr ("Save in format ..."), m_tool_bar); + QAction *action = new QAction (settings.icon ("document-save-as"), + tr ("Save in format ..."), m_tool_bar); QToolButton *save_tool_button = new HoverToolButton (m_tool_bar); save_tool_button->setDefaultAction (action); save_tool_button->setText (tr ("Save in format ...")); save_tool_button->setToolTip (tr("Save variable to a file in different format")); - save_tool_button->setIcon (rmgr.icon ("document-save-as")); + save_tool_button->setIcon (settings.icon ("document-save-as")); save_tool_button->setPopupMode (QToolButton::InstantPopup); QMenu *save_menu = new ReturnFocusMenu (save_tool_button); @@ -1699,22 +1692,22 @@ m_save_mapper->setMapping (save_menu->addAction (ve_save_formats.at (i), m_save_mapper, SLOT (map ())), - ve_save_formats.at (i)); + ve_save_formats.at (i)); save_tool_button->setMenu (save_menu); m_tool_bar->addWidget (save_tool_button); m_tool_bar->addSeparator (); - action = add_tool_bar_button (rmgr.icon ("edit-cut"), tr ("Cut"), + action = add_tool_bar_button (settings.icon ("edit-cut"), tr ("Cut"), this, SLOT (cutClipboard ())); action->setStatusTip(tr("Cut data to clipboard")); - action = add_tool_bar_button (rmgr.icon ("edit-copy"), tr ("Copy"), + action = add_tool_bar_button (settings.icon ("edit-copy"), tr ("Copy"), this, SLOT (copyClipboard ())); action->setStatusTip(tr("Copy data to clipboard")); - action = add_tool_bar_button (rmgr.icon ("edit-paste"), tr ("Paste"), + action = add_tool_bar_button (settings.icon ("edit-paste"), tr ("Paste"), this, SLOT (pasteClipboard ())); action->setStatusTip(tr("Paste clipboard into variable data")); @@ -1724,14 +1717,15 @@ // QAction *print_action; /icons/fileprint.png // m_tool_bar->addSeparator (); - action = new QAction (rmgr.icon ("plot-xy-curve"), tr ("Plot"), m_tool_bar); + action = new QAction (settings.icon ("plot-xy-curve"), tr ("Plot"), + m_tool_bar); action->setToolTip (tr ("Plot Selected Data")); QToolButton *plot_tool_button = new HoverToolButton (m_tool_bar); plot_tool_button->setDefaultAction (action); plot_tool_button->setText (tr ("Plot")); plot_tool_button->setToolTip (tr ("Plot selected data")); - plot_tool_button->setIcon (rmgr.icon ("plot-xy-curve")); + plot_tool_button->setIcon (settings.icon ("plot-xy-curve")); plot_tool_button->setPopupMode (QToolButton::InstantPopup); @@ -1747,7 +1741,7 @@ m_tool_bar->addSeparator (); - action = add_tool_bar_button (rmgr.icon ("go-up"), tr ("Up"), this, + action = add_tool_bar_button (settings.icon ("go-up"), tr ("Up"), this, SLOT (levelUp ())); action->setStatusTip(tr("Go one level up in variable hierarchy")); @@ -1757,7 +1751,7 @@ QList hbuttonlist = m_tool_bar->findChildren ("" , Qt::FindDirectChildrenOnly - ); + ); for (int i = 0; i < hbuttonlist.size (); i++) { connect (hbuttonlist.at (i), &HoverToolButton::hovered_signal, @@ -1769,7 +1763,7 @@ QList rfbuttonlist = m_tool_bar->findChildren ("" , Qt::FindDirectChildrenOnly - ); + ); for (int i = 0; i < rfbuttonlist.size (); i++) { connect (rfbuttonlist.at (i), &ReturnFocusToolButton::about_to_activate, diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/variable-editor.h --- a/libgui/src/variable-editor.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/variable-editor.h Fri May 12 08:03:14 2023 +0200 @@ -26,13 +26,14 @@ #if ! defined (octave_variable_editor_h) #define octave_variable_editor_h 1 +#include "octave-config.h" + #include #include #include #include #include "dw-main-window.h" -#include "gui-settings.h" #include "octave-dock-widget.h" #include "qt-interpreter-events.h" #include "tab-bar.h" @@ -45,8 +46,6 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; - class variable_editor_model; class variable_editor_view; @@ -58,9 +57,9 @@ public: - variable_dock_widget (QWidget *p, base_qobject& oct_qobj); + variable_dock_widget (QWidget *p); - ~variable_dock_widget (void) = default; + ~variable_dock_widget () = default; signals: @@ -84,7 +83,7 @@ void toplevel_change (bool); - void change_fullscreen (void); + void change_fullscreen (); protected: @@ -98,19 +97,19 @@ QRect m_prev_geom; - // See Octave bug #53807 and https://bugreports.qt.io/browse/QTBUG-44813 +// See Octave bug #53807 and https://bugreports.qt.io/browse/QTBUG-44813 #define QTBUG_44813_FIX_VERSION 0x999999 signals: - void queue_unfloat_float (void); + void queue_unfloat_float (); - void queue_float (void); + void queue_float (); protected slots: - void unfloat_float (void); + void unfloat_float (); - void refloat (void); + void refloat (); #if (QT_VERSION >= 0x050302) && (QT_VERSION <= QTBUG_44813_FIX_VERSION) protected: @@ -131,13 +130,13 @@ public: - variable_editor_stack (QWidget *p, base_qobject& oct_qobj); + variable_editor_stack (QWidget *p); - ~variable_editor_stack (void) = default; + ~variable_editor_stack () = default; - variable_editor_view * edit_view (void) {return m_edit_view;}; + variable_editor_view * edit_view () {return m_edit_view;}; - QTextEdit * disp_view (void) {return m_disp_view;}; + QTextEdit * disp_view () {return m_disp_view;}; signals: @@ -152,7 +151,7 @@ void set_editable (bool editable); - void levelUp (void); + void levelUp (); void save (const QString& format = QString ()); @@ -162,8 +161,6 @@ QTextEdit * make_disp_view (QWidget *parent); - base_qobject& m_octave_qobj; - variable_editor_view *m_edit_view; QTextEdit *m_disp_view; @@ -175,9 +172,9 @@ public: - variable_editor_view (QWidget *p, base_qobject& oct_qobj); + variable_editor_view (QWidget *p); - ~variable_editor_view (void) = default; + ~variable_editor_view () = default; void setModel (QAbstractItemModel *model); @@ -189,21 +186,21 @@ public slots: - void createVariable (void); + void createVariable (); - void transposeContent (void); + void transposeContent (); - QList range_selected (void); + QList range_selected (); - void delete_selected (void); + void delete_selected (); - void clearContent (void); + void clearContent (); - void cutClipboard (void); + void cutClipboard (); - void copyClipboard (void); + void copyClipboard (); - void pasteClipboard (void); + void pasteClipboard (); void handle_horizontal_scroll_action (int action); @@ -221,8 +218,6 @@ void add_edit_actions (QMenu *menu, const QString& qualifier_string); - base_qobject& m_octave_qobj; - variable_editor_model *m_var_model; }; @@ -237,13 +232,13 @@ HoverToolButton (QWidget *parent = nullptr); - ~HoverToolButton (void) = default; + ~HoverToolButton () = default; signals: - void hovered_signal (void); + void hovered_signal (); - void popup_shown_signal (void); + void popup_shown_signal (); protected: @@ -258,11 +253,11 @@ ReturnFocusToolButton (QWidget *parent = nullptr); - ~ReturnFocusToolButton (void) = default; + ~ReturnFocusToolButton () = default; signals: - void about_to_activate (void); + void about_to_activate (); protected: @@ -277,11 +272,11 @@ ReturnFocusMenu (QWidget *parent = nullptr); - ~ReturnFocusMenu (void) = default; + ~ReturnFocusMenu () = default; signals: - void about_to_activate (void); + void about_to_activate (); protected: @@ -296,41 +291,37 @@ public: - variable_editor (QWidget *parent, base_qobject& oct_qobj); + variable_editor (QWidget *parent); - ~variable_editor (void); - - // No copying! + ~variable_editor (); - variable_editor (const variable_editor&) = delete; - - variable_editor& operator = (const variable_editor&) = delete; + OCTAVE_DISABLE_COPY_MOVE (variable_editor) - void refresh (void); + void refresh (); - void tab_to_front (void); + void tab_to_front (); signals: - void updated (void); + void updated (); - void finished (void); + void finished (); void command_signal (const QString& cmd); - void refresh_signal (void); + void refresh_signal (); - void clear_content_signal (void); + void clear_content_signal (); - void copy_clipboard_signal (void); + void copy_clipboard_signal (); - void paste_clipboard_signal (void); + void paste_clipboard_signal (); - void level_up_signal (void); + void level_up_signal (); - void save_signal (void); + void save_signal (); - void delete_selected_signal (void); + void delete_selected_signal (); void interpreter_event (const fcn_callback& fcn); void interpreter_event (const meth_callback& meth); @@ -339,7 +330,7 @@ void callUpdate (const QModelIndex&, const QModelIndex&); - void notice_settings (const gui_settings *); + void notice_settings (); void edit_variable (const QString& name, const octave_value& val); @@ -347,23 +338,23 @@ void variable_focused (const QString& name); - void record_hovered_focus_variable (void); + void record_hovered_focus_variable (); - void restore_hovered_focus_variable (void); + void restore_hovered_focus_variable (); protected slots: void closeEvent (QCloseEvent *); - void save (void); + void save (); - void cutClipboard (void); + void cutClipboard (); - void copyClipboard (void); + void copyClipboard (); - void pasteClipboard (void); + void pasteClipboard (); - void levelUp (void); + void levelUp (); protected: @@ -396,12 +387,12 @@ QList m_table_colors; - void update_colors (void); + void update_colors (); QAction * add_tool_bar_button (const QIcon& icon, const QString& text, const QObject *receiver, const char *member); - void construct_tool_bar (void); + void construct_tool_bar (); QString m_current_focus_vname; diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/welcome-wizard.cc --- a/libgui/src/welcome-wizard.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/welcome-wizard.cc Fri May 12 08:03:14 2023 +0200 @@ -39,7 +39,7 @@ #include "gui-preferences-dw.h" #include "gui-preferences-nr.h" -#include "octave-qobject.h" +#include "gui-settings.h" #include "welcome-wizard.h" OCTAVE_BEGIN_NAMESPACE(octave) @@ -53,10 +53,9 @@ return logo; }; -welcome_wizard::welcome_wizard (base_qobject& oct_qobj, QWidget *p) - : QDialog (p), m_octave_qobj (oct_qobj), m_page_ctor_list (), - m_page_list_iterator (), - m_current_page (initial_page::create (oct_qobj, this)), +welcome_wizard::welcome_wizard (QWidget *p) + : QDialog (p), m_page_ctor_list (), m_page_list_iterator (), + m_current_page (initial_page::create (this)), m_allow_web_connect_state (false), m_max_height (0), m_max_width (0) { @@ -92,7 +91,7 @@ #endif } -void welcome_wizard::adjust_size (void) +void welcome_wizard::adjust_size () { // Get adjusted size for the current page adjustSize (); @@ -112,12 +111,12 @@ m_allow_web_connect_state = state == Qt::Checked; } -void welcome_wizard::show_page (void) +void welcome_wizard::show_page () { delete m_current_page; delete layout (); - m_current_page = (*m_page_list_iterator) (m_octave_qobj, this); + m_current_page = (*m_page_list_iterator) (this); QVBoxLayout *new_layout = new QVBoxLayout (); setLayout (new_layout); @@ -125,41 +124,34 @@ new_layout->addWidget (m_current_page); } -void welcome_wizard::previous_page (void) +void welcome_wizard::previous_page () { --m_page_list_iterator; show_page (); } -void welcome_wizard::next_page (void) +void welcome_wizard::next_page () { ++m_page_list_iterator; show_page (); } -void welcome_wizard::accept (void) +void welcome_wizard::accept () { // Create default settings file. - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - rmgr.reload_settings (); - - gui_settings *settings = rmgr.get_settings (); + gui_settings settings; - if (settings) - { - settings->setValue (nr_allow_connection.key, - m_allow_web_connect_state); + settings.setValue (nr_allow_connection.settings_key (), m_allow_web_connect_state); - settings->sync (); - } + settings.sync (); QDialog::accept (); } -initial_page::initial_page (base_qobject& oct_qobj, welcome_wizard *wizard) +initial_page::initial_page (welcome_wizard *wizard) : QWidget (wizard), m_title (new QLabel (tr ("Welcome to Octave!"), this)), m_message (new QLabel (this)), @@ -171,7 +163,7 @@ ft.setPointSize (20); m_title->setFont (ft); - resource_manager& rmgr = oct_qobj.get_resource_manager (); + gui_settings settings; m_message->setText (tr ("\n" @@ -179,7 +171,7 @@ "Click 'Next' to create a configuration file and launch Octave.

\n" "

The configuration file is stored in
%1.

\n" ""). - arg (rmgr.get_settings_file ())); + arg (settings.file_name ())); m_message->setWordWrap (true); m_message->setMinimumWidth (400); @@ -217,8 +209,7 @@ connect (m_cancel, &QPushButton::clicked, wizard, &welcome_wizard::reject); } -setup_community_news::setup_community_news (base_qobject&, - welcome_wizard *wizard) +setup_community_news::setup_community_news (welcome_wizard *wizard) : QWidget (wizard), m_title (new QLabel (tr ("Community News"), this)), m_message (new QLabel (this)), @@ -257,7 +248,7 @@ QHBoxLayout *checkbox_layout = new QHBoxLayout; - bool allow_connection = nr_allow_connection.def.toBool (); + bool allow_connection = nr_allow_connection.def ().toBool (); if (allow_connection) m_checkbox->setCheckState (Qt::Checked); else @@ -311,7 +302,7 @@ connect (m_cancel, &QPushButton::clicked, wizard, &welcome_wizard::reject); } -final_page::final_page (base_qobject&, welcome_wizard *wizard) +final_page::final_page (welcome_wizard *wizard) : QWidget (wizard), m_title (new QLabel (tr ("Enjoy!"), this)), m_message (new QLabel (this)), diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/welcome-wizard.h --- a/libgui/src/welcome-wizard.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/welcome-wizard.h Fri May 12 08:03:14 2023 +0200 @@ -32,26 +32,22 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; - class welcome_wizard : public QDialog { Q_OBJECT public: - typedef QWidget *(*page_creator_fptr) (base_qobject&, welcome_wizard *); + typedef QWidget *(*page_creator_fptr) (welcome_wizard *); - welcome_wizard (base_qobject& oct_qobj, QWidget *parent = nullptr); + welcome_wizard (QWidget *parent = nullptr); - ~welcome_wizard (void) = default; + ~welcome_wizard () = default; - void adjust_size (void); + void adjust_size (); private: - base_qobject& m_octave_qobj; - QList m_page_ctor_list; QList::iterator m_page_list_iterator; QWidget *m_current_page; @@ -63,11 +59,11 @@ void handle_web_connect_option (int state); - void show_page (void); - void previous_page (void); - void next_page (void); + void show_page (); + void previous_page (); + void next_page (); - void accept (void); + void accept (); }; class initial_page : public QWidget @@ -76,14 +72,14 @@ public: - initial_page (base_qobject& oct_qobj, welcome_wizard *wizard); + initial_page (welcome_wizard *wizard); - ~initial_page (void) = default; + ~initial_page () = default; static QWidget * - create (base_qobject& oct_qobj, welcome_wizard *wizard) + create (welcome_wizard *wizard) { - return new initial_page (oct_qobj, wizard); + return new initial_page (wizard); } private: @@ -101,14 +97,14 @@ public: - setup_community_news (base_qobject& oct_qobj, welcome_wizard *wizard); + setup_community_news (welcome_wizard *wizard); - ~setup_community_news (void) = default; + ~setup_community_news () = default; static QWidget * - create (base_qobject& oct_qobj, welcome_wizard *wizard) + create (welcome_wizard *wizard) { - return new setup_community_news (oct_qobj, wizard); + return new setup_community_news (wizard); } private: @@ -129,14 +125,14 @@ public: - final_page (base_qobject& oct_qobj, welcome_wizard *wizard); + final_page (welcome_wizard *wizard); - ~final_page (void) = default; + ~final_page () = default; static QWidget * - create (base_qobject& oct_qobj, welcome_wizard *wizard) + create (welcome_wizard *wizard) { - return new final_page (oct_qobj, wizard); + return new final_page (wizard); } private: diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/workspace-model.cc --- a/libgui/src/workspace-model.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/workspace-model.cc Fri May 12 08:03:14 2023 +0200 @@ -27,13 +27,13 @@ # include "config.h" #endif -#include +#include #include +#include #include "gui-preferences-ws.h" #include "gui-settings.h" -#include "octave-qobject.h" #include "workspace-model.h" #include "syminfo.h" @@ -42,7 +42,7 @@ OCTAVE_BEGIN_NAMESPACE(octave) workspace_model::workspace_model (QObject *p) -: QAbstractTableModel (p) + : QAbstractTableModel (p) { // The header names. Use tr () again when accessing them since // the translator si not yet initialized when this ctor is called @@ -191,22 +191,24 @@ } void -workspace_model::clear_workspace (void) +workspace_model::clear_workspace () { clear_data (); update_table (); } void -workspace_model::notice_settings (const gui_settings *settings) +workspace_model::notice_settings () { - m_enable_colors = settings->value (ws_enable_colors).toBool (); + gui_settings settings; - int mode = settings->value (ws_color_mode).toInt (); + m_enable_colors = settings.bool_value (ws_enable_colors); + + int mode = settings.int_value (ws_color_mode); for (int i = 0; i < ws_colors_count; i++) { - QColor setting_color = settings->color_value (ws_colors[i], mode); + QColor setting_color = settings.color_value (ws_colors[i], mode); QPalette p (setting_color); m_storage_class_colors.replace (i, setting_color); @@ -218,7 +220,19 @@ } void -workspace_model::clear_data (void) +workspace_model::show_symbol_tooltip (const QPoint& pos, + const QString& symbol) +{ + int symbol_idx = m_symbols.indexOf (symbol); + + if (symbol_idx > -1) + QToolTip::showText (pos, symbol + " = " + m_values.at (symbol_idx)); + else + QToolTip::hideText (); +} + +void +workspace_model::clear_data () { m_top_level = false; m_syminfo_list = symbol_info_list (); @@ -231,7 +245,7 @@ } void -workspace_model::update_table (void) +workspace_model::update_table () { beginResetModel (); diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/workspace-model.h --- a/libgui/src/workspace-model.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/workspace-model.h Fri May 12 08:03:14 2023 +0200 @@ -34,8 +34,6 @@ #include #include -#include "gui-settings.h" - #include "syminfo.h" // Defined for purposes of sending QList as part of signal. @@ -51,7 +49,7 @@ workspace_model (QObject *parent = nullptr); - ~workspace_model (void) = default; + ~workspace_model () = default; int rowCount (const QModelIndex& parent = QModelIndex ()) const; @@ -64,36 +62,38 @@ QVariant data (const QModelIndex& index, int role) const; - bool is_top_level (void) const { return m_top_level; } + bool is_top_level () const { return m_top_level; } QColor storage_class_color (int s_class) { return m_storage_class_colors.at (s_class); } - symbol_info_list get_symbol_info (void) const { return m_syminfo_list; } + symbol_info_list get_symbol_info () const { return m_syminfo_list; } - QStringList get_symbol_names (void) const { return m_symbols; } - QStringList get_symbol_values (void) const { return m_values; } + QStringList get_symbol_names () const { return m_symbols; } + QStringList get_symbol_values () const { return m_values; } signals: - void model_changed (void); - void prompt_variable_editor(void); + void model_changed (); + void prompt_variable_editor(); public slots: void set_workspace (bool top_level, bool debug, const symbol_info_list& syminfo); - void clear_workspace (void); + void clear_workspace (); - void notice_settings (const gui_settings *); + void notice_settings (); + + void show_symbol_tooltip (const QPoint& pos, const QString& symbol); private: - void clear_data (void); - void update_table (void); + void clear_data (); + void update_table (); bool m_top_level; symbol_info_list m_syminfo_list; diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/workspace-view.cc --- a/libgui/src/workspace-view.cc Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/workspace-view.cc Fri May 12 08:03:14 2023 +0200 @@ -42,25 +42,24 @@ #include #include "gui-preferences-ws.h" -#include "octave-qobject.h" -#include "octave-qtutils.h" +#include "gui-settings.h" #include "workspace-view.h" OCTAVE_BEGIN_NAMESPACE(octave) -workspace_view::workspace_view (QWidget *p, base_qobject& oct_qobj) -: octave_dock_widget ("WorkspaceView", p, oct_qobj), - m_view (new QTableView (this)), - m_filter_checkbox (new QCheckBox ()), - m_filter (new QComboBox (this)), - m_filter_widget (new QWidget (this)) +workspace_view::workspace_view (QWidget *p) + : octave_dock_widget ("WorkspaceView", p), + m_view (new QTableView (this)), + m_filter_checkbox (new QCheckBox ()), + m_filter (new QComboBox (this)), + m_filter_widget (new QWidget (this)) { set_title (tr ("Workspace")); setStatusTip (tr ("View the variables in the active workspace.")); m_filter->setToolTip (tr ("Enter text to filter the workspace")); m_filter->setEditable (true); - m_filter->setMaxCount (ws_max_filter_history.def.toInt ()); + m_filter->setMaxCount (ws_max_filter_history.def ().toInt ()); m_filter->setInsertPolicy (QComboBox::NoInsert); m_filter->setSizeAdjustPolicy (QComboBox::AdjustToMinimumContentsLengthWithIcon); QSizePolicy sizePol (QSizePolicy::Expanding, QSizePolicy::Preferred); @@ -85,7 +84,7 @@ filter_layout->addWidget (filter_label); filter_layout->addWidget (m_filter_checkbox); filter_layout->addWidget (m_filter); - filter_layout->setMargin (0); + filter_layout->setContentsMargins (0, 0, 0, 0); m_filter_widget->setLayout (filter_layout); @@ -94,51 +93,46 @@ ws_layout->addWidget (m_view); ws_layout->setSpacing (0); - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); + gui_settings settings; - if (settings) - { - m_filter_shown = settings->value (ws_filter_shown).toBool (); - m_filter_widget->setVisible (m_filter_shown); + m_filter_shown = settings.bool_value (ws_filter_shown); + m_filter_widget->setVisible (m_filter_shown); - ws_layout->setMargin (2); + ws_layout->setContentsMargins (2, 2, 2, 2); - // Set the empty widget to have our layout. - widget ()->setLayout (ws_layout); + // Set the empty widget to have our layout. + widget ()->setLayout (ws_layout); - // Initialize collapse/expand state of the workspace subcategories. + // Initialize collapse/expand state of the workspace subcategories. - //enable sorting (setting column and order after model was set) - m_view->setSortingEnabled (true); - // Initialize column order and width of the workspace - m_view->horizontalHeader ()->restoreState - (settings->value (ws_column_state.key).toByteArray ()); + //enable sorting (setting column and order after model was set) + m_view->setSortingEnabled (true); + // Initialize column order and width of the workspace + m_view->horizontalHeader ()->restoreState + (settings.value (ws_column_state.settings_key ()).toByteArray ()); - // Set header properties for sorting - m_view->horizontalHeader ()->setSectionsClickable (true); - m_view->horizontalHeader ()->setSectionsMovable (true); - m_view->horizontalHeader ()->setSortIndicator ( - settings->value (ws_sort_column).toInt (), - static_cast (settings->value (ws_sort_order).toUInt ())); - // FIXME: use value instead of static cast after - // dropping support of Qt 5.4 + // Set header properties for sorting + m_view->horizontalHeader ()->setSectionsClickable (true); + m_view->horizontalHeader ()->setSectionsMovable (true); + m_view->horizontalHeader ()->setSortIndicator + (settings.int_value (ws_sort_column), + static_cast (settings.uint_value (ws_sort_order))); + // FIXME: use value instead of static cast after + // dropping support of Qt 5.4 - m_view->horizontalHeader ()->setSortIndicatorShown (true); + m_view->horizontalHeader ()->setSortIndicatorShown (true); - m_view->horizontalHeader ()->setContextMenuPolicy (Qt::CustomContextMenu); - connect (m_view->horizontalHeader (), - &QTableView::customContextMenuRequested, - this, &workspace_view::header_contextmenu_requested); + m_view->horizontalHeader ()->setContextMenuPolicy (Qt::CustomContextMenu); + connect (m_view->horizontalHeader (), + &QTableView::customContextMenuRequested, + this, &workspace_view::header_contextmenu_requested); - // Init state of the filter - m_filter->addItems (settings->value (ws_mru_list.key).toStringList ()); + // Init state of the filter + m_filter->addItems (settings.value (ws_mru_list.settings_key ()).toStringList ()); - bool filter_state = - settings->value (ws_filter_active).toBool (); - m_filter_checkbox->setChecked (filter_state); - filter_activate (filter_state); - } + bool filter_state = settings.bool_value (ws_filter_active); + m_filter_checkbox->setChecked (filter_state); + filter_activate (filter_state); // Connect signals and slots. @@ -167,29 +161,32 @@ m_view->setModel (&m_filter_model); // set the sorting after the model is set, it would be ignored otherwise - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - m_view->sortByColumn ( - settings->value (ws_sort_column).toInt (), - static_cast (settings->value (ws_sort_order).toUInt ())); - // FIXME: use value instead of static cast after - // dropping support of Qt 5.4 + + gui_settings settings; + + m_view->sortByColumn + (settings.int_value (ws_sort_column), + static_cast (settings.uint_value (ws_sort_order))); + // FIXME: use value instead of static cast after + // dropping support of Qt 5.4 m_model = model; } void -workspace_view::notice_settings (const gui_settings *settings) +workspace_view::notice_settings () { - m_model->notice_settings (settings); // update colors of model first + gui_settings settings; + + m_model->notice_settings (); // update colors of model first for (int i = 0; i < ws_columns_shown.length (); i++) - m_view->setColumnHidden (i + 1, ! settings->value (ws_columns_shown_keys.at (i), true).toBool ()); + m_view->setColumnHidden (i + 1, ! settings.value (ws_columns_shown_keys.at (i), true).toBool ()); QString tool_tip; - if (settings->value (ws_enable_colors).toBool () - && ! settings->value (ws_hide_tool_tips).toBool ()) + if (settings.bool_value (ws_enable_colors) + && ! settings.bool_value (ws_hide_tool_tips)) { tool_tip = QString (tr ("View the variables in the active workspace.
")); tool_tip += QString (tr ("Colors for variable attributes:")); @@ -209,31 +206,27 @@ } void -workspace_view::save_settings (void) +workspace_view::save_settings () { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); + gui_settings settings; - if (! settings) - return; - - settings->setValue (ws_column_state.key, - m_view->horizontalHeader ()->saveState ()); + settings.setValue (ws_column_state.settings_key (), + m_view->horizontalHeader ()->saveState ()); int sort_column = m_view->horizontalHeader ()->sortIndicatorSection (); Qt::SortOrder sort_order = m_view->horizontalHeader ()->sortIndicatorOrder (); - settings->setValue (ws_sort_column.key, sort_column); - settings->setValue (ws_sort_order.key, sort_order); + settings.setValue (ws_sort_column.settings_key (), sort_column); + settings.setValue (ws_sort_order.settings_key (), sort_order); - settings->setValue (ws_filter_active.key, m_filter_checkbox->isChecked ()); - settings->setValue (ws_filter_shown.key, m_filter_shown); + settings.setValue (ws_filter_active.settings_key (), m_filter_checkbox->isChecked ()); + settings.setValue (ws_filter_shown.settings_key (), m_filter_shown); QStringList mru; for (int i = 0; i < m_filter->count (); i++) mru.append (m_filter->itemText (i)); - settings->setValue (ws_mru_list.key, mru); + settings.setValue (ws_mru_list.settings_key (), mru); - settings->sync (); + settings.sync (); octave_dock_widget::save_settings (); } @@ -274,7 +267,7 @@ } void -workspace_view::update_filter_history (void) +workspace_view::update_filter_history () { QString text = m_filter->currentText (); // get current text int index = m_filter->findText (text); // and its actual index @@ -292,8 +285,7 @@ QMenu menu (this); QSignalMapper sig_mapper (this); - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); + gui_settings settings; for (int i = 0; i < ws_columns_shown.length (); i++) { @@ -302,7 +294,7 @@ &sig_mapper, SLOT (map ())); sig_mapper.setMapping (action, i); action->setCheckable (true); - action->setChecked (settings->value (ws_columns_shown_keys.at (i), true).toBool ()); + action->setChecked (settings.value (ws_columns_shown_keys.at (i), true).toBool ()); } // FIXME: We could use @@ -328,16 +320,15 @@ void workspace_view::toggle_header (int col) { - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); + gui_settings settings; QString key = ws_columns_shown_keys.at (col); - bool shown = settings->value (key, true).toBool (); + bool shown = settings.value (key, true).toBool (); m_view->setColumnHidden (col + 1, shown); - settings->setValue (key, ! shown); - settings->sync (); + settings.setValue (key, ! shown); + settings.sync (); octave_dock_widget::save_settings (); } @@ -404,7 +395,7 @@ } void -workspace_view::handle_contextmenu_copy (void) +workspace_view::handle_contextmenu_copy () { QModelIndex index = m_view->currentIndex (); @@ -419,7 +410,7 @@ } void -workspace_view::handle_contextmenu_copy_value (void) +workspace_view::handle_contextmenu_copy_value () { QModelIndex index = m_view->currentIndex (); @@ -428,7 +419,7 @@ } void -workspace_view::handle_contextmenu_rename (void) +workspace_view::handle_contextmenu_rename () { QModelIndex index = m_view->currentIndex (); @@ -452,7 +443,7 @@ } void -workspace_view::handle_contextmenu_edit (void) +workspace_view::handle_contextmenu_edit () { QModelIndex index = m_view->currentIndex (); @@ -461,31 +452,31 @@ } void -workspace_view::handle_contextmenu_clear (void) +workspace_view::handle_contextmenu_clear () { relay_contextmenu_command ("clear", true); } void -workspace_view::handle_contextmenu_disp (void) +workspace_view::handle_contextmenu_disp () { relay_contextmenu_command ("disp"); } void -workspace_view::handle_contextmenu_plot (void) +workspace_view::handle_contextmenu_plot () { relay_contextmenu_command ("figure (); plot"); } void -workspace_view::handle_contextmenu_stem (void) +workspace_view::handle_contextmenu_stem () { relay_contextmenu_command ("figure (); stem"); } void -workspace_view::handle_contextmenu_filter (void) +workspace_view::handle_contextmenu_filter () { m_filter_shown = ! m_filter_shown; m_filter_widget->setVisible (m_filter_shown); @@ -494,7 +485,7 @@ } void -workspace_view::handle_model_changed (void) +workspace_view::handle_model_changed () { // m_view->resizeRowsToContents (); // Just modify those rows that have been added rather than go through diff -r e2911d0176dc -r 212145b8e5f0 libgui/src/workspace-view.h --- a/libgui/src/workspace-view.h Fri May 12 08:00:41 2023 +0200 +++ b/libgui/src/workspace-view.h Fri May 12 08:03:14 2023 +0200 @@ -39,17 +39,15 @@ OCTAVE_BEGIN_NAMESPACE(octave) -class base_qobject; - class workspace_view : public octave_dock_widget { Q_OBJECT public: - workspace_view (QWidget *parent, base_qobject& oct_qobj); + workspace_view (QWidget *parent); - ~workspace_view (void) = default; + ~workspace_view () = default; signals: @@ -74,15 +72,15 @@ void setModel (workspace_model *model); - void notice_settings (const gui_settings *); + void notice_settings (); - void save_settings (void); + void save_settings (); protected slots: void filter_update (const QString& expression); void filter_activate (bool enable); - void update_filter_history (void); + void update_filter_history (); void header_contextmenu_requested (const QPoint& mpos); @@ -90,22 +88,22 @@ void contextmenu_requested (const QPoint& pos); - void handle_contextmenu_copy (void); - void handle_contextmenu_copy_value (void); - void handle_contextmenu_rename (void); - void handle_contextmenu_edit (void); - void handle_contextmenu_clear (void); - void handle_contextmenu_disp (void); - void handle_contextmenu_plot (void); - void handle_contextmenu_stem (void); - void handle_contextmenu_filter (void); + void handle_contextmenu_copy (); + void handle_contextmenu_copy_value (); + void handle_contextmenu_rename (); + void handle_contextmenu_edit (); + void handle_contextmenu_clear (); + void handle_contextmenu_disp (); + void handle_contextmenu_plot (); + void handle_contextmenu_stem (); + void handle_contextmenu_filter (); public slots: - void handle_model_changed (void); + void handle_model_changed (); - void copyClipboard (void); - void selectAll (void); + void copyClipboard (); + void selectAll (); private: diff -r e2911d0176dc -r 212145b8e5f0 libinterp/build-env.h --- a/libinterp/build-env.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/build-env.h Fri May 12 08:03:14 2023 +0200 @@ -34,7 +34,7 @@ OCTAVE_BEGIN_NAMESPACE(build_env) -extern OCTINTERP_API octave_scalar_map features (void); +extern OCTINTERP_API octave_scalar_map features (); extern OCTINTERP_API const char *AMD_CPPFLAGS; extern OCTINTERP_API const char *AMD_LDFLAGS; @@ -144,7 +144,6 @@ extern OCTINTERP_API const char *QT_CPPFLAGS; extern OCTINTERP_API const char *QT_LDFLAGS; extern OCTINTERP_API const char *QT_LIBS; -extern OCTINTERP_API const char *QT_OPENGL_LIBS; extern OCTINTERP_API const char *RANLIB; extern OCTINTERP_API const char *RDYNAMIC_FLAG; extern OCTINTERP_API const char *READLINE_LIBS; diff -r e2911d0176dc -r 212145b8e5f0 libinterp/build-env.in.cc --- a/libinterp/build-env.in.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/build-env.in.cc Fri May 12 08:03:14 2023 +0200 @@ -251,8 +251,6 @@ const char *QT_LIBS = %OCTAVE_CONF_QT_LIBS%; -const char *QT_OPENGL_LIBS = %OCTAVE_CONF_QT_OPENGL_LIBS%; - const char *RANLIB = %OCTAVE_CONF_RANLIB%; const char *RDYNAMIC_FLAG = %OCTAVE_CONF_RDYNAMIC_FLAG%; diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/Cell.cc --- a/libinterp/corefcn/Cell.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/Cell.cc Fri May 12 08:03:14 2023 +0200 @@ -123,7 +123,7 @@ } bool -Cell::iscellstr (void) const +Cell::iscellstr () const { bool retval = true; @@ -142,7 +142,7 @@ } Array -Cell::cellstr_value (void) const +Cell::cellstr_value () const { Array retval (dims ()); @@ -155,7 +155,7 @@ } string_vector -Cell::string_vector_value (void) const +Cell::string_vector_value () const { octave_idx_type n = numel (); @@ -288,7 +288,7 @@ } octave_idx_type -Cell::nnz (void) const +Cell::nnz () const { err_wrong_type_arg ("nnz", "cell array"); } @@ -355,7 +355,7 @@ } octave_value -Cell::resize_fill_value (void) const +Cell::resize_fill_value () const { static octave_value rfv = octave_value (Matrix ()); return rfv; diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/Cell.h --- a/libinterp/corefcn/Cell.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/Cell.h Fri May 12 08:03:14 2023 +0200 @@ -43,13 +43,13 @@ { public: - Cell (void) = default; + Cell () = default; Cell (const Cell& c) = default; Cell& operator = (const Cell& c) = default; - ~Cell (void) = default; + ~Cell () = default; Cell (const octave_value& val) : Array (dim_vector (1, 1), val) { } @@ -97,11 +97,11 @@ Cell (const dim_vector& dv, const string_vector& sv, bool trim = false); - bool iscellstr (void) const; + bool iscellstr () const; - Array cellstr_value (void) const; + Array cellstr_value () const; - string_vector string_vector_value (void) const; + string_vector string_vector_value () const; using Array::index; @@ -119,7 +119,7 @@ Cell reshape (const dim_vector& new_dims) const { return Array::reshape (new_dims); } - octave_idx_type nnz (void) const; + octave_idx_type nnz () const; Cell column (octave_idx_type i) const; @@ -135,33 +135,33 @@ Cell& insert (const Cell& a, const Array& ra_idx); // FIXME - bool any_element_is_nan (void) const { return false; } - bool is_true (void) const { return false; } + bool any_element_is_nan () const { return false; } + bool is_true () const { return false; } - octave_value resize_fill_value (void) const; + octave_value resize_fill_value () const; Cell diag (octave_idx_type k = 0) const; Cell diag (octave_idx_type m, octave_idx_type n) const; - Cell xisalnum (void) const { return map (&octave_value::xisalnum); } - Cell xisalpha (void) const { return map (&octave_value::xisalpha); } - Cell xisascii (void) const { return map (&octave_value::xisascii); } - Cell xiscntrl (void) const { return map (&octave_value::xiscntrl); } - Cell xisdigit (void) const { return map (&octave_value::xisdigit); } - Cell xisgraph (void) const { return map (&octave_value::xisgraph); } - Cell xislower (void) const { return map (&octave_value::xislower); } - Cell xisprint (void) const { return map (&octave_value::xisprint); } - Cell xispunct (void) const { return map (&octave_value::xispunct); } - Cell xisspace (void) const { return map (&octave_value::xisspace); } - Cell xisupper (void) const { return map (&octave_value::xisupper); } - Cell xisxdigit (void) const { return map (&octave_value::xisxdigit); } - Cell xtolower (void) const { return map (&octave_value::xtolower); } - Cell xtoupper (void) const { return map (&octave_value::xtoupper); } + Cell xisalnum () const { return map (&octave_value::xisalnum); } + Cell xisalpha () const { return map (&octave_value::xisalpha); } + Cell xisascii () const { return map (&octave_value::xisascii); } + Cell xiscntrl () const { return map (&octave_value::xiscntrl); } + Cell xisdigit () const { return map (&octave_value::xisdigit); } + Cell xisgraph () const { return map (&octave_value::xisgraph); } + Cell xislower () const { return map (&octave_value::xislower); } + Cell xisprint () const { return map (&octave_value::xisprint); } + Cell xispunct () const { return map (&octave_value::xispunct); } + Cell xisspace () const { return map (&octave_value::xisspace); } + Cell xisupper () const { return map (&octave_value::xisupper); } + Cell xisxdigit () const { return map (&octave_value::xisxdigit); } + Cell xtolower () const { return map (&octave_value::xtolower); } + Cell xtoupper () const { return map (&octave_value::xtoupper); } private: - typedef octave_value (octave_value::*ctype_mapper) (void) const; + typedef octave_value (octave_value::*ctype_mapper) () const; Cell map (ctype_mapper) const; }; diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/__contourc__.cc --- a/libinterp/corefcn/__contourc__.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/__contourc__.cc Fri May 12 08:03:14 2023 +0200 @@ -71,7 +71,7 @@ // Add contents of current contour to contourc. // this_contour.cols () - 1; static void -end_contour (void) +end_contour () { if (elem > 2) { diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/__eigs__.cc --- a/libinterp/corefcn/__eigs__.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/__eigs__.cc Fri May 12 08:03:14 2023 +0200 @@ -53,6 +53,10 @@ { public: + eigs_callback (octave::interpreter& interp) + : m_interpreter (interp) + { } + ColumnVector eigs_func (const ColumnVector& x, int& eigs_error); @@ -61,6 +65,8 @@ //-------- + octave::interpreter& m_interpreter; + // Pointer for user defined function. octave_value m_eigs_fcn; @@ -84,7 +90,7 @@ try { - tmp = octave::feval (m_eigs_fcn, args, 1); + tmp = m_interpreter.feval (m_eigs_fcn, args, 1); } catch (octave::execution_exception& ee) { @@ -125,7 +131,7 @@ try { - tmp = octave::feval (m_eigs_fcn, args, 1); + tmp = m_interpreter.feval (m_eigs_fcn, args, 1); } catch (octave::execution_exception& ee) { @@ -213,7 +219,7 @@ ComplexColumnVector cresid; octave_idx_type info = 1; - eigs_callback callback; + eigs_callback callback (interp); unwind_protect_var restore_var (call_depth); call_depth++; diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/__ftp__.cc --- a/libinterp/corefcn/__ftp__.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/__ftp__.cc Fri May 12 08:03:14 2023 +0200 @@ -367,12 +367,10 @@ { std::string file = files(i); - sys::file_stat fs (file); - - if (! fs.exists ()) + if (! sys::file_exists (file)) error ("__ftp__mput: file does not exist"); - if (fs.is_dir ()) + if (sys::dir_exists (file)) { file_list.append (url_xfer.mput_directory ("", file)); diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/__ichol__.cc --- a/libinterp/corefcn/__ichol__.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/__ichol__.cc Fri May 12 08:03:14 2023 +0200 @@ -117,7 +117,7 @@ iw[ridx[j]] = j; jrow = Llist[k]; - // Iterate over each non-zero element in the actual row. + // Iterate over each nonzero element in the actual row. while (jrow != -1) { jjrow = Lfirst[jrow]; @@ -201,7 +201,7 @@ // matrix is used to build the output matrix due to that fact. if (! args(0).iscomplex ()) { - SparseMatrix sm = Ftril (args(0))(0).sparse_matrix_value (); + SparseMatrix sm = Ftril (ovl (args(0)))(0).sparse_matrix_value (); ichol_0 (sm, michol); return ovl (sm); @@ -209,7 +209,7 @@ else { SparseComplexMatrix sm - = Ftril (args(0))(0).sparse_complex_matrix_value (); + = Ftril (ovl (args(0)))(0).sparse_complex_matrix_value (); ichol_0 (sm, michol); return ovl (sm); @@ -296,8 +296,8 @@ { j = ridx_l[jj]; // If the element in the j position of the row is zero, - // then it will become non-zero, so we add it to the - // vector that tracks non-zero elements in the working row. + // then it will become nonzero, so we add it to the + // vector that tracks nonzero elements in the working row. if (! mark[j]) { mark[j] = true; @@ -330,7 +330,7 @@ ridx_l = ridx_out_l.fortran_vec (); } - // The sorting of the non-zero elements of the working column can be + // The sorting of the nonzero elements of the working column can be // handled in a couple of ways. The most efficient two I found, are // keeping the elements in an ordered binary search tree dynamically or // keep them unsorted in a vector and at the end of the outer iteration @@ -341,7 +341,7 @@ ridx_l[total_len] = k; w_len = 1; - // Extract the non-zero elements of working column and + // Extract the nonzero elements of working column and // drop the elements that are lower than droptol * cols_norm[k]. for (i = 0; i < ind ; i++) { @@ -434,7 +434,7 @@ if (! args(0).iscomplex ()) { SparseMatrix L; - SparseMatrix sm_l = Ftril (args(0))(0).sparse_matrix_value (); + SparseMatrix sm_l = Ftril (ovl (args(0)))(0).sparse_matrix_value (); RowVector sm_col_norms = xcolnorms (sm_l, 1); ichol_t @@ -446,7 +446,7 @@ { SparseComplexMatrix L; SparseComplexMatrix sm_l - = Ftril (args(0))(0).sparse_complex_matrix_value (); + = Ftril (ovl (args(0)))(0).sparse_complex_matrix_value (); Array cols_norm = xcolnorms (sm_l, 1); ichol_t diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/__magick_read__.cc --- a/libinterp/corefcn/__magick_read__.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/__magick_read__.cc Fri May 12 08:03:14 2023 +0200 @@ -181,6 +181,8 @@ { public: + image_region () = delete; + image_region (const octave_scalar_map& options) { // FIXME: should we have better checking on the input map and values @@ -208,36 +210,28 @@ m_col_out = cols.numel (); } - // Default copy, move, and delete methods are all OK for this class. - - image_region (const image_region&) = default; - image_region (image_region&&) = default; + OCTAVE_DEFAULT_COPY_MOVE_DELETE (image_region) - image_region& operator = (const image_region&) = default; - image_region& operator = (image_region&&) = default; - - ~image_region (void) = default; - - octave_idx_type row_start (void) const { return m_row_start; } - octave_idx_type col_start (void) const { return m_col_start; } - octave_idx_type row_end (void) const { return m_row_end; } - octave_idx_type col_end (void) const { return m_col_end; } + octave_idx_type row_start () const { return m_row_start; } + octave_idx_type col_start () const { return m_col_start; } + octave_idx_type row_end () const { return m_row_end; } + octave_idx_type col_end () const { return m_col_end; } // Length of the area to load into the Image Pixel Cache. We use max and // min to account for cases where last element of range is the range limit. - octave_idx_type row_cache (void) const { return m_row_cache; } - octave_idx_type col_cache (void) const { return m_col_cache; } + octave_idx_type row_cache () const { return m_row_cache; } + octave_idx_type col_cache () const { return m_col_cache; } // How much we have to shift in the memory when doing the loops. - octave_idx_type row_shift (void) const { return m_row_shift; } - octave_idx_type col_shift (void) const { return m_col_shift; } + octave_idx_type row_shift () const { return m_row_shift; } + octave_idx_type col_shift () const { return m_col_shift; } // The actual height and width of the output image - octave_idx_type row_out (void) const { return m_row_out; } - octave_idx_type col_out (void) const { return m_col_out; } + octave_idx_type row_out () const { return m_row_out; } + octave_idx_type col_out () const { return m_col_out; } private: @@ -343,7 +337,7 @@ retval(0) = octave_value (img); // Only bother reading the colormap if it was requested as output. - if (nargout > 1) + if (nargout >= 2) { // In theory, it should be possible for each frame of an image to // have different colormaps but for Matlab compatibility, we only @@ -355,22 +349,31 @@ retval(1) = maps(0); - // only interpret alpha channel if it exists and was requested as output - if (imvec[def_elem].matte () && nargout >= 3) + // only interpret alpha channel if it was requested as output + if (nargout >= 3) { - const Matrix amap = maps(1).matrix_value (); - const double *amap_fvec = amap.data (); + if (imvec[def_elem].matte ()) + { + // Alpha channel exists. + const Matrix amap = maps(1).matrix_value (); + const double *amap_fvec = amap.data (); + + NDArray alpha (dim_vector (nRows, nCols, 1, nFrames)); + double *alpha_fvec = alpha.fortran_vec (); - NDArray alpha (dim_vector (nRows, nCols, 1, nFrames)); - double *alpha_fvec = alpha.fortran_vec (); + // GraphicsMagick stores the alpha values inverted, i.e., + // 1 for transparent and 0 for opaque so we fix that here. + const octave_idx_type nPixels = alpha.numel (); + for (octave_idx_type pix = 0; pix < nPixels; pix++) + alpha_fvec[pix] = 1 - amap_fvec[static_cast (img_fvec[3])]; - // GraphicsMagick stores the alpha values inverted, i.e., - // 1 for transparent and 0 for opaque so we fix that here. - const octave_idx_type nPixels = alpha.numel (); - for (octave_idx_type pix = 0; pix < nPixels; pix++) - alpha_fvec[pix] = 1 - amap_fvec[static_cast (img_fvec[3])]; - - retval(2) = alpha; + retval(2) = alpha; + } + else + { + // No alpha channel. Return empty matrix. + retval(2) = Matrix (); + } } } @@ -785,7 +788,7 @@ } static void -maybe_initialize_magick (void) +maybe_initialize_magick () { static bool initialized = false; @@ -1589,7 +1592,7 @@ // If writemode is set to append, read the image and append to it. Even // if set to append, make sure that something was read at all. const std::string writemode = options.getfield ("writemode").string_value (); - if (writemode == "append" && sys::file_stat (filename).exists ()) + if (writemode == "append" && sys::file_exists (filename)) { std::vector ini_imvec; read_file (filename, ini_imvec); diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/amd.cc --- a/libinterp/corefcn/amd.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/amd.cc Fri May 12 08:03:14 2023 +0200 @@ -132,8 +132,7 @@ AMD_NAME (_defaults) (Control); if (nargin > 1) { - octave_scalar_map arg1 = args( - 1).xscalar_map_value ("amd: OPTS argument must be a scalar structure"); + octave_scalar_map arg1 = args(1).xscalar_map_value ("amd: OPTS argument must be a scalar structure"); octave_value tmp; diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/auto-shlib.cc --- a/libinterp/corefcn/auto-shlib.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/auto-shlib.cc Fri May 12 08:03:14 2023 +0200 @@ -34,7 +34,7 @@ OCTAVE_BEGIN_NAMESPACE(octave) -auto_shlib::auto_shlib (void) +auto_shlib::auto_shlib () : dynamic_library (get_current_shlib ()) { } diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/auto-shlib.h --- a/libinterp/corefcn/auto-shlib.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/auto-shlib.h Fri May 12 08:03:14 2023 +0200 @@ -43,9 +43,9 @@ { public: - auto_shlib (void); + auto_shlib (); - ~auto_shlib (void) = default; + ~auto_shlib () = default; auto_shlib (const auto_shlib&) = default; diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/base-text-renderer.h --- a/libinterp/corefcn/base-text-renderer.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/base-text-renderer.h Fri May 12 08:03:14 2023 +0200 @@ -53,15 +53,11 @@ ROTATION_270 = 3 }; - base_text_renderer (void) : text_processor () { } - - // No copying! + base_text_renderer () : text_processor () { } - base_text_renderer (const base_text_renderer&) = delete; + OCTAVE_DISABLE_COPY_MOVE (base_text_renderer) - base_text_renderer& operator = (const base_text_renderer&) = delete; - - virtual ~base_text_renderer (void) = default; + virtual ~base_text_renderer () = default; virtual void set_anti_aliasing (bool val) = 0; @@ -78,10 +74,10 @@ const std::string& angle, double size) = 0; virtual bool - ok (void) { return true; }; + ok () { return true; }; virtual octave_map - get_system_fonts (void) = 0; + get_system_fonts () = 0; virtual void set_color (const Matrix& c) = 0; diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/bsxfun.cc --- a/libinterp/corefcn/bsxfun.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/bsxfun.cc Fri May 12 08:03:14 2023 +0200 @@ -38,7 +38,6 @@ #include "oct-map.h" #include "ov-colon.h" #include "ov-fcn-handle.h" -#include "parse.h" #include "unwind-prot.h" #include "variables.h" @@ -131,7 +130,7 @@ return octave_value (bsxfun_pow (xa, ya)); } -static void maybe_fill_table (void) +static void maybe_fill_table () { static bool filled = false; if (filled) @@ -283,30 +282,6 @@ } } -#if 0 -// FIXME: this function is not used; is it OK to delete it? -static void -update_index (octave_value_list& idx, const dim_vector& dv, octave_idx_type i) -{ - octave_idx_type nd = dv.ndims (); - - if (i == 0) - { - for (octave_idx_type j = nd - 1; j > 0; j--) - idx(j) = octave_value (1.0); - idx(0) = octave_value (':'); - } - else - { - for (octave_idx_type j = 1; j < nd; j++) - { - idx (j) = octave_value (i % dv(j) + 1); - i /= dv(j); - } - } -} -#endif - static void update_index (Array& idx, const dim_vector& dv, octave_idx_type i) { @@ -414,14 +389,14 @@ octave_value_list inputs (2); inputs(0) = A; inputs(1) = B; - retval = feval (fcn, inputs, 1); + retval = interp.feval (fcn, inputs, 1); } else if (dvc.numel () < 1) { octave_value_list inputs (2); inputs(0) = A.resize (dvc); inputs(1) = B.resize (dvc); - retval = feval (fcn, inputs, 1); + retval = interp.feval (fcn, inputs, 1); } else { @@ -463,7 +438,7 @@ if (maybe_update_column (Bc, B, dvb, dvc, i, idxB)) inputs(1) = Bc; - octave_value_list tmp = feval (fcn, inputs, 1); + octave_value_list tmp = interp.feval (fcn, inputs, 1); #define BSXINIT(T, CLS, EXTRACTOR) \ (result_type == CLS) \ diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/c-file-ptr-stream.cc --- a/libinterp/corefcn/c-file-ptr-stream.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/c-file-ptr-stream.cc Fri May 12 08:03:14 2023 +0200 @@ -47,7 +47,7 @@ # define SEEK_END 2 #endif -c_file_ptr_buf::~c_file_ptr_buf (void) +c_file_ptr_buf::~c_file_ptr_buf () { buf_close (); } @@ -142,7 +142,7 @@ } int -c_file_ptr_buf::sync (void) +c_file_ptr_buf::sync () { flush (); @@ -150,13 +150,13 @@ } int -c_file_ptr_buf::flush (void) +c_file_ptr_buf::flush () { return m_f ? std::fflush (m_f) : traits_type::eof (); } int -c_file_ptr_buf::buf_close (void) +c_file_ptr_buf::buf_close () { int retval = -1; @@ -178,7 +178,7 @@ } off_t -c_file_ptr_buf::tell (void) +c_file_ptr_buf::tell () { return m_f ? octave_ftello_wrapper (m_f) : -1; } @@ -191,7 +191,7 @@ #if defined (HAVE_ZLIB) -c_zfile_ptr_buf::~c_zfile_ptr_buf (void) +c_zfile_ptr_buf::~c_zfile_ptr_buf () { buf_close (); } @@ -253,39 +253,17 @@ std::ios::seekdir /* dir */, std::ios::openmode) { - // FIXME -#if 0 - if (m_f) - { - gzseek (m_f, offset, seekdir_to_whence (dir)); - - return gztell (m_f); - } - else - return 0; -#endif return -1; } std::streampos c_zfile_ptr_buf::seekpos (std::streampos /* offset */, std::ios::openmode) { - // FIXME -#if 0 - if (m_f) - { - gzseek (m_f, offset, SEEK_SET); - - return gztell (m_f); - } - else - return 0; -#endif return -1; } int -c_zfile_ptr_buf::sync (void) +c_zfile_ptr_buf::sync () { flush (); @@ -293,7 +271,7 @@ } int -c_zfile_ptr_buf::flush (void) +c_zfile_ptr_buf::flush () { // FIXME: do we need something more complex here, passing // something other than 0 for the second argument to gzflush and @@ -303,7 +281,7 @@ } int -c_zfile_ptr_buf::buf_close (void) +c_zfile_ptr_buf::buf_close () { int retval = -1; diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/c-file-ptr-stream.h --- a/libinterp/corefcn/c-file-ptr-stream.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/c-file-ptr-stream.h Fri May 12 08:03:14 2023 +0200 @@ -46,25 +46,23 @@ typedef int (*close_fcn) (FILE *); - FILE * stdiofile (void) { return m_f; } + FILE * stdiofile () { return m_f; } + + c_file_ptr_buf () = delete; c_file_ptr_buf (FILE *f, close_fcn cf = file_close) : std::streambuf (), m_f (f), m_cf (cf) { } - // No copying! - - c_file_ptr_buf (const c_file_ptr_buf&) = delete; + OCTAVE_DISABLE_COPY_MOVE (c_file_ptr_buf) - c_file_ptr_buf& operator = (const c_file_ptr_buf&) = delete; - - ~c_file_ptr_buf (void); + ~c_file_ptr_buf (); int_type overflow (int_type); - int_type underflow (void) { return underflow_common (false); } + int_type underflow () { return underflow_common (false); } - int_type uflow (void) { return underflow_common (true); } + int_type uflow () { return underflow_common (true); } int_type pbackfail (int_type); @@ -78,19 +76,19 @@ std::streampos seekpos (std::streampos, std::ios::openmode = std::ios::in | std::ios::out); - int sync (void); + int sync (); - int flush (void); + int flush (); - int buf_close (void); + int buf_close (); int file_number () const { return m_f ? fileno (m_f) : -1; } int seek (off_t offset, int origin); - off_t tell (void); + off_t tell (); - void clear (void) { if (m_f) clearerr (m_f); } + void clear () { if (m_f) clearerr (m_f); } static int file_close (FILE *m_f); @@ -113,29 +111,27 @@ { public: + c_file_ptr_stream () = delete; + c_file_ptr_stream (FILE_T m_f, typename BUF_T::close_fcn m_cf = BUF_T::file_close) : STREAM_T (nullptr), m_buf (new BUF_T (m_f, m_cf)) { STREAM_T::init (m_buf); } - // No copying! + OCTAVE_DISABLE_COPY_MOVE (c_file_ptr_stream) - c_file_ptr_stream (const c_file_ptr_stream&) = delete; - - c_file_ptr_stream& operator = (const c_file_ptr_stream&) = delete; + ~c_file_ptr_stream () { delete m_buf; m_buf = nullptr; } - ~c_file_ptr_stream (void) { delete m_buf; m_buf = nullptr; } + BUF_T * rdbuf () { return m_buf; } - BUF_T * rdbuf (void) { return m_buf; } - - void stream_close (void) { if (m_buf) m_buf->buf_close (); } + void stream_close () { if (m_buf) m_buf->buf_close (); } int seek (off_t offset, int origin) { return m_buf ? m_buf->seek (offset, origin) : -1; } - off_t tell (void) { return m_buf ? m_buf->tell () : -1; } + off_t tell () { return m_buf ? m_buf->tell () : -1; } - void clear (void) { if (m_buf) m_buf->clear (); STREAM_T::clear (); } + void clear () { if (m_buf) m_buf->clear (); STREAM_T::clear (); } private: @@ -161,25 +157,23 @@ typedef int (*close_fcn) (gzFile); - gzFile stdiofile (void) { return m_f; } + gzFile stdiofile () { return m_f; } + + c_zfile_ptr_buf () = delete; c_zfile_ptr_buf (gzFile f, close_fcn cf = file_close) : std::streambuf (), m_f (f), m_cf (cf) { } - // No copying! - - c_zfile_ptr_buf (const c_zfile_ptr_buf&) = delete; + OCTAVE_DISABLE_COPY_MOVE (c_zfile_ptr_buf) - c_zfile_ptr_buf& operator = (const c_zfile_ptr_buf&) = delete; - - ~c_zfile_ptr_buf (void); + ~c_zfile_ptr_buf (); int_type overflow (int_type); - int_type underflow (void) { return underflow_common (false); } + int_type underflow () { return underflow_common (false); } - int_type uflow (void) { return underflow_common (true); } + int_type uflow () { return underflow_common (true); } int_type pbackfail (int_type); @@ -193,20 +187,20 @@ std::streampos seekpos (std::streampos, std::ios::openmode = std::ios::in | std::ios::out); - int sync (void); + int sync (); - int flush (void); + int flush (); - int buf_close (void); + int buf_close (); int file_number () const { return -1; } int seek (off_t offset, int origin) { return m_f ? gzseek (m_f, offset, origin) >= 0 : -1; } - off_t tell (void) { return m_f ? gztell (m_f) : -1; } + off_t tell () { return m_f ? gztell (m_f) : -1; } - void clear (void) { if (m_f) gzclearerr (m_f); } + void clear () { if (m_f) gzclearerr (m_f); } static int file_close (gzFile m_f) { return ::gzclose (m_f); } @@ -232,39 +226,4 @@ OCTAVE_END_NAMESPACE(octave) -#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS) - -OCTAVE_DEPRECATED (7, "use 'octave::i_c_file_ptr_stream' instead") -typedef octave::i_c_file_ptr_stream i_c_file_ptr_stream; - -OCTAVE_DEPRECATED (7, "use 'octave::o_c_file_ptr_stream' instead") -typedef octave::o_c_file_ptr_stream o_c_file_ptr_stream; - -OCTAVE_DEPRECATED (7, "use 'octave::io_c_file_ptr_stream' instead") -typedef octave::io_c_file_ptr_stream io_c_file_ptr_stream; - -// FIXME: HAVE_ZLIB is not defined here because we do not (and should -// not) include config.h in this header file. We need to find a way to -// define this interface without exposing gzFile. Should this be a -// private header that can only be used if included after config.h in an -// Octave source file and not inside another header file? - -# if defined (HAVE_ZLIB) - -OCTAVE_DEPRECATED (7, "use 'octave::i_c_zfile_ptr_stream' instead") -typedef octave::c_file_ptr_stream - i_c_zfile_ptr_stream; - -OCTAVE_DEPRECATED (7, "use 'octave::o_c_zfile_ptr_stream' instead") -typedef octave::c_file_ptr_stream - o_c_zfile_ptr_stream; - -OCTAVE_DEPRECATED (7, "use 'octave::io_c_zfile_ptr_stream' instead") -typedef octave::c_file_ptr_stream - io_c_zfile_ptr_stream; - -# endif - #endif - -#endif diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/call-stack.cc --- a/libinterp/corefcn/call-stack.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/call-stack.cc Fri May 12 08:03:14 2023 +0200 @@ -30,17 +30,17 @@ #include "lo-regexp.h" #include "str-vec.h" +#include "builtin-defun-decls.h" #include "call-stack.h" #include "defun.h" #include "interpreter.h" #include "interpreter-private.h" #include "oct-map.h" #include "ov.h" +#include "ov-fcn-handle.h" #include "ov-fcn.h" -#include "ov-fcn-handle.h" #include "ov-usr-fcn.h" #include "pager.h" -#include "parse.h" #include "stack-frame.h" #include "syminfo.h" #include "symrec.h" @@ -88,7 +88,7 @@ return fcn; } -int call_stack::current_line (void) const +int call_stack::current_line () const { int retval = -1; @@ -101,7 +101,7 @@ return retval; } -int call_stack::current_column (void) const +int call_stack::current_column () const { int retval = -1; @@ -114,7 +114,7 @@ return retval; } -octave_user_code *call_stack::current_user_code (void) const +octave_user_code *call_stack::current_user_code () const { // Start at current frame. @@ -133,7 +133,7 @@ return nullptr; } -int call_stack::current_user_code_line (void) const +int call_stack::current_user_code_line () const { // Start at current frame. @@ -157,7 +157,7 @@ return -1; } -int call_stack::current_user_code_column (void) const +int call_stack::current_user_code_column () const { // Start at current frame. @@ -181,7 +181,7 @@ return -1; } -unwind_protect *call_stack::curr_fcn_unwind_protect_frame (void) +unwind_protect *call_stack::curr_fcn_unwind_protect_frame () { // Start at current frame. @@ -200,7 +200,7 @@ return nullptr; } -octave_user_code *call_stack::debug_user_code (void) const +octave_user_code *call_stack::debug_user_code () const { octave_user_code *retval = nullptr; @@ -226,7 +226,7 @@ return retval; } -int call_stack::debug_user_code_line (void) const +int call_stack::debug_user_code_line () const { int retval = -1; @@ -255,7 +255,7 @@ return retval; } -int call_stack::debug_user_code_column (void) const +int call_stack::debug_user_code_column () const { int retval = -1; @@ -285,7 +285,7 @@ return retval; } -std::string call_stack::get_dispatch_class (void) const +std::string call_stack::get_dispatch_class () const { return m_cs[m_curr_frame]->get_dispatch_class (); } @@ -323,7 +323,7 @@ return retval; } -bool call_stack::all_scripts (void) const +bool call_stack::all_scripts () const { bool retval = true; @@ -486,7 +486,7 @@ return retval; } -std::size_t call_stack::find_current_user_frame (void) const +std::size_t call_stack::find_current_user_frame () const { std::size_t user_frame = m_curr_frame; @@ -503,7 +503,7 @@ return user_frame; } -std::shared_ptr call_stack::current_user_frame (void) const +std::shared_ptr call_stack::current_user_frame () const { std::size_t frame = find_current_user_frame (); @@ -616,7 +616,7 @@ // value of m_curr_frame would be wiped out when dbup returns and the // stack frame for dbup is popped. -void call_stack::goto_caller_frame (void) +void call_stack::goto_caller_frame () { std::size_t start = find_current_user_frame (); @@ -628,7 +628,7 @@ m_curr_frame = caller_frame ? caller_frame->index () : 0; } -void call_stack::goto_base_frame (void) +void call_stack::goto_base_frame () { if (m_curr_frame > 0) m_curr_frame = 0; @@ -669,7 +669,7 @@ } std::list> - call_stack::backtrace_frames (void) const + call_stack::backtrace_frames () const { octave_idx_type curr_user_frame = -1; @@ -699,7 +699,7 @@ return retval; } -std::list call_stack::backtrace_info (void) const +std::list call_stack::backtrace_info () const { octave_idx_type curr_user_frame = -1; @@ -740,19 +740,19 @@ return retval; } -octave_map call_stack::backtrace (void) const +octave_map call_stack::backtrace () const { octave_idx_type curr_user_frame = -1; return backtrace (curr_user_frame, true); } -octave_map call_stack::empty_backtrace (void) const +octave_map call_stack::empty_backtrace () const { return octave_map (dim_vector (0, 1), bt_fields); } -void call_stack::pop (void) +void call_stack::pop () { // Never pop top scope. // FIXME: is it possible for this case to happen? @@ -772,18 +772,18 @@ } } -void call_stack::clear (void) +void call_stack::clear () { while (! m_cs.empty ()) pop (); } -symbol_info_list call_stack::all_variables (void) +symbol_info_list call_stack::all_variables () { return m_cs[m_curr_frame]->all_variables (); } -std::list call_stack::global_variable_names (void) const +std::list call_stack::global_variable_names () const { std::list retval; @@ -798,12 +798,12 @@ return retval; } -std::list call_stack::top_level_variable_names (void) const +std::list call_stack::top_level_variable_names () const { return m_cs[0]->variable_names (); } -std::list call_stack::variable_names (void) const +std::list call_stack::variable_names () const { return m_cs[m_curr_frame]->variable_names (); } @@ -838,7 +838,7 @@ } } -void call_stack::clear_global_variables (void) +void call_stack::clear_global_variables () { for (auto& nm_ov : m_global_values) nm_ov.second = octave_value (); @@ -856,12 +856,12 @@ return m_cs[m_curr_frame]->regexp_symbol_info (pattern); } -symbol_info_list call_stack::get_symbol_info (void) +symbol_info_list call_stack::get_symbol_info () { return m_cs[m_curr_frame]->get_symbol_info (); } -symbol_info_list call_stack::top_scope_symbol_info (void) const +symbol_info_list call_stack::top_scope_symbol_info () const { return m_cs[0]->get_symbol_info (); } @@ -976,15 +976,17 @@ // Set up temporary scope. - symbol_scope tmp_scope ("$dummy_scope$"); + symbol_scope tmp_scope (file_name); push (tmp_scope); - unwind_action restore_scope ([=] (void) { pop (); }); + unwind_action restore_scope ([=] () { pop (); }); + + interpreter& interp = m_evaluator.get_interpreter (); - feval ("load", octave_value (file_name), 0); + Fload (interp, ovl (file_name)); - std::string newmsg = "Variables in the file " + file_name + ":\n\n"; + std::string newmsg = "Variables in the file " + file_name + ":\n"; if (global_only) return do_global_who_two (patterns, have_regexp, return_list, @@ -1109,7 +1111,7 @@ return octave_value (); } -void call_stack::display (void) const +void call_stack::display () const { std::ostream& os = octave_stdout; diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/call-stack.h --- a/libinterp/corefcn/call-stack.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/call-stack.h Fri May 12 08:03:14 2023 +0200 @@ -73,39 +73,39 @@ octave_function * current_function (bool skip_first = false) const; - octave_function * caller_function (void) const + octave_function * caller_function () const { return current_function (true); } // Current line in current function. - int current_line (void) const; + int current_line () const; // Current column in current function. - int current_column (void) const; + int current_column () const; - std::size_t current_frame (void) const { return m_curr_frame; } + std::size_t current_frame () const { return m_curr_frame; } - std::size_t size (void) const { return m_cs.size (); } + std::size_t size () const { return m_cs.size (); } - std::shared_ptr get_current_stack_frame (void) const + std::shared_ptr get_current_stack_frame () const { return m_cs[m_curr_frame]; } - symbol_scope top_scope (void) const + symbol_scope top_scope () const { return m_cs[0]->get_scope (); } - symbol_scope current_scope (void) const + symbol_scope current_scope () const { // FIXME: Can m_curr_frame ever be invalid? return (m_curr_frame < m_cs.size () ? m_cs[m_curr_frame]->get_scope () : symbol_scope ()); } - bool at_top_level (void) const + bool at_top_level () const { return current_scope () == top_scope (); } @@ -123,26 +123,26 @@ } // User code caller. - octave_user_code * current_user_code (void) const; + octave_user_code * current_user_code () const; - unwind_protect * curr_fcn_unwind_protect_frame (void); + unwind_protect * curr_fcn_unwind_protect_frame (); // Line in user code caller. - int current_user_code_line (void) const; + int current_user_code_line () const; // Column in user code caller. - int current_user_code_column (void) const; + int current_user_code_column () const; // Current function that we are debugging. - octave_user_code * debug_user_code (void) const; + octave_user_code * debug_user_code () const; // Line number in current function that we are debugging. - int debug_user_code_line (void) const; + int debug_user_code_line () const; // Column number in current function that we are debugging. - int debug_user_code_column (void) const; + int debug_user_code_column () const; - std::string get_dispatch_class (void) const; + std::string get_dispatch_class () const; void set_dispatch_class (const std::string& class_name); @@ -151,7 +151,7 @@ bool is_class_constructor_executing (std::string& dispatch_class) const; // Return TRUE if all elements on the call stack are scripts. - bool all_scripts (void) const; + bool all_scripts () const; void push (const symbol_scope& scope); @@ -204,23 +204,23 @@ goto_frame (n); } - std::size_t find_current_user_frame (void) const; + std::size_t find_current_user_frame () const; - std::shared_ptr current_user_frame (void) const; + std::shared_ptr current_user_frame () const; std::size_t dbupdown (std::size_t start, int n, bool verbose); std::size_t dbupdown (int n = -1, bool verbose = false); - void goto_caller_frame (void); + void goto_caller_frame (); - void goto_base_frame (void); + void goto_base_frame (); std::list> backtrace_frames (octave_idx_type& curr_user_frame) const; // List of raw stack frames. - std::list> backtrace_frames (void) const; + std::list> backtrace_frames () const; // List of stack_info objects that can be used in liboctave and // stored in the execution_exception object. @@ -228,7 +228,7 @@ std::list backtrace_info (octave_idx_type& curr_user_frame, bool print_subfn = true) const; - std::list backtrace_info (void) const; + std::list backtrace_info () const; // The same as backtrace_info but in the form of a struct array // object that may be used in the interpreter. @@ -236,21 +236,21 @@ octave_map backtrace (octave_idx_type& curr_user_frame, bool print_subfn = true) const; - octave_map backtrace (void) const; + octave_map backtrace () const; - octave_map empty_backtrace (void) const; + octave_map empty_backtrace () const; - void pop (void); + void pop (); - void clear (void); + void clear (); - symbol_info_list all_variables (void); + symbol_info_list all_variables (); - std::list global_variable_names (void) const; + std::list global_variable_names () const; - std::list top_level_variable_names (void) const; + std::list top_level_variable_names () const; - std::list variable_names (void) const; + std::list variable_names () const; void clear_global_variable (const std::string& name); @@ -258,15 +258,15 @@ void clear_global_variable_regexp(const std::string& pattern); - void clear_global_variables (void); + void clear_global_variables (); symbol_info_list glob_symbol_info (const std::string& pattern) const; symbol_info_list regexp_symbol_info (const std::string& pattern) const; - symbol_info_list get_symbol_info (void); + symbol_info_list get_symbol_info (); - symbol_info_list top_scope_symbol_info (void) const; + symbol_info_list top_scope_symbol_info () const; octave_value max_stack_depth (const octave_value_list& args, int nargout); @@ -294,7 +294,7 @@ bool have_regexp, bool return_list, bool verbose, const std::string& msg = ""); - void display (void) const; + void display () const; void set_auto_fcn_var (stack_frame::auto_var_type avt, const octave_value& val); diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/cellfun.cc --- a/libinterp/corefcn/cellfun.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/cellfun.cc Fri May 12 08:03:14 2023 +0200 @@ -41,7 +41,6 @@ #include "defun.h" #include "interpreter-private.h" #include "interpreter.h" -#include "parse.h" #include "variables.h" #include "unwind-prot.h" #include "errwarn.h" @@ -68,11 +67,9 @@ OCTAVE_BEGIN_NAMESPACE(octave) static octave_value_list -get_output_list (error_system& es, - octave_idx_type count, octave_idx_type nargout, - const octave_value_list& inputlist, - octave_value& fcn, - octave_value& error_handler) +get_output_list (interpreter& interp, octave_idx_type count, + octave_idx_type nargout, const octave_value_list& inputlist, + octave_value& fcn, octave_value& error_handler) { octave_value_list tmp; @@ -80,13 +77,13 @@ try { - tmp = feval (fcn, inputlist, nargout); + tmp = interp.feval (fcn, inputlist, nargout); } catch (const execution_exception& ee) { if (error_handler.is_defined ()) { - interpreter& interp = __get_interpreter__ (); + error_system& es = interp.get_error_system (); es.save_exception (ee); interp.recover_from_exception (); @@ -101,6 +98,8 @@ { if (error_handler.is_defined ()) { + error_system& es = interp.get_error_system (); + octave_scalar_map msg; msg.assign ("identifier", es.last_error_id ()); msg.assign ("message", es.last_error_message ()); @@ -111,7 +110,7 @@ octave_value_list errlist = inputlist; errlist.prepend (msg); - tmp = feval (error_handler, errlist, nargout); + tmp = interp.feval (error_handler, errlist, nargout); } else tmp.clear (); @@ -359,7 +358,7 @@ @example @group -cellfun ("tolower", @{"Foo", "Bar", "FooBar"@}, +cellfun ("lower", @{"Foo", "Bar", "FooBar"@}, "UniformOutput", false) @result{} @{"foo", "bar", "foobar"@} @end group @@ -537,8 +536,6 @@ } } - error_system& es = interp.get_error_system (); - // Apply functions. if (uniform_output) @@ -559,7 +556,7 @@ } const octave_value_list tmp - = get_output_list (es, count, nargout, inputlist, fcn, + = get_output_list (interp, count, nargout, inputlist, fcn, error_handler); int tmp_numel = tmp.length (); @@ -645,7 +642,7 @@ } const octave_value_list tmp - = get_output_list (es, count, nargout, inputlist, fcn, + = get_output_list (interp, count, nargout, inputlist, fcn, error_handler); if (nargout > 0 && tmp.length () < nargout) @@ -1277,8 +1274,6 @@ } } - error_system& es = interp.get_error_system (); - // Apply functions. if (uniform_output) @@ -1300,7 +1295,7 @@ } const octave_value_list tmp - = get_output_list (es, count, nargout, inputlist, fcn, + = get_output_list (interp, count, nargout, inputlist, fcn, error_handler); if (nargout > 0 && tmp.length () < nargout) @@ -1392,7 +1387,7 @@ } const octave_value_list tmp - = get_output_list (es, count, nargout, inputlist, fcn, + = get_output_list (interp, count, nargout, inputlist, fcn, error_handler); if (nargout > 0 && tmp.length () < nargout) @@ -2057,20 +2052,29 @@ if (mat2cell_mismatch (a.dims (), d, nd)) return retval; - dim_vector rdv = dim_vector::alloc (nd); + // For each dimension, count the number of partitions specified. + // For example, "mat2cell (A, [1 1 1], [2 2])" has 3 partitions on dim1 + // and 2 partitions on dim2. Number of dimension (nd) is 2 for this example. + dim_vector retdv = dim_vector::alloc (nd); OCTAVE_LOCAL_BUFFER (octave_idx_type, nidx, nd); - octave_idx_type idxtot = 0; + octave_idx_type idxtot = 0; // Number of idx operations. 5 in example. for (int i = 0; i < nd; i++) { - rdv(i) = nidx[i] = d[i].numel (); + retdv(i) = nidx[i] = d[i].numel (); idxtot += nidx[i]; } - retval.clear (rdv); + if (nd == 1) + retdv(1) = 1; // All Octave arrays have at least two dimensions. + retval.clear (retdv); // Resize retval based on calculated partitions. OCTAVE_LOCAL_BUFFER (idx_vector, xidx, idxtot); OCTAVE_LOCAL_BUFFER (idx_vector *, idx, nd); + // Loop over all dimensions (specified partitions) and prepare an idx_vector + // to retrieve the requested elements. The partitions are specified in + // input parameter 'd' which is an Array of octave_idx_type. In the example, + // d[0] = [1 1 1]. idxtot = 0; for (int i = 0; i < nd; i++) { @@ -2080,19 +2084,28 @@ } OCTAVE_LOCAL_BUFFER_INIT (octave_idx_type, ridx, nd, 0); - Array ra_idx - (dim_vector (1, std::max (nd, a.ndims ())), idx_vector::colon); + // Declare array of index vectors which will perform indexing. + // Initialize to magic colon (':') so that dimensions that are not actually + // specified will be collapsed. + Array ra_idx (dim_vector (1, std::max (nd, a.ndims ())), + idx_vector::colon); - for (octave_idx_type j = 0; j < retval.numel (); j++) + const octave_idx_type retnumel = retval.numel (); + for (octave_idx_type j = 0; j < retnumel; j++) { octave_quit (); + // Copy prepared indices for this iteration to ra_idx. for (int i = 0; i < nd; i++) ra_idx.xelem (i) = idx[i][ridx[i]]; + // Perform indexing operation and store in output retval. retval.xelem (j) = a.index (ra_idx); - rdv.increment_index (ridx); + // DO NOT increment on last loop because it will overflow past + // declared size of ridx (bug #63682). + if (j < (retnumel - 1)) + retdv.increment_index (ridx); } return retval; @@ -2166,7 +2179,7 @@ doc: /* -*- texinfo -*- @deftypefn {} {@var{C} =} mat2cell (@var{A}, @var{dim1}, @var{dim2}, @dots{}, @var{dimi}, @dots{}, @var{dimn}) @deftypefnx {} {@var{C} =} mat2cell (@var{A}, @var{rowdim}) -Convert the matrix @var{A} to a cell array. +Convert the matrix @var{A} to a cell array @var{C}. Each dimension argument (@var{dim1}, @var{dim2}, etc.@:) is a vector of integers which specifies how to divide that dimension's elements amongst the @@ -2337,6 +2350,15 @@ %! c = mat2cell (x, 1, [0,4,2,0,4,0]); %! empty1by0str = resize ("", 1, 0); %! assert (c, {empty1by0str,"abcd","ef",empty1by0str,"ghij",empty1by0str}); + +## Omitted input for trailing dimensions means not splitting on them. +%!test <*63682> +%! x = reshape (1:16, 4, 2, 2); +%! c1 = mat2cell (x, [2, 2], 2, 2); +%! c2 = mat2cell (x, [2, 2]); +%! assert (c1, c2); +%! assert (c1, {cat(3, [1,5;2,6], [9,13;10,14]); ... +%! cat(3, [3,7;4,8], [11,15;12,16])}); */ // FIXME: it would be nice to allow ranges being handled without a conversion. diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/daspk.cc --- a/libinterp/corefcn/daspk.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/daspk.cc Fri May 12 08:03:14 2023 +0200 @@ -36,11 +36,11 @@ #include "error.h" #include "errwarn.h" #include "interpreter-private.h" +#include "interpreter.h" #include "ovl.h" #include "ov-fcn.h" #include "ov-cell.h" #include "pager.h" -#include "parse.h" #include "unwind-prot.h" #include "utils.h" #include "variables.h" @@ -82,7 +82,9 @@ try { - tmp = feval (daspk_fcn, args, 1); + interpreter& interp = __get_interpreter__ (); + + tmp = interp.feval (daspk_fcn, args, 1); } catch (execution_exception& ee) { @@ -132,7 +134,9 @@ try { - tmp = feval (daspk_jac, args, 1); + interpreter& interp = __get_interpreter__ (); + + tmp = interp.feval (daspk_jac, args, 1); } catch (execution_exception& ee) { diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/dasrt.cc --- a/libinterp/corefcn/dasrt.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/dasrt.cc Fri May 12 08:03:14 2023 +0200 @@ -37,11 +37,11 @@ #include "error.h" #include "errwarn.h" #include "interpreter-private.h" +#include "interpreter.h" #include "ovl.h" #include "ov-fcn.h" #include "ov-cell.h" #include "pager.h" -#include "parse.h" #include "unwind-prot.h" #include "utils.h" #include "variables.h" @@ -83,7 +83,9 @@ try { - tmp = feval (dasrt_fcn, args, 1); + interpreter& interp = __get_interpreter__ (); + + tmp = interp.feval (dasrt_fcn, args, 1); } catch (execution_exception& ee) { @@ -124,7 +126,9 @@ try { - tmp = feval (dasrt_cf, args, 1); + interpreter& interp = __get_interpreter__ (); + + tmp = interp.feval (dasrt_cf, args, 1); } catch (execution_exception& ee) { @@ -170,7 +174,9 @@ try { - tmp = feval (dasrt_jac, args, 1); + interpreter& interp = __get_interpreter__ (); + + tmp = interp.feval (dasrt_jac, args, 1); } catch (execution_exception& ee) { @@ -466,11 +472,9 @@ ColumnVector state = args(argp++).xvector_value ("dasrt: initial state X_0 must be a vector"); - ColumnVector stateprime = args( - argp++).xvector_value ("dasrt: initial derivatives XDOT_0 must be a vector"); + ColumnVector stateprime = args(argp++).xvector_value ("dasrt: initial derivatives XDOT_0 must be a vector"); - ColumnVector out_times = args( - argp++).xvector_value ("dasrt: output time variable T must be a vector"); + ColumnVector out_times = args(argp++).xvector_value ("dasrt: output time variable T must be a vector"); double tzero = out_times (0); diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/dassl.cc --- a/libinterp/corefcn/dassl.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/dassl.cc Fri May 12 08:03:14 2023 +0200 @@ -35,11 +35,11 @@ #include "error.h" #include "errwarn.h" #include "interpreter-private.h" +#include "interpreter.h" #include "ovl.h" #include "ov-fcn.h" #include "ov-cell.h" #include "pager.h" -#include "parse.h" #include "unwind-prot.h" #include "utils.h" #include "variables.h" @@ -81,7 +81,9 @@ try { - tmp = feval (dassl_fcn, args, 1); + interpreter& interp = __get_interpreter__ (); + + tmp = interp.feval (dassl_fcn, args, 1); } catch (execution_exception& ee) { @@ -131,7 +133,9 @@ try { - tmp = feval (dassl_jac, args, 1); + interpreter& interp = __get_interpreter__ (); + + tmp = interp.feval (dassl_jac, args, 1); } catch (execution_exception& ee) { diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/data.cc --- a/libinterp/corefcn/data.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/data.cc Fri May 12 08:03:14 2023 +0200 @@ -49,6 +49,7 @@ #include "error.h" #include "errwarn.h" #include "interpreter-private.h" +#include "interpreter.h" #include "oct-map.h" #include "ov-class.h" #include "ov-complex.h" @@ -60,7 +61,6 @@ #include "ov.h" #include "ovl.h" #include "pager.h" -#include "parse.h" #include "pt-mat.h" #include "utils.h" #include "variables.h" @@ -1680,7 +1680,9 @@ std::string cname = ov.class_name (); - symbol_table& symtab = __get_symbol_table__ (); + interpreter& interp = __get_interpreter__ (); + + symbol_table& symtab = interp.get_symbol_table (); octave_value fcn = symtab.find_method (dtype, cname); @@ -1690,7 +1692,7 @@ try { - result = feval (fcn, ovl (ov), 1); + result = interp.feval (fcn, ovl (ov), 1); } catch (execution_exception& ee) { @@ -1718,7 +1720,7 @@ try { - result = feval (fcn, ovl (ov), 1); + result = interp.feval (fcn, ovl (ov), 1); } catch (execution_exception& ee) { @@ -1746,7 +1748,9 @@ std::string dtype = get_dispatch_type (ovl); - symbol_table& symtab = __get_symbol_table__ (); + interpreter& interp = __get_interpreter__ (); + + symbol_table& symtab = interp.get_symbol_table (); octave_value fcn = symtab.find_method (cattype, dtype); @@ -1758,7 +1762,7 @@ try { - tmp2 = feval (fcn, ovl, 1); + tmp2 = interp.feval (fcn, ovl, 1); } catch (execution_exception& ee) { @@ -4635,6 +4639,7 @@ %!assert (ones (2, "like", speye (2)), sparse ([1, 1; 1, 1])) %!assert (ones (2, "like", sparse (1i)), sparse (complex ([1, 1; 1, 1]))) +## Note: Matlab compatibility requires using 0 for negative dimensions. %!assert (size (ones (1, -2, 2)), [1, 0, 2]) ## Test input validation @@ -4790,6 +4795,9 @@ %!assert (Inf (3, 2, "single"), single ([Inf, Inf; Inf, Inf; Inf, Inf])) %!assert (size (inf (3, 4, 5, "single")), [3, 4, 5]) +## Note: Matlab compatibility requires using 0 for negative dimensions. +%!assert (size (Inf (2, -3, 2)), [2, 0, 2]) + %!assert (Inf (2, 2, "like", speye (2)), sparse ([Inf, Inf; Inf, Inf])) %!assert (Inf (2, 2, "like", complex (ones (2, 2))), [Inf, Inf; Inf, Inf]) %!assert (Inf (2, 2, "like", double (1)), double ([Inf, Inf; Inf, Inf])) @@ -5045,6 +5053,10 @@ %!assert (eps (single (NaN)), single (NaN)) %!assert (eps (single ([1/2 1 2 realmax("single") 0 realmin("single")/2 realmin("single")/16 Inf NaN])), %! single ([2^-24 2^-23 2^-22 2^104 2^-149 2^-149 2^-149 NaN NaN])) + +## Note: Matlab compatibility requires using 0 for negative dimensions. +%!assert (size (eps (2, -3, 2)), [2, 0, 2]) + %!error eps (uint8 ([0 1 2])) %!error eps (1:3, 1) %!error eps (1, 1:3) @@ -5534,12 +5546,15 @@ %!assert (full (eye (3)), [1, 0, 0; 0, 1, 0; 0, 0, 1]) %!assert (full (eye (2, 3)), [1, 0, 0; 0, 1, 0]) -%!assert (full (eye (3,"single")), single ([1, 0, 0; 0, 1, 0; 0, 0, 1])) -%!assert (full (eye (2, 3,"single")), single ([1, 0, 0; 0, 1, 0])) +%!assert (full (eye (3, "single")), single ([1, 0, 0; 0, 1, 0; 0, 0, 1])) +%!assert (full (eye (2, 3, "single")), single ([1, 0, 0; 0, 1, 0])) %!assert (eye (3, "int8"), int8 ([1, 0, 0; 0, 1, 0; 0, 0, 1])) %!assert (eye (2, 3, "int8"), int8 ([1, 0, 0; 0, 1, 0])) +## Note: Matlab compatibility requires using 0 for negative dimensions. +%!assert (size (eye (2, -3)), [2, 0]) + ## Test input validation %!error eye (1, 2, 3) %!error eye (1.1) @@ -5741,27 +5756,41 @@ %!assert (numel (linspace (0, 1, 2-eps)), 1) %!assert (linspace (10, 20, 2.1), [10 20]) %!assert (linspace (10, 20, 2.9), [10 20]) -%!assert (1 ./ linspace (-0, 0, 4), [-Inf, Inf, Inf, Inf]) %!assert (linspace (Inf, Inf, 3), [Inf, Inf, Inf]) %!assert (linspace (-Inf, -Inf, 3), [-Inf, -Inf, -Inf]) %!assert (linspace (-Inf, Inf, 3), [-Inf, 0, Inf]) +## Octave prefers to return NaN which indicates failure of algorithm. +%!assert (linspace (-Inf, Inf, 4), [-Inf, NaN, NaN, Inf]) +%!assert (linspace (-Inf, 0, 3), [-Inf, NaN, 0]) +%!assert (linspace (-Inf, 0, 4), [-Inf, NaN, NaN, 0]) %!assert (linspace (Inf + 1i, Inf + 1i, 3), [Inf + 1i, Inf + 1i, Inf + 1i]) -%!assert (linspace (-Inf + 1i, Inf + 1i, 3), [-Inf + 1i, NaN + 1i, Inf + 1i]) +%!assert (linspace (-Inf - 1i, Inf + 1i, 3), [-Inf - 1i, 0 + 0i, Inf + 1i]) +%!assert (linspace (-Inf - 1i, Inf + 2i, 3), [-Inf - 1i, NaN + 0.5i, Inf + 2i]) +%!assert (linspace (-Inf - 3i, Inf + 0i, 4), +%! [-Inf - 3i, NaN - 2i, NaN - 1i, Inf + 0i]) +%!assert (linspace (complex (-1, -Inf), complex (1, Inf), 3), +%! [complex(-1, -Inf), 0 + 0i, complex(1, Inf)]) +%!assert (linspace (complex (-1, -Inf), complex (2, Inf), 3), +%! [complex(-1, -Inf), complex(0.5, NaN), complex(2, Inf)]) +%!assert (linspace (complex (-3, -Inf), complex (0, Inf), 4), +%! [complex(-3, -Inf), complex(-2, NaN), complex(-1, NaN), complex(0, Inf)]) ## FIXME: Octave is not fully Matlab-compatible for some combinations of ## Inf/-Inf endpoints. See bug #56933. This was dubbed "Won't Fix" -## so these tests have been removed from the test suite by commenting -## them out. If the behavior in the future is made compatible these -## tests can be re-instated. +## as Octave prefers to return NaN for some of these conditions to +## better reflect that the algorithm has failed. If the behavior in +## the future is made compatible these tests can be re-instated. ##%!assert <56933> (linspace (-Inf, Inf, 4), [-Inf, -Inf, Inf, Inf]) ##%!assert <56933> (linspace (-Inf, Inf, 5), [-Inf, -Inf, 0, Inf, Inf]) ##%!assert <56933> (linspace (0, Inf, 4), [0, Inf, Inf, Inf]) ##%!assert <56933> (linspace (0, -Inf, 4), [0, -Inf, -Inf, -Inf]) ##%!assert <56933> (linspace (-Inf, 0, 4), [-Inf, NaN, NaN, 0]) ##%!assert <56933> (linspace (Inf, 0, 4), [Inf, NaN, NaN, 0]) - -%!error linspace () -%!error linspace (1, 2, 3, 4) +##%!assert (1 ./ linspace (-0, 0, 4), [-Inf, Inf, Inf, Inf]) + +## Test input validation +%!error linspace () +%!error linspace (1, 2, 3, 4) %!error linspace (1, 2, [3, 4]) %!error linspace (ones (2,2), 2, 3) %!error linspace (2, ones (2,2), 3) @@ -6528,7 +6557,7 @@ (@dots{}((@var{A1} * @var{A2}) * @var{A3}) * @dots{}) @end example -@seealso{times, plus, minus, rdivide, mrdivide, mldivide, mpower} +@seealso{times, plus, minus, rdivide, mrdivide, mldivide, mpower, tensorprod} @end deftypefn */) { return binary_assoc_op_defun_body (octave_value::op_mul, diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/data.h --- a/libinterp/corefcn/data.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/data.h Fri May 12 08:03:14 2023 +0200 @@ -41,14 +41,4 @@ OCTAVE_END_NAMESPACE(octave) -#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS) -OCTAVE_DEPRECATED (7, "use 'octave::do_class_concat' instead") -inline OCTINTERP_API octave_value -do_class_concat (const octave_value_list& ovl, const std::string& cattype, - int dim) -{ - return octave::do_class_concat (ovl, cattype, dim); -} #endif - -#endif diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/debug.cc --- a/libinterp/corefcn/debug.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/debug.cc Fri May 12 08:03:14 2023 +0200 @@ -935,7 +935,7 @@ // for example. void -show_octave_dbstack (void) +show_octave_dbstack () { do_dbstack (octave::__get_interpreter__ (), octave_value_list (), 0, std::cerr); diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/defaults.cc --- a/libinterp/corefcn/defaults.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/defaults.cc Fri May 12 08:03:14 2023 +0200 @@ -74,7 +74,7 @@ return retval; } -static std::string get_octave_home (void) +static std::string get_octave_home () { std::string op = OCTAVE_PREFIX; @@ -86,7 +86,7 @@ return oh.empty () ? op : oh; } -static std::string get_octave_exec_home (void) +static std::string get_octave_exec_home () { std::string op = OCTAVE_PREFIX; std::string oep = OCTAVE_EXEC_PREFIX; @@ -108,14 +108,14 @@ return oep; } -static std::string get_local_site_defaults_file (void) +static std::string get_local_site_defaults_file () { std::string lsf = sys::env::getenv ("OCTAVE_SITE_INITFILE"); return lsf.empty () ? local_startupfile_dir () + "/octaverc" : lsf; } -static std::string get_site_defaults_file (void) +static std::string get_site_defaults_file () { std::string sf = sys::env::getenv ("OCTAVE_VERSION_INITFILE"); @@ -132,7 +132,7 @@ return prepend_home_dir (octave_exec_home (), s); } -std::string canonical_host_type (void) +std::string canonical_host_type () { static const std::string s_canonical_host_type = OCTAVE_CANONICAL_HOST_TYPE; @@ -140,35 +140,35 @@ return s_canonical_host_type; } -std::string release (void) +std::string release () { static const std::string s_octave_release = OCTAVE_RELEASE; return s_octave_release; } -std::string default_pager (void) +std::string default_pager () { static const std::string s_default_pager = OCTAVE_DEFAULT_PAGER; return s_default_pager; } -std::string octave_home (void) +std::string octave_home () { static const std::string s_octave_home = get_octave_home (); return s_octave_home; } -std::string octave_exec_home (void) +std::string octave_exec_home () { static const std::string s_octave_exec_home = get_octave_exec_home (); return s_octave_exec_home; } -std::string bin_dir (void) +std::string bin_dir () { static const std::string s_bin_dir = prepend_octave_exec_home (OCTAVE_BINDIR); @@ -176,7 +176,7 @@ return s_bin_dir; } -std::string data_dir (void) +std::string data_dir () { static const std::string s_data_dir = prepend_octave_home (OCTAVE_DATADIR); @@ -184,7 +184,7 @@ return s_data_dir; } -std::string dataroot_dir (void) +std::string dataroot_dir () { static const std::string s_dataroot_dir = prepend_octave_home (OCTAVE_DATAROOTDIR); @@ -192,7 +192,7 @@ return s_dataroot_dir; } -std::string include_dir (void) +std::string include_dir () { static const std::string s_include_dir = prepend_octave_home (OCTAVE_INCLUDEDIR); @@ -200,7 +200,7 @@ return s_include_dir; } -std::string lib_dir (void) +std::string lib_dir () { static const std::string s_lib_dir = prepend_octave_exec_home (OCTAVE_LIBDIR); @@ -208,7 +208,7 @@ return s_lib_dir; } -std::string libexec_dir (void) +std::string libexec_dir () { static const std::string s_libexec_dir = prepend_octave_exec_home (OCTAVE_LIBEXECDIR); @@ -216,7 +216,7 @@ return s_libexec_dir; } -std::string arch_lib_dir (void) +std::string arch_lib_dir () { static const std::string s_arch_lib_dir = prepend_octave_exec_home (OCTAVE_ARCHLIBDIR); @@ -224,7 +224,7 @@ return s_arch_lib_dir; } -std::string info_dir (void) +std::string info_dir () { static const std::string s_info_dir = prepend_octave_exec_home (OCTAVE_INFODIR); @@ -232,7 +232,7 @@ return s_info_dir; } -std::string local_ver_arch_lib_dir (void) +std::string local_ver_arch_lib_dir () { static const std::string s_local_ver_arch_lib_dir = prepend_octave_exec_home (OCTAVE_LOCALVERARCHLIBDIR); @@ -240,7 +240,7 @@ return s_local_ver_arch_lib_dir; } -std::string local_api_arch_lib_dir (void) +std::string local_api_arch_lib_dir () { static const std::string s_local_api_arch_lib_dir = prepend_octave_exec_home (OCTAVE_LOCALAPIARCHLIBDIR); @@ -248,7 +248,7 @@ return s_local_api_arch_lib_dir; } -std::string local_arch_lib_dir (void) +std::string local_arch_lib_dir () { static const std::string s_local_arch_lib_dir = prepend_octave_exec_home (OCTAVE_LOCALARCHLIBDIR); @@ -256,7 +256,7 @@ return s_local_arch_lib_dir; } -std::string local_ver_oct_file_dir (void) +std::string local_ver_oct_file_dir () { static const std::string s_local_ver_oct_file_dir = prepend_octave_exec_home (OCTAVE_LOCALVEROCTFILEDIR); @@ -264,7 +264,7 @@ return s_local_ver_oct_file_dir; } -std::string local_api_oct_file_dir (void) +std::string local_api_oct_file_dir () { static const std::string s_local_api_oct_file_dir = prepend_octave_exec_home (OCTAVE_LOCALAPIOCTFILEDIR); @@ -272,7 +272,7 @@ return s_local_api_oct_file_dir; } -std::string local_oct_file_dir (void) +std::string local_oct_file_dir () { static const std::string s_local_oct_file_dir = prepend_octave_exec_home (OCTAVE_LOCALOCTFILEDIR); @@ -280,7 +280,7 @@ return s_local_oct_file_dir; } -std::string oct_file_dir (void) +std::string oct_file_dir () { static const std::string s_oct_file_dir = prepend_octave_exec_home (OCTAVE_OCTFILEDIR); @@ -288,7 +288,7 @@ return s_oct_file_dir; } -std::string local_ver_fcn_file_dir (void) +std::string local_ver_fcn_file_dir () { static const std::string s_local_ver_fcn_file_dir = prepend_octave_home (OCTAVE_LOCALVERFCNFILEDIR); @@ -296,7 +296,7 @@ return s_local_ver_fcn_file_dir; } -std::string local_api_fcn_file_dir (void) +std::string local_api_fcn_file_dir () { static const std::string s_local_api_fcn_file_dir = prepend_octave_home (OCTAVE_LOCALAPIFCNFILEDIR); @@ -304,7 +304,7 @@ return s_local_api_fcn_file_dir; } -std::string local_fcn_file_dir (void) +std::string local_fcn_file_dir () { static const std::string s_local_fcn_file_dir = prepend_octave_home (OCTAVE_LOCALFCNFILEDIR); @@ -312,7 +312,7 @@ return s_local_fcn_file_dir; } -std::string fcn_file_dir (void) +std::string fcn_file_dir () { static const std::string s_fcn_file_dir = prepend_octave_home (OCTAVE_FCNFILEDIR); @@ -320,7 +320,7 @@ return s_fcn_file_dir; } -std::string oct_data_dir (void) +std::string oct_data_dir () { static const std::string s_oct_data_dir = prepend_octave_home (OCTAVE_OCTDATADIR); @@ -328,7 +328,7 @@ return s_oct_data_dir; } -std::string oct_doc_dir (void) +std::string oct_doc_dir () { static const std::string s_oct_doc_dir = prepend_octave_home (OCTAVE_OCTDOCDIR); @@ -336,7 +336,7 @@ return s_oct_doc_dir; } -std::string oct_etc_dir (void) +std::string oct_etc_dir () { static const std::string s_oct_etc_dir = prepend_octave_home (OCTAVE_OCTETCDIR); @@ -344,7 +344,7 @@ return s_oct_etc_dir; } -std::string oct_fonts_dir (void) +std::string oct_fonts_dir () { static const std::string s_oct_fonts_dir = prepend_octave_home (OCTAVE_OCTFONTSDIR); @@ -352,7 +352,7 @@ return s_oct_fonts_dir; } -std::string oct_include_dir (void) +std::string oct_include_dir () { static const std::string s_oct_include_dir = prepend_octave_home (OCTAVE_OCTINCLUDEDIR); @@ -360,7 +360,7 @@ return s_oct_include_dir; } -std::string oct_lib_dir (void) +std::string oct_lib_dir () { static const std::string s_oct_lib_dir = prepend_octave_exec_home (OCTAVE_OCTLIBDIR); @@ -368,7 +368,7 @@ return s_oct_lib_dir; } -std::string oct_locale_dir (void) +std::string oct_locale_dir () { static const std::string s_oct_locale_dir = prepend_octave_home (OCTAVE_OCTLOCALEDIR); @@ -376,7 +376,7 @@ return s_oct_locale_dir; } -std::string oct_tests_dir (void) +std::string oct_tests_dir () { static const std::string s_oct_tests_dir = prepend_octave_home (OCTAVE_OCTTESTSDIR); @@ -384,7 +384,7 @@ return s_oct_tests_dir; } -std::string man_dir (void) +std::string man_dir () { static const std::string s_man_dir = prepend_octave_home (OCTAVE_MANDIR); @@ -392,7 +392,7 @@ return s_man_dir; } -std::string man1_dir (void) +std::string man1_dir () { static const std::string s_man1_dir = prepend_octave_home (OCTAVE_MAN1DIR); @@ -400,14 +400,14 @@ return s_man1_dir; } -std::string man1_ext (void) +std::string man1_ext () { static const std::string s_man1_ext = OCTAVE_MAN1EXT; return s_man1_ext; } -std::string image_dir (void) +std::string image_dir () { static const std::string s_image_dir = prepend_octave_home (OCTAVE_IMAGEDIR); @@ -415,7 +415,7 @@ return s_image_dir; } -std::string local_startupfile_dir (void) +std::string local_startupfile_dir () { static const std::string s_local_startupfile_dir = prepend_octave_home (OCTAVE_LOCALSTARTUPFILEDIR); @@ -423,7 +423,7 @@ return s_local_startupfile_dir; } -std::string startupfile_dir (void) +std::string startupfile_dir () { static const std::string s_startupfile_dir = prepend_octave_home (OCTAVE_STARTUPFILEDIR); @@ -431,7 +431,7 @@ return s_startupfile_dir; } -std::string local_site_defaults_file (void) +std::string local_site_defaults_file () { static const std::string s_local_site_defaults_file = get_local_site_defaults_file (); @@ -439,7 +439,7 @@ return s_local_site_defaults_file; } -std::string site_defaults_file (void) +std::string site_defaults_file () { static const std::string s_site_defaults_file = get_site_defaults_file (); diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/defaults.h --- a/libinterp/corefcn/defaults.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/defaults.h Fri May 12 08:03:14 2023 +0200 @@ -46,61 +46,61 @@ // functions to be consistent with the values that require // initialization. -extern OCTINTERP_API std::string canonical_host_type (void); -extern OCTINTERP_API std::string release (void); -extern OCTINTERP_API std::string default_pager (void); +extern OCTINTERP_API std::string canonical_host_type (); +extern OCTINTERP_API std::string release (); +extern OCTINTERP_API std::string default_pager (); // These require initialization, so can't be defined as pure // constants. We use functions to access these values so that // they can't be modified by users. -extern OCTINTERP_API std::string octave_home (void); -extern OCTINTERP_API std::string octave_exec_home (void); +extern OCTINTERP_API std::string octave_home (); +extern OCTINTERP_API std::string octave_exec_home (); -extern OCTINTERP_API std::string bin_dir (void); -extern OCTINTERP_API std::string data_dir (void); -extern OCTINTERP_API std::string dataroot_dir (void); -extern OCTINTERP_API std::string include_dir (void); -extern OCTINTERP_API std::string lib_dir (void); -extern OCTINTERP_API std::string libexec_dir (void); +extern OCTINTERP_API std::string bin_dir (); +extern OCTINTERP_API std::string data_dir (); +extern OCTINTERP_API std::string dataroot_dir (); +extern OCTINTERP_API std::string include_dir (); +extern OCTINTERP_API std::string lib_dir (); +extern OCTINTERP_API std::string libexec_dir (); -extern OCTINTERP_API std::string local_ver_arch_lib_dir (void); -extern OCTINTERP_API std::string local_api_arch_lib_dir (void); -extern OCTINTERP_API std::string local_arch_lib_dir (void); -extern OCTINTERP_API std::string arch_lib_dir (void); +extern OCTINTERP_API std::string local_ver_arch_lib_dir (); +extern OCTINTERP_API std::string local_api_arch_lib_dir (); +extern OCTINTERP_API std::string local_arch_lib_dir (); +extern OCTINTERP_API std::string arch_lib_dir (); -extern OCTINTERP_API std::string local_ver_oct_file_dir (void); -extern OCTINTERP_API std::string local_api_oct_file_dir (void); -extern OCTINTERP_API std::string local_oct_file_dir (void); -extern OCTINTERP_API std::string oct_file_dir (void); +extern OCTINTERP_API std::string local_ver_oct_file_dir (); +extern OCTINTERP_API std::string local_api_oct_file_dir (); +extern OCTINTERP_API std::string local_oct_file_dir (); +extern OCTINTERP_API std::string oct_file_dir (); -extern OCTINTERP_API std::string local_ver_fcn_file_dir (void); -extern OCTINTERP_API std::string local_api_fcn_file_dir (void); -extern OCTINTERP_API std::string local_fcn_file_dir (void); -extern OCTINTERP_API std::string fcn_file_dir (void); +extern OCTINTERP_API std::string local_ver_fcn_file_dir (); +extern OCTINTERP_API std::string local_api_fcn_file_dir (); +extern OCTINTERP_API std::string local_fcn_file_dir (); +extern OCTINTERP_API std::string fcn_file_dir (); -extern OCTINTERP_API std::string oct_data_dir (void); -extern OCTINTERP_API std::string oct_doc_dir (void); -extern OCTINTERP_API std::string oct_etc_dir (void); -extern OCTINTERP_API std::string oct_fonts_dir (void); -extern OCTINTERP_API std::string oct_include_dir (void); -extern OCTINTERP_API std::string oct_lib_dir (void); -extern OCTINTERP_API std::string oct_locale_dir (void); -extern OCTINTERP_API std::string oct_tests_dir (void); +extern OCTINTERP_API std::string oct_data_dir (); +extern OCTINTERP_API std::string oct_doc_dir (); +extern OCTINTERP_API std::string oct_etc_dir (); +extern OCTINTERP_API std::string oct_fonts_dir (); +extern OCTINTERP_API std::string oct_include_dir (); +extern OCTINTERP_API std::string oct_lib_dir (); +extern OCTINTERP_API std::string oct_locale_dir (); +extern OCTINTERP_API std::string oct_tests_dir (); -extern OCTINTERP_API std::string info_dir (void); +extern OCTINTERP_API std::string info_dir (); -extern OCTINTERP_API std::string man_dir (void); -extern OCTINTERP_API std::string man1_dir (void); -extern OCTINTERP_API std::string man1_ext (void); +extern OCTINTERP_API std::string man_dir (); +extern OCTINTERP_API std::string man1_dir (); +extern OCTINTERP_API std::string man1_ext (); -extern OCTINTERP_API std::string image_dir (void); +extern OCTINTERP_API std::string image_dir (); -extern OCTINTERP_API std::string local_startupfile_dir (void); -extern OCTINTERP_API std::string startupfile_dir (void); +extern OCTINTERP_API std::string local_startupfile_dir (); +extern OCTINTERP_API std::string startupfile_dir (); -extern OCTINTERP_API std::string local_site_defaults_file (void); -extern OCTINTERP_API std::string site_defaults_file (void); +extern OCTINTERP_API std::string local_site_defaults_file (); +extern OCTINTERP_API std::string site_defaults_file (); OCTAVE_END_NAMESPACE(config) diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/defun.cc --- a/libinterp/corefcn/defun.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/defun.cc Fri May 12 08:03:14 2023 +0200 @@ -46,13 +46,12 @@ #include "interpreter.h" #include "symtab.h" #include "variables.h" -#include "parse.h" OCTAVE_BEGIN_NAMESPACE(octave) // Print the usage part of the doc string of FCN (user-defined or DEFUN). void -print_usage (void) +print_usage () { tree_evaluator& tw = __get_evaluator__ (); @@ -67,7 +66,9 @@ void print_usage (const std::string& name) { - feval ("print_usage", octave_value (name), 0); + interpreter& interp = __get_interpreter__ (); + + interp.feval ("print_usage", octave_value (name), 0); } void @@ -136,7 +137,7 @@ } dynamic_library -get_current_shlib (void) +get_current_shlib () { dynamic_library retval; diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/dirfns.cc --- a/libinterp/corefcn/dirfns.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/dirfns.cc Fri May 12 08:03:14 2023 +0200 @@ -39,6 +39,7 @@ #include "file-ops.h" #include "file-stat.h" #include "glob-match.h" +#include "lo-sysdep.h" #include "oct-env.h" #include "oct-glob.h" #include "pathsearch.h" @@ -207,9 +208,7 @@ dirname = sys::file_ops::tilde_expand (dirname); - sys::file_stat fs (dirname); - - if (fs && fs.is_dir ()) + if (sys::dir_exists (dirname)) { // For Matlab compatibility, return true when directory already exists. return ovl (true, "directory exists", "mkdir"); diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/display.cc --- a/libinterp/corefcn/display.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/display.cc Fri May 12 08:03:14 2023 +0200 @@ -39,7 +39,7 @@ OCTAVE_BEGIN_NAMESPACE(octave) -void display_info::initialize (void) +void display_info::initialize () { int avail = 0; diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/display.h --- a/libinterp/corefcn/display.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/display.h Fri May 12 08:03:14 2023 +0200 @@ -42,32 +42,32 @@ // initialize to find the actual system parameters for the given // display. - display_info (void) + display_info () : m_rx (72), m_ry (72), m_ht (1), m_wd (1), m_dp (0), m_dpy_avail (false), m_msg () { } - ~display_info (void) = default; + ~display_info () = default; display_info (const display_info&) = default; display_info& operator = (const display_info&) = default; - void initialize (void); + void initialize (); - double x_dpi (void) const { return m_rx; } + double x_dpi () const { return m_rx; } - double y_dpi (void) const { return m_ry; } + double y_dpi () const { return m_ry; } - int height (void) const { return m_ht; } + int height () const { return m_ht; } - int width (void) const { return m_wd; } + int width () const { return m_wd; } - int depth (void) const { return m_dp; } + int depth () const { return m_dp; } - bool display_available (void) const { return m_dpy_avail; } + bool display_available () const { return m_dpy_avail; } - std::string message (void) const { return m_msg; } + std::string message () const { return m_msg; } private: diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/dot.cc --- a/libinterp/corefcn/dot.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/dot.cc Fri May 12 08:03:14 2023 +0200 @@ -91,7 +91,7 @@ the result is equivalent to @code{@var{X}' * @var{Y}}. Although, @code{dot} is defined for integer arrays, the output may differ from the expected result due to the limited range of integer objects. -@seealso{cross, divergence} +@seealso{cross, divergence, tensorprod} @end deftypefn */) { int nargin = args.length (); @@ -193,9 +193,9 @@ // of calculating possibly garbage results. // Think of the dot product of two int8 vectors where the multiplications // exceed intmax. - octave_value_list tmp; + octave_value_list tmp (2); + tmp(0) = binary_op (octave_value::op_el_mul, argx, argy); tmp(1) = dim + 1; - tmp(0) = binary_op (octave_value::op_el_mul, argx, argy); tmp = Fsum (tmp, 1); if (! tmp.empty ()) diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/dynamic-ld.cc --- a/libinterp/corefcn/dynamic-ld.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/dynamic-ld.cc Fri May 12 08:03:14 2023 +0200 @@ -95,7 +95,7 @@ } void -dynamic_loader::shlibs_list::display (void) const +dynamic_loader::shlibs_list::display () const { std::cerr << "current shared libraries:" << std::endl; for (const auto& lib : m_lib_list) diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/dynamic-ld.h --- a/libinterp/corefcn/dynamic-ld.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/dynamic-ld.h Fri May 12 08:03:14 2023 +0200 @@ -52,15 +52,11 @@ typedef std::list::iterator iterator; typedef std::list::const_iterator const_iterator; - shlibs_list (void) : m_lib_list () { } - - // No copying! + shlibs_list () : m_lib_list () { } - shlibs_list (const shlibs_list&) = delete; + OCTAVE_DISABLE_COPY_MOVE (shlibs_list) - shlibs_list& operator = (const shlibs_list&) = delete; - - ~shlibs_list (void) = default; + ~shlibs_list () = default; void append (const dynamic_library& shl); @@ -68,7 +64,7 @@ dynamic_library find_file (const std::string& file_name) const; - void display (void) const; + void display () const; private: @@ -79,17 +75,15 @@ public: + dynamic_loader () = delete; + dynamic_loader (interpreter& interp) : m_interpreter (interp), m_loaded_shlibs (), m_doing_load (false) { } - // No copying! - - dynamic_loader (const dynamic_loader&) = delete; + OCTAVE_DISABLE_COPY_MOVE (dynamic_loader) - dynamic_loader& operator = (const dynamic_loader&) = delete; - - virtual ~dynamic_loader (void) = default; + virtual ~dynamic_loader () = default; octave_function * load_oct (const std::string& fcn_name, diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/environment.cc --- a/libinterp/corefcn/environment.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/environment.cc Fri May 12 08:03:14 2023 +0200 @@ -104,7 +104,7 @@ false); } -std::string environment::init_editor (void) +std::string environment::init_editor () { std::string retval = "emacs"; @@ -116,7 +116,7 @@ return retval; } -std::string environment::init_exec_path (void) +std::string environment::init_exec_path () { std::string exec_path = sys::env::getenv ("OCTAVE_EXEC_PATH"); @@ -134,7 +134,7 @@ return exec_path; } -std::string environment::init_image_path (void) +std::string environment::init_image_path () { std::string image_path = "."; diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/environment.h --- a/libinterp/corefcn/environment.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/environment.h Fri May 12 08:03:14 2023 +0200 @@ -39,15 +39,17 @@ { public: - environment (void) + environment () : m_editor (init_editor ()), m_exec_path (init_exec_path ()), m_image_path (init_image_path ()) { } + OCTAVE_DEFAULT_COPY_DELETE (environment) + octave_value editor (const octave_value_list& args, int nargout); - std::string editor (void) const { return m_editor; } + std::string editor () const { return m_editor; } std::string editor (const std::string& ed) { @@ -56,13 +58,13 @@ octave_value exec_path (const octave_value_list& args, int nargout); - std::string exec_path (void) const { return m_exec_path; } + std::string exec_path () const { return m_exec_path; } std::string exec_path (const std::string& path); octave_value image_path (const octave_value_list& args, int nargout); - std::string image_path (void) const { return m_image_path; } + std::string image_path () const { return m_image_path; } std::string image_path (const std::string& path) { @@ -77,11 +79,11 @@ std::string m_image_path; - static std::string init_editor (void); + static std::string init_editor (); - static std::string init_exec_path (void); + static std::string init_exec_path (); - static std::string init_image_path (void); + static std::string init_image_path (); std::string set (std::string& var, const std::string& new_val) { diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/error.cc --- a/libinterp/corefcn/error.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/error.cc Fri May 12 08:03:14 2023 +0200 @@ -697,7 +697,7 @@ return retval; } -std::string error_system::default_warning_state (void) +std::string error_system::default_warning_state () { std::string retval = "on"; @@ -829,7 +829,7 @@ set_warning_option ("off", id); } -void error_system::initialize_default_warning_state (void) +void error_system::initialize_default_warning_state () { warning_options (init_warning_options ("on")); @@ -901,17 +901,6 @@ last_error_stack (make_stack_map (ee.stack_info ())); } -// DEPRECATED in Octave 7. -void error_system::display_exception (const execution_exception& ee, - std::ostream& os) const -{ - if (m_beep_on_error) - os << "\a"; - - ee.display (octave_diary); - ee.display (os); -} - void error_system::display_exception (const execution_exception& ee) const { // FIXME: How should we handle beep_on_error? @@ -1813,10 +1802,10 @@ octave_value_list set_warning_state (const std::string& id, const std::string& state) { - octave_value_list args; + octave_value_list args (2); + args(0) = state; args(1) = id; - args(0) = state; interpreter& interp = __get_interpreter__ (); diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/error.h --- a/libinterp/corefcn/error.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/error.h Fri May 12 08:03:14 2023 +0200 @@ -48,18 +48,16 @@ OCTINTERP_API error_system (interpreter& interp); - error_system (const error_system&) = delete; + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (error_system) - error_system& operator = (const error_system&) = delete; - - ~error_system (void) = default; + ~error_system () = default; OCTINTERP_API octave_value debug_on_error (const octave_value_list& args, int nargout); void set_debug_on_error (bool flag) { m_debug_on_error = flag; } - bool debug_on_error (void) const { return m_debug_on_error; } + bool debug_on_error () const { return m_debug_on_error; } bool debug_on_error (bool flag) { @@ -73,7 +71,7 @@ void set_debug_on_caught (bool flag) { m_debug_on_caught = flag; } - bool debug_on_caught (void) const { return m_debug_on_caught; } + bool debug_on_caught () const { return m_debug_on_caught; } bool debug_on_caught (bool flag) { @@ -87,7 +85,7 @@ void set_debug_on_warning (bool flag) { m_debug_on_warning = flag; } - bool debug_on_warning (void) const { return m_debug_on_warning; } + bool debug_on_warning () const { return m_debug_on_warning; } bool debug_on_warning (bool flag) { @@ -104,7 +102,7 @@ m_discard_warning_messages = flag; } - bool discard_warning_messages (void) const + bool discard_warning_messages () const { return m_discard_warning_messages; } @@ -121,7 +119,7 @@ void set_beep_on_error (bool flag) { m_beep_on_error = flag; } - bool beep_on_error (void) const { return m_beep_on_error; } + bool beep_on_error () const { return m_beep_on_error; } bool beep_on_error (bool flag) { @@ -135,7 +133,7 @@ void set_backtrace_on_warning (bool flag) { m_backtrace_on_warning = flag; } - bool backtrace_on_warning (void) const { return m_backtrace_on_warning; } + bool backtrace_on_warning () const { return m_backtrace_on_warning; } bool backtrace_on_warning (bool flag) { @@ -149,7 +147,7 @@ void set_verbose_warning (bool flag) { m_verbose_warning = flag; } - bool verbose_warning (void) const { return m_verbose_warning; } + bool verbose_warning () const { return m_verbose_warning; } bool verbose_warning (bool flag) { @@ -163,7 +161,7 @@ void set_quiet_warning (bool flag) { m_quiet_warning = flag; } - bool quiet_warning (void) const { return m_quiet_warning; } + bool quiet_warning () const { return m_quiet_warning; } bool quiet_warning (bool flag) { @@ -172,7 +170,7 @@ return val; } - octave_map warning_options (void) const { return m_warning_options; } + octave_map warning_options () const { return m_warning_options; } void set_warning_options (const octave_map& val) { m_warning_options = val; } @@ -190,7 +188,7 @@ void set_last_error_message (const std::string& val) { m_last_error_message = val; } - std::string last_error_message (void) const { return m_last_error_message; } + std::string last_error_message () const { return m_last_error_message; } std::string last_error_message (const std::string& s) { @@ -205,7 +203,7 @@ void set_last_warning_message (const std::string& val) { m_last_warning_message = val; } - std::string last_warning_message (void) const + std::string last_warning_message () const { return m_last_warning_message; } std::string last_warning_message (const std::string& s) @@ -221,7 +219,7 @@ void set_last_warning_id (const std::string& val) { m_last_warning_id = val; } - std::string last_warning_id (void) const { return m_last_warning_id; } + std::string last_warning_id () const { return m_last_warning_id; } std::string last_warning_id (const std::string& s) { @@ -235,7 +233,7 @@ void set_last_error_id (const std::string& val) { m_last_error_id = val; } - std::string last_error_id (void) const { return m_last_error_id; } + std::string last_error_id () const { return m_last_error_id; } std::string last_error_id (const std::string& s) { @@ -249,7 +247,7 @@ m_last_error_stack = val; } - octave_map last_error_stack (void) const { return m_last_error_stack; } + octave_map last_error_stack () const { return m_last_error_stack; } octave_map last_error_stack (const octave_map& new_val) { @@ -305,7 +303,7 @@ OCTINTERP_API octave_scalar_map warning_query (const std::string& id_arg); - OCTINTERP_API std::string default_warning_state (void); + OCTINTERP_API std::string default_warning_state (); OCTINTERP_API void display_warning_options (std::ostream& os); @@ -314,7 +312,7 @@ OCTINTERP_API void disable_warning (const std::string& id); - OCTINTERP_API void initialize_default_warning_state (void); + OCTINTERP_API void initialize_default_warning_state (); OCTINTERP_API void interpreter_try (unwind_protect& frame); @@ -334,13 +332,6 @@ OCTINTERP_API void save_exception (const execution_exception& ee); - // FIXME - //#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS) - OCTAVE_DEPRECATED (7, "second argument is no longer accepted") - OCTINTERP_API void display_exception (const execution_exception& ee, - std::ostream& os) const; - //#endif - OCTINTERP_API void display_exception (const execution_exception& ee) const; private: @@ -573,44 +564,4 @@ OCTAVE_END_NAMESPACE(octave) -#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS) -OCTAVE_DEPRECATED (7, "use 'octave::defun_usage_message' instead") -inline void defun_usage_message (const std::string& msg) -{ - octave::defun_usage_message (msg); -} - -OCTAVE_DEPRECATED (7, "use 'octave::set_warning_state' instead") -inline octave_value_list -set_warning_state (const std::string& id, const std::string& state) -{ - return octave::set_warning_state (id, state); -} - -OCTAVE_DEPRECATED (7, "use 'octave::set_warning_state' instead") -inline octave_value_list set_warning_state (const octave_value_list& args) -{ - return octave::set_warning_state (args); -} - -OCTAVE_DEPRECATED (7, "use 'octave::warning_enabled' instead") -inline int warning_enabled (const std::string& id) -{ - return octave::warning_enabled (id); -} - -OCTAVE_DEPRECATED (7, "use 'octave::disable_warning' instead") -inline void disable_warning (const std::string& id) -{ - octave::disable_warning (id); -} - -OCTAVE_DEPRECATED (7, "use 'octave::interpreter_try' instead") -inline void interpreter_try (octave::unwind_protect& uwp) -{ - octave::interpreter_try (uwp); -} - #endif - -#endif diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/errwarn.cc --- a/libinterp/corefcn/errwarn.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/errwarn.cc Fri May 12 08:03:14 2023 +0200 @@ -38,7 +38,7 @@ //////////////////////////////////////////////////////////////////////////////// void -err_2_or_3_dim_plot (void) +err_2_or_3_dim_plot () { error ("plot: can only plot in 2 or 3 dimensions"); } @@ -62,7 +62,7 @@ } void -err_indexed_cs_list (void) +err_indexed_cs_list () { error ("a cs-list cannot be further indexed"); } @@ -74,25 +74,25 @@ } void -err_invalid_inquiry_subscript (void) +err_invalid_inquiry_subscript () { error ("invalid dimension inquiry of a non-existent value"); } void -err_invalid_structure_assignment (void) +err_invalid_structure_assignment () { error ("invalid dot name structure assignment because the structure array is empty. Specify a subscript on the structure array to resolve."); } void -err_nonbraced_cs_list_assignment (void) +err_nonbraced_cs_list_assignment () { error ("invalid assignment to cs-list outside multiple assignment"); } void -err_nonconformant (void) +err_nonconformant () { error ("nonconformant matrices"); } @@ -113,7 +113,7 @@ } void -err_range_invalid (void) +err_range_invalid () { error ("range constant used in invalid context"); } @@ -125,7 +125,7 @@ } void -err_string_invalid (void) +err_string_invalid () { error ("std::string constant used in invalid context"); } @@ -137,7 +137,7 @@ } void -err_unrecognized_float_fmt (void) +err_unrecognized_float_fmt () { error ("unrecognized floating point format requested"); } @@ -300,7 +300,7 @@ */ void -warn_complex_cmp (void) +warn_complex_cmp () { warning_with_id ("Octave:language-extension", "comparing complex numbers is not supported in Matlab"); @@ -362,7 +362,7 @@ } void -warn_logical_conversion (void) +warn_logical_conversion () { warning_with_id ("Octave:logical-conversion", "value not equal to 1 or 0 converted to logical 1"); diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/errwarn.h --- a/libinterp/corefcn/errwarn.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/errwarn.h Fri May 12 08:03:14 2023 +0200 @@ -44,7 +44,7 @@ //////////////////////////////////////////////////////////////////////////////// OCTAVE_NORETURN extern OCTINTERP_API void -err_2_or_3_dim_plot (void); +err_2_or_3_dim_plot (); OCTAVE_NORETURN extern OCTINTERP_API void err_data_conversion (const char *from, const char *to); @@ -54,22 +54,22 @@ const std::string& pkg = "Octave"); OCTAVE_NORETURN extern OCTINTERP_API void -err_indexed_cs_list (void); +err_indexed_cs_list (); OCTAVE_NORETURN extern OCTINTERP_API void err_invalid_conversion (const std::string& from, const std::string& to); OCTAVE_NORETURN extern OCTINTERP_API void -err_invalid_inquiry_subscript (void); +err_invalid_inquiry_subscript (); OCTAVE_NORETURN extern OCTINTERP_API void -err_invalid_structure_assignment (void); +err_invalid_structure_assignment (); OCTAVE_NORETURN extern OCTINTERP_API void -err_nonbraced_cs_list_assignment (void); +err_nonbraced_cs_list_assignment (); OCTAVE_NORETURN extern OCTINTERP_API void -err_nonconformant (void); +err_nonconformant (); OCTAVE_NORETURN extern OCTINTERP_API void err_nonconformant (octave_idx_type r1, octave_idx_type c1, @@ -79,19 +79,19 @@ err_not_implemented (const char *); OCTAVE_NORETURN extern OCTINTERP_API void -err_range_invalid (void); +err_range_invalid (); OCTAVE_NORETURN extern OCTINTERP_API void err_square_matrix_required (const char *fcn, const char *name); OCTAVE_NORETURN extern OCTINTERP_API void -err_string_invalid (void); +err_string_invalid (); OCTAVE_NORETURN extern OCTINTERP_API void err_unrecognized_data_fmt (const char *name); OCTAVE_NORETURN extern OCTINTERP_API void -err_unrecognized_float_fmt (void); +err_unrecognized_float_fmt (); OCTAVE_NORETURN extern OCTINTERP_API void err_user_returned_invalid (const char *name); @@ -158,7 +158,7 @@ warn_array_as_logical (const dim_vector& dv); extern OCTINTERP_API void -warn_complex_cmp (void); +warn_complex_cmp (); extern OCTINTERP_API void warn_data_file_in_path (const std::string& fcn, const std::string& file); @@ -184,7 +184,7 @@ warn_invalid_value_specified (const char *name); extern OCTINTERP_API void -warn_logical_conversion (void); +warn_logical_conversion (); extern OCTINTERP_API void warn_wrong_type_arg (const char *name, const octave_value& tc); diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/event-manager.cc --- a/libinterp/corefcn/event-manager.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/event-manager.cc Fri May 12 08:03:14 2023 +0200 @@ -46,7 +46,7 @@ OCTAVE_BEGIN_NAMESPACE(octave) -static int readline_event_hook (void) +static int readline_event_hook () { event_manager& evmgr = __get_event_manager__ (); @@ -74,7 +74,7 @@ command_editor::add_event_hook (readline_event_hook); } -event_manager::~event_manager (void) +event_manager::~event_manager () { delete m_event_queue_mutex; } @@ -94,7 +94,7 @@ m_instance = obj; } -bool event_manager::enable (void) +bool event_manager::enable () { bool retval = m_link_enabled; @@ -121,7 +121,7 @@ } } -void event_manager::discard_events (void) +void event_manager::discard_events () { if (enabled ()) { @@ -133,13 +133,13 @@ } } -void event_manager::push_event_queue (void) +void event_manager::push_event_queue () { std::shared_ptr evq (new event_queue ()); m_gui_event_queue.push (evq); } -void event_manager::pop_event_queue (void) +void event_manager::pop_event_queue () { // FIXME: Should we worry about the possibility of events remaining // in the queue when we pop back to the previous queue? If so, then @@ -172,7 +172,7 @@ } } -void event_manager::set_workspace (void) +void event_manager::set_workspace () { if (enabled ()) { @@ -183,7 +183,7 @@ } } -void event_manager::set_history (void) +void event_manager::set_history () { if (enabled ()) m_instance->set_history (command_history::list ()); diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/event-manager.h --- a/libinterp/corefcn/event-manager.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/event-manager.h Fri May 12 08:03:14 2023 +0200 @@ -44,7 +44,7 @@ OCTAVE_BEGIN_NAMESPACE(octave) -typedef std::function fcn_callback; +typedef std::function fcn_callback; typedef std::function meth_callback; class execution_exception; @@ -79,13 +79,13 @@ { public: - interpreter_events (void) = default; + interpreter_events () = default; interpreter_events (const interpreter_events&) = default; interpreter_events& operator = (const interpreter_events&) = default; - virtual ~interpreter_events (void) = default; + virtual ~interpreter_events () = default; // Note: START_GUI and CLOSE_GUI currently only work with the new // experimental terminal widget. @@ -96,11 +96,11 @@ // command line application. virtual void start_gui (bool /*gui_app*/ = false) { } - virtual void close_gui (void) { } + virtual void close_gui () { } // Dialogs. - virtual bool have_dialogs (void) const { return false; } + virtual bool have_dialogs () const { return false; } typedef std::list> filter_list; @@ -144,27 +144,27 @@ return ""; } - virtual void update_path_dialog (void) { } + virtual void update_path_dialog () { } - virtual void show_preferences (void) { } + virtual void show_preferences () { } - virtual void apply_preferences (void) { } + virtual void apply_preferences () { } - virtual void show_terminal_window (void) { } + virtual void show_terminal_window () { } virtual bool show_documentation (const std::string& /*file*/) { return false; } - virtual void show_file_browser (void) { } + virtual void show_file_browser () { } - virtual void show_command_history (void) { } + virtual void show_command_history () { } - virtual void show_workspace (void) { } + virtual void show_workspace () { } virtual void show_community_news (int /*serial*/) { } - virtual void show_release_notes (void) { } + virtual void show_release_notes () { } virtual bool edit_file (const std::string& /*file*/) { return false; } @@ -176,7 +176,7 @@ // confirmation before another action. Could these be reformulated // using the question_dialog action? - virtual bool confirm_shutdown (void) { return true; } + virtual bool confirm_shutdown () { return true; } virtual bool prompt_new_edit_file (const std::string& /*file*/) { @@ -231,7 +231,7 @@ virtual void gui_status_update (const std::string& /*feature*/, const std::string& /*status*/) { } - virtual void update_gui_lexer (void) { } + virtual void update_gui_lexer () { } // Notifications of events in the interpreter that a GUI will // normally wish to respond to. @@ -250,7 +250,7 @@ bool /*update_variable_editor*/) { } - virtual void clear_workspace (void) { } + virtual void clear_workspace () { } virtual void update_prompt (const std::string& /*prompt*/) { } @@ -258,11 +258,11 @@ virtual void append_history (const std::string& /*hist_entry*/) { } - virtual void clear_history (void) { } + virtual void clear_history () { } - virtual void pre_input_event (void) { } + virtual void pre_input_event () { } - virtual void post_input_event (void) { } + virtual void post_input_event () { } virtual void enter_debugger_event (const std::string& /*fcn_name*/, @@ -273,14 +273,14 @@ virtual void execute_in_debugger_event (const std::string& /*file*/, int /*line*/) { } - virtual void exit_debugger_event (void) { } + virtual void exit_debugger_event () { } virtual void update_breakpoint (bool /*insert*/, const std::string& /*file*/, int /*line*/, const std::string& /*cond*/) { } - virtual void interpreter_interrupted (void) { } + virtual void interpreter_interrupted () { } }; //! Provides threadsafe access to octave. @@ -296,14 +296,9 @@ OCTINTERP_API event_manager (interpreter& interp); - // No copying! - - event_manager (const event_manager&) = delete; + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (event_manager) - event_manager& - operator = (const event_manager&) = delete; - - virtual ~event_manager (void); + virtual ~event_manager (); // OBJ should be an object of a class that is derived from the base // class interpreter_events, or nullptr to disconnect and delete the @@ -312,16 +307,16 @@ OCTINTERP_API void connect_link (const std::shared_ptr& obj); - OCTINTERP_API bool enable (void); + OCTINTERP_API bool enable (); - bool disable (void) + bool disable () { bool retval = m_link_enabled; m_link_enabled = false; return retval; } - bool enabled (void) const + bool enabled () const { return m_link_enabled; } @@ -337,22 +332,22 @@ } std::shared_ptr - qt_event_handlers (void) const { return m_qt_event_handlers; } + qt_event_handlers () const { return m_qt_event_handlers; } // If disable is TRUE, then no additional events will be processed // other than exit. OCTINTERP_API void process_events (bool disable = false); - OCTINTERP_API void discard_events (void); + OCTINTERP_API void discard_events (); // The post_event and post_exception functions provide a thread-safe // way for the GUI to queue interpreter functions for execution. // The queued functions are executed when the interpreter is // otherwise idle. - void push_event_queue (void); - void pop_event_queue (void); + void push_event_queue (); + void pop_event_queue (); OCTINTERP_API void post_event (const fcn_callback& fcn); OCTINTERP_API void post_event (const meth_callback& meth); @@ -376,7 +371,7 @@ m_instance->start_gui (gui_app); } - void close_gui (void) + void close_gui () { if (enabled ()) m_instance->close_gui (); @@ -384,7 +379,7 @@ // Dialogs - bool have_dialogs (void) const + bool have_dialogs () const { return m_qt_event_handlers && m_qt_event_handlers->have_dialogs (); } @@ -442,13 +437,13 @@ : ""); } - void update_path_dialog (void) + void update_path_dialog () { if (application::is_gui_running () && enabled ()) m_instance->update_path_dialog (); } - bool show_preferences (void) + bool show_preferences () { if (enabled ()) { @@ -459,7 +454,7 @@ return false; } - bool apply_preferences (void) + bool apply_preferences () { if (enabled ()) { @@ -470,7 +465,7 @@ return false; } - void show_terminal_window (void) + void show_terminal_window () { if (enabled ()) m_instance->show_terminal_window (); @@ -481,19 +476,19 @@ return enabled () ? m_instance->show_documentation (file) : false; } - void show_file_browser (void) + void show_file_browser () { if (enabled ()) m_instance->show_file_browser (); } - void show_command_history (void) + void show_command_history () { if (enabled ()) m_instance->show_command_history (); } - void show_workspace (void) + void show_workspace () { if (enabled ()) m_instance->show_workspace (); @@ -505,7 +500,7 @@ m_instance->show_community_news (serial); } - void show_release_notes (void) + void show_release_notes () { if (enabled ()) m_instance->show_release_notes (); @@ -527,7 +522,7 @@ return false; } - bool confirm_shutdown (void) + bool confirm_shutdown () { bool retval = true; @@ -637,7 +632,7 @@ return false; } - bool update_gui_lexer (void) + bool update_gui_lexer () { if (enabled ()) { @@ -667,7 +662,7 @@ m_instance->file_renamed (load_new); } - OCTINTERP_API void set_workspace (void); + OCTINTERP_API void set_workspace (); void set_workspace (bool top_level, const symbol_info_list& syminfo, bool update_variable_editor = true) @@ -677,7 +672,7 @@ update_variable_editor); } - void clear_workspace (void) + void clear_workspace () { if (enabled ()) m_instance->clear_workspace (); @@ -689,7 +684,7 @@ m_instance->update_prompt (prompt); } - OCTINTERP_API void set_history (void); + OCTINTERP_API void set_history (); void set_history (const string_vector& hist) { @@ -703,19 +698,19 @@ m_instance->append_history (hist_entry); } - void clear_history (void) + void clear_history () { if (enabled ()) m_instance->clear_history (); } - void pre_input_event (void) + void pre_input_event () { if (enabled ()) m_instance->pre_input_event (); } - void post_input_event (void) + void post_input_event () { if (enabled ()) m_instance->post_input_event (); @@ -738,7 +733,7 @@ m_instance->execute_in_debugger_event (file, line); } - void exit_debugger_event (void) + void exit_debugger_event () { if (enabled () && m_debugging) { @@ -755,7 +750,7 @@ m_instance->update_breakpoint (insert, file, line, cond); } - void interpreter_interrupted (void) + void interpreter_interrupted () { if (enabled ()) m_instance->interpreter_interrupted (); diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/event-queue.cc --- a/libinterp/corefcn/event-queue.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/event-queue.cc Fri May 12 08:03:14 2023 +0200 @@ -33,7 +33,7 @@ OCTAVE_BEGIN_NAMESPACE(octave) void -event_queue_safe::warn_unhandled_exception (void) const +event_queue_safe::warn_unhandled_exception () const { warning ("unhandled exception in event_queue_safe handler. " "It is a bug in Octave for this to happen. " diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/event-queue.h --- a/libinterp/corefcn/event-queue.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/event-queue.h Fri May 12 08:03:14 2023 +0200 @@ -40,20 +40,16 @@ { public: - event_queue (void) : m_fifo () { } - - // No copying! + event_queue () : m_fifo () { } - event_queue (const event_queue&) = delete; - - event_queue& operator = (const event_queue&) = delete; + OCTAVE_DISABLE_COPY_MOVE (event_queue) // Destructor should not raise an exception, so all actions registered // should be exception-safe. If you're not sure, see event_queue_safe. - ~event_queue (void) { run (); } + ~event_queue () { run (); } - void run_first (void) + void run_first () { if (! empty ()) { @@ -64,7 +60,7 @@ } } - void discard_first (void) + void discard_first () { if (! empty ()) { @@ -74,7 +70,7 @@ } } - std::size_t size (void) const { return m_fifo.size (); } + std::size_t size () const { return m_fifo.size (); } protected: @@ -97,15 +93,11 @@ { public: - event_queue_safe (void) : event_queue () { } - - // No copying! + event_queue_safe () : event_queue () { } - event_queue_safe (const event_queue_safe&) = delete; + OCTAVE_DISABLE_COPY_MOVE (event_queue_safe) - event_queue_safe& operator = (const event_queue_safe&) = delete; - - ~event_queue_safe (void) + ~event_queue_safe () { while (! empty ()) { @@ -122,7 +114,7 @@ private: - void warn_unhandled_exception (void) const; + void warn_unhandled_exception () const; }; diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/fcn-info.cc --- a/libinterp/corefcn/fcn-info.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/fcn-info.cc Fri May 12 08:03:14 2023 +0200 @@ -29,6 +29,7 @@ #include "file-ops.h" #include "file-stat.h" +#include "lo-sysdep.h" #include "oct-env.h" #include "defun.h" @@ -91,7 +92,7 @@ } octave_value -fcn_info::fcn_info_rep::load_class_constructor (void) +fcn_info::fcn_info_rep::load_class_constructor () { octave_value retval; @@ -241,7 +242,7 @@ // to btyp_num_types (static constant). Only the leftmost dimension can be // variable in C/C++. Typedefs are boring. -static builtin_type_t (* build_sup_table (void))[btyp_num_types] +static builtin_type_t (* build_sup_table ())[btyp_num_types] { static builtin_type_t sup_table[btyp_num_types][btyp_num_types]; for (int i = 0; i < btyp_num_types; i++) @@ -573,7 +574,7 @@ } if (! file.empty ()) - is_same_file = same_file (file, ff); + is_same_file = sys::same_file (file, ff); } else { @@ -999,7 +1000,7 @@ } octave_value -fcn_info::fcn_info_rep::find_autoload (void) +fcn_info::fcn_info_rep::find_autoload () { // Autoloaded function. @@ -1030,7 +1031,7 @@ } octave_value -fcn_info::fcn_info_rep::find_user_function (void) +fcn_info::fcn_info_rep::find_user_function () { // Function on the path. @@ -1060,7 +1061,7 @@ } octave_value -fcn_info::fcn_info_rep::find_package (void) +fcn_info::fcn_info_rep::find_package () { // FIXME: implement correct way to check out of date package //if (package.is_defined ()) @@ -1098,7 +1099,7 @@ } octave_value -fcn_info::fcn_info_rep::dump (void) const +fcn_info::fcn_info_rep::dump () const { std::map m = {{ "name", full_name () }, @@ -1183,8 +1184,7 @@ if (nargin == 1) { - std::string sval = args( - 0).xstring_value ("ignore_function_time_stamp: first argument must be a string"); + std::string sval = args(0).xstring_value ("ignore_function_time_stamp: first argument must be a string"); if (sval == "all") Vignore_function_time_stamp = 2; diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/fcn-info.h --- a/libinterp/corefcn/fcn-info.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/fcn-info.h Fri May 12 08:03:14 2023 +0200 @@ -68,19 +68,15 @@ } } - // No copying! - - fcn_info_rep (const fcn_info_rep&) = delete; + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (fcn_info_rep) - fcn_info_rep& operator = (const fcn_info_rep&) = delete; - - ~fcn_info_rep (void) = default; + ~fcn_info_rep () = default; octave_value install_local_function (const std::string& file_name); octave_value load_private_function (const std::string& dir_name); - octave_value load_class_constructor (void); + octave_value load_class_constructor (); octave_value load_class_method (const std::string& dispatch_type); @@ -97,13 +93,13 @@ octave_value find_method (const octave_value_list& args); - octave_value find_autoload (void); + octave_value find_autoload (); - octave_value find_package (void); + octave_value find_package (); - octave_value find_user_function (void); + octave_value find_user_function (); - bool is_user_function_defined (void) const + bool is_user_function_defined () const { return function_on_path.is_defined (); } @@ -171,13 +167,13 @@ cmdline_function = octave_value (); } - void clear_mex_function (void) + void clear_mex_function () { if (function_on_path.is_mex_function ()) clear_user_function (); } - void clear_package (void) + void clear_package () { package = octave_value (); } @@ -194,9 +190,9 @@ clear_package (); } - octave_value dump (void) const; + octave_value dump () const; - std::string full_name (void) const + std::string full_name () const { if (package_name.empty ()) return name; @@ -247,7 +243,7 @@ fcn_info& operator = (const fcn_info&) = default; - ~fcn_info (void) = default; + ~fcn_info () = default; octave_value find (const symbol_scope& search_scope, const octave_value_list& args = octave_value_list ()) @@ -276,28 +272,28 @@ return m_rep->find_method (dispatch_type); } - octave_value find_built_in_function (void) const + octave_value find_built_in_function () const { return m_rep->built_in_function; } - octave_value find_cmdline_function (void) const + octave_value find_cmdline_function () const { return m_rep->cmdline_function; } - octave_value find_autoload (void) + octave_value find_autoload () { return m_rep->find_autoload (); } // FIXME: find_function_on_path might be a better name? - octave_value find_user_function (void) + octave_value find_user_function () { return m_rep->find_user_function (); } - bool is_user_function_defined (void) const + bool is_user_function_defined () const { return m_rep->is_user_function_defined (); } @@ -347,9 +343,9 @@ m_rep->clear_autoload_function (force); } - void clear_mex_function (void) { m_rep->clear_mex_function (); } + void clear_mex_function () { m_rep->clear_mex_function (); } - octave_value dump (void) const { return m_rep->dump (); } + octave_value dump () const { return m_rep->dump (); } private: diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/file-io.cc --- a/libinterp/corefcn/file-io.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/file-io.cc Fri May 12 08:03:14 2023 +0200 @@ -418,12 +418,12 @@ std::string fname = sys::file_ops::tilde_expand (name); - sys::file_stat fs (fname); + bool is_dir = sys::dir_exists (fname); if (! (md & std::ios::out)) fname = find_data_file_in_load_path ("fopen", fname); - if (! fs.is_dir ()) + if (! is_dir) { #if defined (HAVE_ZLIB) if (use_zlib) diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/ft-text-renderer.cc --- a/libinterp/corefcn/ft-text-renderer.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/ft-text-renderer.cc Fri May 12 08:03:14 2023 +0200 @@ -102,7 +102,7 @@ { private: - ft_manager (void) + ft_manager () : m_library (), m_freetype_initialized (false), m_fontconfig_initialized (false) { @@ -121,15 +121,11 @@ public: - // No copying! - - ft_manager (const ft_manager&) = delete; - - ft_manager& operator = (const ft_manager&) = delete; + OCTAVE_DISABLE_COPY_MOVE (ft_manager) private: - ~ft_manager (void) + ~ft_manager () { if (m_freetype_initialized) FT_Done_FreeType (m_library); @@ -146,42 +142,42 @@ public: - static bool instance_ok (void) + static bool instance_ok () { bool retval = true; - if (! m_instance) + if (! s_instance) { - m_instance = new ft_manager (); + s_instance = new ft_manager (); singleton_cleanup_list::add (cleanup_instance); } return retval; } - static void cleanup_instance (void) - { delete m_instance; m_instance = nullptr; } + static void cleanup_instance () + { delete s_instance; s_instance = nullptr; } static FT_Face get_font (const std::string& name, const std::string& weight, const std::string& angle, double size, FT_ULong c = 0) { return (instance_ok () - ? m_instance->do_get_font (name, weight, angle, size, c) + ? s_instance->do_get_font (name, weight, angle, size, c) : nullptr); } - static octave_map get_system_fonts (void) + static octave_map get_system_fonts () { return (instance_ok () - ? m_instance->do_get_system_fonts () + ? s_instance->do_get_system_fonts () : octave_map ()); } static void font_destroyed (FT_Face face) { if (instance_ok ()) - m_instance->do_font_destroyed (face); + s_instance->do_font_destroyed (face); } private: @@ -189,7 +185,7 @@ typedef std::pair ft_key; typedef std::map ft_cache; - static octave_map do_get_system_fonts (void) + static octave_map do_get_system_fonts () { static octave_map font_map; @@ -434,7 +430,7 @@ //-------- - static ft_manager *m_instance; + static ft_manager *s_instance; // Cache the fonts loaded by FreeType. This cache only contains // weak references to the fonts, strong references are only present @@ -446,7 +442,7 @@ bool m_fontconfig_initialized; }; -ft_manager *ft_manager::m_instance = nullptr; +ft_manager *ft_manager::s_instance = nullptr; static void ft_face_destroyed (void *object) @@ -468,7 +464,7 @@ public: - ft_text_renderer (void) + ft_text_renderer () : base_text_renderer (), m_font (), m_bbox (1, 4, 0.0), m_halign (0), m_xoffset (0), m_line_yoffset (0), m_yoffset (0), m_mode (MODE_BBOX), m_color (dim_vector (1, 3), 0), m_do_strlist (false), m_strlist (), @@ -476,13 +472,9 @@ m_max_fontsize (0), m_antialias (true) { } - // No copying! - - ft_text_renderer (const ft_text_renderer&) = delete; + OCTAVE_DISABLE_COPY_MOVE (ft_text_renderer) - ft_text_renderer& operator = (const ft_text_renderer&) = delete; - - ~ft_text_renderer (void) = default; + ~ft_text_renderer () = default; void visit (text_element_string& e); @@ -504,11 +496,11 @@ void visit (text_element_combined& e); - void reset (void); + void reset (); - uint8NDArray get_pixels (void) const { return m_pixels; } + uint8NDArray get_pixels () const { return m_pixels; } - Matrix get_boundingbox (void) const { return m_bbox; } + Matrix get_boundingbox () const { return m_bbox; } uint8NDArray render (text_element *elt, Matrix& box, int rotation = ROTATION_0); @@ -522,7 +514,7 @@ void set_font (const std::string& name, const std::string& weight, const std::string& angle, double size); - octave_map get_system_fonts (void); + octave_map get_system_fonts (); void set_color (const Matrix& c); @@ -543,7 +535,7 @@ { public: - ft_font (void) + ft_font () : text_renderer::font (), m_face (nullptr) { } ft_font (const std::string& nm, const std::string& wt, @@ -553,7 +545,7 @@ ft_font (const ft_font& ft); - ~ft_font (void) + ~ft_font () { if (m_face) FT_Done_Face (m_face); @@ -561,20 +553,20 @@ ft_font& operator = (const ft_font& ft); - bool is_valid (void) const { return get_face (); } + bool is_valid () const { return get_face (); } - FT_Face get_face (void) const; + FT_Face get_face () const; private: mutable FT_Face m_face; }; - void push_new_line (void); + void push_new_line (); - void update_line_bbox (void); + void update_line_bbox (); - void compute_bbox (void); + void compute_bbox (); int compute_line_xoffset (const Matrix& lb) const; @@ -660,13 +652,13 @@ } octave_map -ft_text_renderer::get_system_fonts (void) +ft_text_renderer::get_system_fonts () { return ft_manager::get_system_fonts (); } void -ft_text_renderer::push_new_line (void) +ft_text_renderer::push_new_line () { switch (m_mode) { @@ -727,7 +719,7 @@ } void -ft_text_renderer::compute_bbox (void) +ft_text_renderer::compute_bbox () { // Stack the various line bbox together and compute the final // bounding box for the entire text string. @@ -761,7 +753,7 @@ } void -ft_text_renderer::update_line_bbox (void) +ft_text_renderer::update_line_bbox () { // Called after a font change, when in MODE_BBOX mode, to update the // current line bbox with the new font metrics. This also includes the @@ -1368,7 +1360,7 @@ } void -ft_text_renderer::reset (void) +ft_text_renderer::reset () { set_mode (MODE_BBOX); set_color (Matrix (1, 3, 0.0)); @@ -1509,7 +1501,7 @@ } FT_Face -ft_text_renderer::ft_font::get_face (void) const +ft_text_renderer::ft_font::get_face () const { if (! m_face && ! m_name.empty ()) { @@ -1534,7 +1526,7 @@ OCTAVE_BEGIN_NAMESPACE(octave) base_text_renderer * -make_ft_text_renderer (void) +make_ft_text_renderer () { #if defined (HAVE_FREETYPE) return new ft_text_renderer (); diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/ft-text-renderer.h --- a/libinterp/corefcn/ft-text-renderer.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/ft-text-renderer.h Fri May 12 08:03:14 2023 +0200 @@ -32,7 +32,7 @@ class base_text_renderer; -extern base_text_renderer * make_ft_text_renderer (void); +extern base_text_renderer * make_ft_text_renderer (); OCTAVE_END_NAMESPACE(octave) diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/genprops.awk --- a/libinterp/corefcn/genprops.awk Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/genprops.awk Fri May 12 08:03:14 2023 +0200 @@ -44,7 +44,7 @@ ## in the class declaration: ## ## TYPE -## get_NAME (void) const +## get_NAME () const ## { ## return NAME; ## } @@ -151,7 +151,7 @@ function emit_get_accessor (i, rtype, faccess) { - printf (" %s get_%s (void) const", rtype, name[i]); + printf (" %s get_%s () const", rtype, name[i]); if (emit_get[i] == "definition" && deprecated[i]) printf ("\n {\n warning_with_id (\"Octave:deprecated-property\",\"'%s' is deprecated and will be removed from a future version of Octave\");\n return m_%s.%s ();\n }\n", name[i], name[i], faccess); @@ -165,7 +165,7 @@ function emit_get_bool (i) { - printf (" bool is_%s (void) const", name[i]); + printf (" bool is_%s () const", name[i]); if (emit_get[i] == "definition") printf (" { return m_%s.is_on (); }\n", name[i]); @@ -193,7 +193,7 @@ function emit_get_color (i) { - printf (" bool %s_is_rgb (void) const { return m_%s.is_rgb (); }\n", name[i], name[i]); + printf (" bool %s_is_rgb () const { return m_%s.is_rgb (); }\n", name[i], name[i]); printf (" bool %s_is (const std::string& v) const", name[i]); @@ -202,7 +202,7 @@ else printf (";\n"); - printf (" Matrix get_%s_rgb (void) const", name[i]); + printf (" Matrix get_%s_rgb () const", name[i]); if (emit_get[i] == "definition") printf (" { return (m_%s.is_rgb () ? m_%s.rgb () : Matrix ()); }\n", name[i], name[i]); @@ -216,7 +216,7 @@ function emit_get_double_radio (i) { - printf (" bool %s_is_double (void) const { return m_%s.is_double (); }\n", name[i], name[i]); + printf (" bool %s_is_double () const { return m_%s.is_double (); }\n", name[i], name[i]); printf (" bool %s_is (const std::string& v) const", name[i]); @@ -225,7 +225,7 @@ else printf (";\n"); - printf (" double get_%s_double (void) const", name[i]); + printf (" double get_%s_double () const", name[i]); if (emit_get[i] == "definition") printf (" { return (m_%s.is_double () ? m_%s.double_value () : 0); }\n", name[i], name[i]); @@ -260,14 +260,14 @@ function emit_get_string_array (i) { - printf (" std::string get_%s_string (void) const", name[i]); + printf (" std::string get_%s_string () const", name[i]); if (emit_get[i] == "definition") printf (" { return m_%s.string_value (); }\n", name[i]); else printf (";\n"); - printf (" string_vector get_%s_vector (void) const", name[i]); + printf (" string_vector get_%s_vector () const", name[i]); if (emit_get[i] == "definition") printf (" { return m_%s.string_vector_value (); }\n", name[i]); @@ -283,15 +283,17 @@ { printf ("public:\n"); printf (" properties (const graphics_handle& mh, const graphics_handle& p);\n\n"); - printf (" ~properties (void) { }\n\n"); + printf (" properties () = delete;\n\n"); + printf (" OCTAVE_DISABLE_COPY_MOVE (properties)\n\n"); + printf (" ~properties () = default;\n\n"); printf (" void set (const caseless_str& pname, const octave_value& val);\n\n"); printf (" octave_value get (bool all = false) const;\n\n"); printf (" octave_value get (const caseless_str& pname) const;\n\n"); printf (" octave_value get (const std::string& pname) const\n {\n return get (caseless_str (pname));\n }\n\n"); printf (" octave_value get (const char *pname) const\n {\n return get (caseless_str (pname));\n }\n\n"); printf (" property get_property (const caseless_str& pname);\n\n"); - printf (" std::string graphics_object_name (void) const { return s_go_name; }\n\n"); - printf (" static property_list::pval_map_type factory_defaults (void);\n\n"); + printf (" std::string graphics_object_name () const { return s_go_name; }\n\n"); + printf (" static property_list::pval_map_type factory_defaults ();\n\n"); printf ("private:\n static std::string s_go_name;\n\n"); } @@ -300,7 +302,7 @@ if (class_name && ! base) emit_common_declarations(); - printf ("public:\n\n\n static std::set core_property_names (void);\n\n static std::set readonly_property_names (void);\n\n static bool has_core_property (const caseless_str& pname);\n\n static bool has_readonly_property (const caseless_str& pname);\n\n std::set all_property_names (void) const;\n\n"); + printf ("public:\n\n\n static std::set core_property_names ();\n\n static std::set readonly_property_names ();\n\n static bool has_core_property (const caseless_str& pname);\n\n static bool has_readonly_property (const caseless_str& pname);\n\n std::set all_property_names () const;\n\n"); if (! base) printf (" bool has_property (const caseless_str& pname) const;\n\n"); @@ -357,7 +359,7 @@ emit_get_string_array(i); else { - printf (" %s get_%s (void) const", type[i], name[i]); + printf (" %s get_%s () const", type[i], name[i]); if (emit_get[i] == "definition") printf (" { return m_%s; }\n", name[i]); @@ -418,7 +420,7 @@ if (updater[i] == "extern") { - printf (" void update_%s (void);\n\n", name[i]); + printf (" void update_%s ();\n\n", name[i]); } ## if (emit_ov_set[i]) @@ -593,12 +595,12 @@ if (base) { - printf ("property_list::pval_map_type\nbase_properties::factory_defaults (void)\n{\n"); + printf ("property_list::pval_map_type\nbase_properties::factory_defaults ()\n{\n"); printf (" property_list::pval_map_type m;\n\n"); } else { - printf ("property_list::pval_map_type\n%s::properties::factory_defaults (void)\n{\n", + printf ("property_list::pval_map_type\n%s::properties::factory_defaults ()\n{\n", class_name); printf (" property_list::pval_map_type m = base_properties::factory_defaults ();\n\n"); } @@ -638,7 +640,7 @@ printf ("base_properties"); else printf ("%s::properties", class_name); - printf ("::core_property_names (void)\n{\n static std::set all_pnames;\n\n static bool initialized = false;\n\n if (! initialized)\n {\n"); + printf ("::core_property_names ()\n{\n static std::set all_pnames;\n\n static bool initialized = false;\n\n if (! initialized)\n {\n"); for (i = 1; i <= idx; i++) printf (" all_pnames.insert (\"%s\");\n", name[i]); if (! base) @@ -658,7 +660,7 @@ printf ("base_properties"); else printf ("%s::properties", class_name); - printf ("::readonly_property_names (void)\n{\n static std::set all_pnames;\n\n static bool initialized = false;\n\n if (! initialized)\n {\n"); + printf ("::readonly_property_names ()\n{\n static std::set all_pnames;\n\n static bool initialized = false;\n\n if (! initialized)\n {\n"); for (i = 1; i <= idx; i++) if (readonly[i]) { @@ -681,7 +683,7 @@ printf ("base_properties"); else printf ("%s::properties", class_name); - printf ("::all_property_names (void) const\n{\n static std::set all_pnames = core_property_names ();\n\n"); + printf ("::all_property_names () const\n{\n static std::set all_pnames = core_property_names ();\n\n"); if (base) printf (" std::set retval = all_pnames;\n std::set dyn_props = dynamic_property_names ();\n retval.insert (dyn_props.begin (), dyn_props.end ());\n for (std::map::const_iterator p = m_all_props.begin ();\n p != m_all_props.end (); p++)\n retval.insert (p->first);\n\n return retval;\n}\n\n"); else diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/gh-manager.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libinterp/corefcn/gh-manager.cc Fri May 12 08:03:14 2023 +0200 @@ -0,0 +1,705 @@ +//////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2007-2023 The Octave Project Developers +// +// See the file COPYRIGHT.md in the top-level directory of this +// distribution or . +// +// 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 +// . +// +//////////////////////////////////////////////////////////////////////// + +#if defined (HAVE_CONFIG_H) +# include "config.h" +#endif + +#include "cmd-edit.h" + +#include "builtin-defun-decls.h" +#include "gh-manager.h" +#include "graphics-utils.h" +#include "input.h" +#include "interpreter-private.h" +#include "interpreter.h" + +OCTAVE_BEGIN_NAMESPACE(octave) + +static double +make_handle_fraction () +{ + static double maxrand = RAND_MAX + 2.0; + + return (rand () + 1.0) / maxrand; +} + +graphics_handle +gh_manager::get_handle (bool integer_figure_handle) +{ + graphics_handle retval; + + if (integer_figure_handle) + { + // Figure handles are positive integers corresponding + // to the figure number. + + // We always want the lowest unused figure number. + + retval = 1; + + while (m_handle_map.find (retval) != m_handle_map.end ()) + retval++; + } + else + { + // Other graphics handles are negative integers plus some random + // fractional part. To avoid running out of integers, we recycle the + // integer part but tack on a new random part each time. + + auto p = m_handle_free_list.begin (); + + if (p != m_handle_free_list.end ()) + { + retval = *p; + m_handle_free_list.erase (p); + } + else + { + retval = graphics_handle (m_next_handle); + + m_next_handle = std::ceil (m_next_handle) - 1.0 - make_handle_fraction (); + } + } + + return retval; +} + +void +gh_manager::free (const graphics_handle& h, bool from_root) +{ + if (h.ok ()) + { + if (h.value () == 0) + error ("graphics_handle::free: can't delete root object"); + + auto p = m_handle_map.find (h); + + if (p == m_handle_map.end ()) + error ("graphics_handle::free: invalid object %g", h.value ()); + + base_properties& bp = p->second.get_properties (); + + if (! p->second.valid_object () || bp.is_beingdeleted ()) + return; + + graphics_handle parent_h = p->second.get_parent (); + graphics_object parent_go = nullptr; + if (! from_root || isfigure (h.value ())) + parent_go = get_object (parent_h); + + bp.set_beingdeleted (true); + + // delete listeners before invalidating object + p->second.remove_all_listeners (); + + bp.delete_children (true, from_root); + + // NOTE: Call the delete function while the object's state is still valid. + octave_value val = bp.get_deletefcn (); + + bp.execute_deletefcn (); + + // Notify graphics toolkit. + p->second.finalize (); + + + // NOTE: Call remove_child before erasing the go from the map if not + // removing from groot. + // A callback function might have already deleted the parent + if ((! from_root || isfigure (h.value ())) && parent_go.valid_object () + && h.ok ()) + parent_go.remove_child (h); + + // Note: this will be valid only for first explicitly deleted + // object. All its children will then have an + // unknown graphics toolkit. + + // Graphics handles for non-figure objects are negative + // integers plus some random fractional part. To avoid + // running out of integers, we recycle the integer part + // but tack on a new random part each time. + + m_handle_map.erase (p); + + if (h.value () < 0) + m_handle_free_list.insert + (std::ceil (h.value ()) - make_handle_fraction ()); + } +} + +void +gh_manager::renumber_figure (const graphics_handle& old_gh, + const graphics_handle& new_gh) +{ + auto p = m_handle_map.find (old_gh); + + if (p == m_handle_map.end ()) + error ("graphics_handle::free: invalid object %g", old_gh.value ()); + + graphics_object go = p->second; + + m_handle_map.erase (p); + + m_handle_map[new_gh] = go; + + if (old_gh.value () < 0) + m_handle_free_list.insert (std::ceil (old_gh.value ()) + - make_handle_fraction ()); + + for (auto& hfig : m_figure_list) + { + if (hfig == old_gh) + { + hfig = new_gh; + break; + } + } +} + +void +gh_manager::close_all_figures () +{ + // FIXME: should we process or discard pending events? + + m_event_queue.clear (); + + // Don't use m_figure_list_iterator because we'll be removing elements + // from the list elsewhere. + + Matrix hlist = figure_handle_list (true); + + for (octave_idx_type i = 0; i < hlist.numel (); i++) + { + graphics_handle h = lookup (hlist(i)); + + if (h.ok ()) + close_figure (h); + } + + // They should all be closed now. If not, force them to close. + + hlist = figure_handle_list (true); + + for (octave_idx_type i = 0; i < hlist.numel (); i++) + { + graphics_handle h = lookup (hlist(i)); + + if (h.ok ()) + force_close_figure (h); + } + + // None left now, right? + + hlist = figure_handle_list (true); + + if (hlist.numel () != 0) + warning ("gh_manager::close_all_figures: some graphics elements failed to close"); + + // Clear all callback objects from our list. + + m_callback_objects.clear (); +} + +// We use a random value for the handle to avoid issues with plots and +// scalar values for the first argument. +gh_manager::gh_manager (octave::interpreter& interp) + : m_interpreter (interp), m_handle_map (), m_handle_free_list (), + m_next_handle (-1.0 - (rand () + 1.0) / (RAND_MAX + 2.0)), + m_figure_list (), m_graphics_lock (), m_event_queue (), + m_callback_objects (), m_event_processing (0) +{ + m_handle_map[0] = graphics_object (new root_figure ()); + + octave::gtk_manager& gtk_mgr = octave::__get_gtk_manager__ (); + + // Make sure the default graphics toolkit is registered. + gtk_mgr.default_toolkit (); +} + +graphics_handle +gh_manager::make_graphics_handle (const std::string& go_name, + const graphics_handle& p, + bool integer_figure_handle, + bool call_createfcn, bool notify_toolkit) +{ + graphics_handle h = get_handle (integer_figure_handle); + + base_graphics_object *bgo = make_graphics_object_from_type (go_name, h, p); + + if (! bgo) + error ("gh_manager::make_graphics_handle: invalid object type '%s'", + go_name.c_str ()); + + graphics_object go (bgo); + + m_handle_map[h] = go; + + if (go_name == "axes") + { + // Handle defaults for labels since overriding defaults for + // them can't work before the axes object is fully + // constructed. + + axes::properties& props + = dynamic_cast (go.get_properties ()); + + graphics_object tgo; + + tgo = get_object (props.get_xlabel ()); + tgo.override_defaults (); + + tgo = get_object (props.get_ylabel ()); + tgo.override_defaults (); + + tgo = get_object (props.get_zlabel ()); + tgo.override_defaults (); + + tgo = get_object (props.get_title ()); + tgo.override_defaults (); + } + + // Overriding defaults will work now because the handle is valid + // and we can find parent objects (not just handles). + go.override_defaults (); + + if (call_createfcn) + bgo->get_properties ().execute_createfcn (); + + // Notify graphics toolkit. + if (notify_toolkit) + go.initialize (); + + return h; +} + +graphics_handle +gh_manager::make_figure_handle (double val, bool notify_toolkit) +{ + graphics_handle h = val; + + base_graphics_object *bgo = new figure (h, 0); + graphics_object go (bgo); + + m_handle_map[h] = go; + + // Notify graphics toolkit. + if (notify_toolkit) + go.initialize (); + + go.override_defaults (); + + return h; +} + +void +gh_manager::push_figure (const graphics_handle& h) +{ + pop_figure (h); + + m_figure_list.push_front (h); +} + +void +gh_manager::pop_figure (const graphics_handle& h) +{ + for (auto it = m_figure_list.begin (); it != m_figure_list.end (); it++) + { + if (*it == h) + { + m_figure_list.erase (it); + break; + } + } +} + +static void +xset_gcbo (const graphics_handle& h) +{ + gh_manager& gh_mgr = octave::__get_gh_manager__ (); + + graphics_object go = gh_mgr.get_object (0); + + root_figure::properties& props + = dynamic_cast (go.get_properties ()); + + props.set_callbackobject (h.as_octave_value ()); +} + +void +gh_manager::restore_gcbo () +{ + octave::autolock guard (m_graphics_lock); + + m_callback_objects.pop_front (); + + xset_gcbo (m_callback_objects.empty () + ? graphics_handle () : m_callback_objects.front ().get_handle ()); +} + +void +gh_manager::execute_listener (const graphics_handle& h, const octave_value& l) +{ + if (octave::thread::is_thread ()) + execute_callback (h, l, octave_value ()); + else + { + octave::autolock guard (m_graphics_lock); + + post_event (graphics_event::create_callback_event (h, l)); + } +} + +void +gh_manager::execute_callback (const graphics_handle& h, + const octave_value& cb_arg, + const octave_value& data) +{ + if (cb_arg.is_defined () && ! cb_arg.isempty ()) + { + octave_value_list args; + octave_value ov_fcn; + octave_function *fcn = nullptr; + + args(0) = h.as_octave_value (); + if (data.is_defined ()) + args(1) = data; + else + args(1) = Matrix (); + + octave::unwind_action_safe restore_gcbo_action + (&gh_manager::restore_gcbo, this); + + graphics_object go (get_object (h)); + if (go) + { + // FIXME: Is the lock necessary when we're only calling a + // const "get" method? + octave::autolock guard (m_graphics_lock); + m_callback_objects.push_front (go); + xset_gcbo (h); + } + + // Copy CB because "function_value" method is non-const. + octave_value cb = cb_arg; + + if (cb.is_function ()) + fcn = cb.function_value (); + else if (cb.is_function_handle ()) + ov_fcn = cb; + else if (cb.is_string ()) + { + int status; + std::string s = cb.string_value (); + + try + { + m_interpreter.eval_string (s, false, status, 0); + } + catch (const octave::execution_exception& ee) + { + m_interpreter.handle_exception (ee); + } + } + else if (cb.iscell () && cb.length () > 0 + && (cb.rows () == 1 || cb.columns () == 1) + && (cb.cell_value ()(0).is_function () + || cb.cell_value ()(0).is_function_handle ())) + { + Cell c = cb.cell_value (); + + ov_fcn = c(0); + + for (int i = 1; i < c.numel () ; i++) + args(1+i) = c(i); + } + else + { + std::string nm = cb.class_name (); + error ("trying to execute non-executable object (class = %s)", + nm.c_str ()); + } + + if (fcn || ov_fcn.is_defined ()) + try + { + if (ov_fcn.is_defined ()) + m_interpreter.feval (ov_fcn, args); + else + m_interpreter.feval (fcn, args); + } + catch (const octave::execution_exception& ee) + { + m_interpreter.handle_exception (ee); + } + + // Redraw after interacting with a user-interface (ui*) object. + if (Vdrawnow_requested) + { + if (go) + { + std::string go_name + = go.get_properties ().graphics_object_name (); + + if (go_name.length () > 1 + && go_name[0] == 'u' && go_name[1] == 'i') + { + Fdrawnow (m_interpreter); + Vdrawnow_requested = false; + } + } + } + } +} + +static int +process_graphics_events () +{ + gh_manager& gh_mgr = octave::__get_gh_manager__ (); + + return gh_mgr.process_events (); +} + +void +gh_manager::post_event (const graphics_event& e) +{ + m_event_queue.push_back (e); + + octave::command_editor::add_event_hook (process_graphics_events); +} + +void +gh_manager::post_callback (const graphics_handle& h, const std::string& name, + const octave_value& data) +{ + octave::autolock guard (m_graphics_lock); + + graphics_object go = get_object (h); + + if (go.valid_object ()) + { + caseless_str cname (name); + int busyaction = base_graphics_event::QUEUE; + + if (cname == "deletefcn" || cname == "createfcn" + || cname == "closerequestfcn" + || ((go.isa ("figure") || go.isa ("uipanel") + || go.isa ("uibuttongroup")) + && (cname == "resizefcn" || cname == "sizechangedfcn"))) + busyaction = base_graphics_event::INTERRUPT; + else if (go.get_properties ().get_busyaction () == "cancel") + busyaction = base_graphics_event::CANCEL; + + // The "closerequestfcn" callback must be executed once the figure has + // been made current. Let "close" do the job. + if (cname == "closerequestfcn") + { + std::string cmd ("close (gcbf ());"); + post_event (graphics_event::create_mcode_event (h, cmd, busyaction)); + } + else + post_event (graphics_event::create_callback_event (h, name, data, + busyaction)); + } +} + +void +gh_manager::post_function (graphics_event::event_fcn fcn, void *fcn_data) +{ + octave::autolock guard (m_graphics_lock); + + post_event (graphics_event::create_function_event (fcn, fcn_data)); +} + +void +gh_manager::post_set (const graphics_handle& h, const std::string& name, + const octave_value& value, bool notify_toolkit, + bool redraw_figure) +{ + octave::autolock guard (m_graphics_lock); + + post_event (graphics_event::create_set_event (h, name, value, notify_toolkit, + redraw_figure)); +} + +int +gh_manager::process_events (bool force) +{ + graphics_event e; + bool old_Vdrawnow_requested = Vdrawnow_requested; + bool events_executed = false; + + do + { + e = graphics_event (); + + { + octave::autolock guard (m_graphics_lock); + + if (! m_event_queue.empty ()) + { + if (m_callback_objects.empty () || force) + { + e = m_event_queue.front (); + + m_event_queue.pop_front (); + } + else + { + const graphics_object& go = m_callback_objects.front (); + + if (go.get_properties ().is_interruptible ()) + { + e = m_event_queue.front (); + + m_event_queue.pop_front (); + } + else + { + std::list::iterator p = m_event_queue.begin (); + + while (p != m_event_queue.end ()) + if (p->get_busyaction () == base_graphics_event::CANCEL) + { + p = m_event_queue.erase (p); + } + else if (p->get_busyaction () + == base_graphics_event::INTERRUPT) + { + e = (*p); + m_event_queue.erase (p); + break; + } + else + p++; + } + } + } + } + + if (e.ok ()) + { + e.execute (); + events_executed = true; + } + } + while (e.ok ()); + + { + octave::autolock guard (m_graphics_lock); + + if (m_event_queue.empty () && m_event_processing == 0) + octave::command_editor::remove_event_hook (process_graphics_events); + } + + if (events_executed) + octave::flush_stdout (); + + if (Vdrawnow_requested && ! old_Vdrawnow_requested) + { + Fdrawnow (m_interpreter); + + Vdrawnow_requested = false; + } + + return 0; +} + + +/* +## Test interruptible/busyaction properties +%!function cb (h, ~) +%! setappdata (gcbf (), "cb_exec", [getappdata(gcbf (), "cb_exec") h]); +%! drawnow (); +%! setappdata (gcbf (), "cb_exec", [getappdata(gcbf (), "cb_exec") h]); +%!endfunction +%! +%!testif HAVE_OPENGL, HAVE_QT; have_window_system () && any (strcmp ("qt", available_graphics_toolkits ())) +%! hf = figure ("visible", "off", "resizefcn", @cb); +%! graphics_toolkit (hf, "qt"); +%! unwind_protect +%! ## Default +%! hui1 = uicontrol ("parent", hf, "interruptible", "on", "callback", @cb); +%! hui2 = uicontrol ("parent", hf, "busyaction", "queue", "callback", @cb); +%! hui3 = uicontrol ("parent", hf, "busyaction", "queue", "callback", @cb); +%! __go_post_callback__ (hui1, "callback"); +%! __go_post_callback__ (hui2, "callback"); +%! __go_post_callback__ (hui3, "callback"); +%! +%! assert (getappdata (hf, "cb_exec"), []); +%! drawnow (); +%! assert (getappdata (hf, "cb_exec"), [hui1 hui2 hui3 hui3 hui2 hui1]); +%! +%! ## Interruptible off +%! setappdata (hf, "cb_exec", []); +%! set (hui1, "interruptible", "off"); +%! __go_post_callback__ (hui1, "callback"); +%! __go_post_callback__ (hui2, "callback"); +%! __go_post_callback__ (hui3, "callback"); +%! drawnow (); +%! assert (getappdata (hf, "cb_exec"), [hui1 hui1 hui2 hui3 hui3 hui2]); +%! +%! ## "resizefcn" callback interrupts regardless of interruptible property +%! setappdata (hf, "cb_exec", []); +%! __go_post_callback__ (hui1, "callback"); +%! __go_post_callback__ (hf, "resizefcn"); +%! drawnow (); +%! assert (getappdata (hf, "cb_exec"), [hui1 hf hf hui1]); +%! +%! ## test "busyaction" "cancel" +%! setappdata (hf, "cb_exec", []); +%! set (hui2, "busyaction", "cancel"); +%! __go_post_callback__ (hui1, "callback"); +%! __go_post_callback__ (hui2, "callback"); +%! __go_post_callback__ (hui3, "callback"); +%! __go_post_callback__ (hf, "resizefcn"); +%! drawnow (); +%! assert (getappdata (hf, "cb_exec"), [hui1 hf hui3 hui3 hf hui1]); +%! unwind_protect_cleanup +%! close (hf) +%! end_unwind_protect +*/ + +void +gh_manager::enable_event_processing (bool enable) +{ + octave::autolock guard (m_graphics_lock); + + if (enable) + { + m_event_processing++; + + octave::command_editor::add_event_hook (process_graphics_events); + } + else + { + m_event_processing--; + + if (m_event_queue.empty () && m_event_processing == 0) + octave::command_editor::remove_event_hook (process_graphics_events); + } +} + +OCTAVE_END_NAMESPACE(octave) diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/gh-manager.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libinterp/corefcn/gh-manager.h Fri May 12 08:03:14 2023 +0200 @@ -0,0 +1,288 @@ +//////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2007-2023 The Octave Project Developers +// +// See the file COPYRIGHT.md in the top-level directory of this +// distribution or . +// +// 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 +// . +// +//////////////////////////////////////////////////////////////////////// + +#if ! defined (octave_gh_manager_h) +#define octave_gh_manager_h 1 + +#include "octave-config.h" + +#include "graphics.h" +#include "gtk-manager.h" + +OCTAVE_BEGIN_NAMESPACE(octave) + +class OCTINTERP_API gh_manager +{ +public: + + typedef std::pair latex_data; + + OCTINTERP_API gh_manager (octave::interpreter& interp); + + // FIXME: eventually eliminate these static functions and access + // gh_manager object through the interpreter. + + OCTINTERP_API graphics_handle get_handle (bool integer_figure_handle); + + OCTINTERP_API void free (const graphics_handle& h, bool from_root = false); + + OCTINTERP_API void renumber_figure (const graphics_handle& old_gh, + const graphics_handle& new_gh); + + graphics_handle lookup (double val) const + { + const_iterator p = (octave::math::isnan (val) + ? m_handle_map.end () : m_handle_map.find (val)); + + return (p != m_handle_map.end ()) ? p->first : graphics_handle (); + } + + graphics_handle lookup (const octave_value& val) const + { + return (val.is_real_scalar () + ? lookup (val.double_value ()) : graphics_handle ()); + } + + graphics_object get_object (double val) const + { + return get_object (lookup (val)); + } + + graphics_object get_object (const graphics_handle& h) const + { + const_iterator p = (h.ok () ? m_handle_map.find (h) : m_handle_map.end ()); + + return (p != m_handle_map.end ()) ? p->second : graphics_object (); + } + + OCTINTERP_API graphics_handle + make_graphics_handle (const std::string& go_name, + const graphics_handle& p, + bool integer_figure_handle = false, + bool call_createfcn = true, + bool notify_toolkit = true); + + OCTINTERP_API graphics_handle + make_figure_handle (double val, bool notify_toolkit = true); + + OCTINTERP_API void push_figure (const graphics_handle& h); + + OCTINTERP_API void pop_figure (const graphics_handle& h); + + graphics_handle current_figure () const + { + graphics_handle retval; + + for (const auto& hfig : m_figure_list) + { + if (is_handle_visible (hfig)) + retval = hfig; + } + + return retval; + } + + Matrix handle_list (bool show_hidden = false) + { + Matrix retval (1, m_handle_map.size ()); + + octave_idx_type i = 0; + for (const auto& h_iter : m_handle_map) + { + graphics_handle h = h_iter.first; + + if (show_hidden || is_handle_visible (h)) + retval(i++) = h.value (); + } + + retval.resize (1, i); + + return retval; + } + + void lock () { m_graphics_lock.lock (); } + + bool try_lock () { return m_graphics_lock.try_lock (); } + + void unlock () { m_graphics_lock.unlock (); } + + Matrix figure_handle_list (bool show_hidden = false) + { + Matrix retval (1, m_figure_list.size ()); + + octave_idx_type i = 0; + for (const auto& hfig : m_figure_list) + { + if (show_hidden || is_handle_visible (hfig)) + retval(i++) = hfig.value (); + } + + retval.resize (1, i); + + return retval; + } + + OCTINTERP_API void + execute_listener (const graphics_handle& h, const octave_value& l); + + void execute_callback (const graphics_handle& h, + const std::string& name, + const octave_value& data = Matrix ()) + { + octave_value cb; + + if (true) + { + octave::autolock guard (graphics_lock ()); + + graphics_object go = get_object (h); + + if (go.valid_object ()) + cb = go.get (name); + } + + execute_callback (h, cb, data); + } + + OCTINTERP_API void + execute_callback (const graphics_handle& h, const octave_value& cb, + const octave_value& data = Matrix ()); + + OCTINTERP_API void + post_callback (const graphics_handle& h, const std::string& name, + const octave_value& data = Matrix ()); + + OCTINTERP_API void + post_function (graphics_event::event_fcn fcn, void *fcn_data = nullptr); + + OCTINTERP_API void + post_set (const graphics_handle& h, const std::string& name, + const octave_value& value, bool notify_toolkit = true, + bool redraw_figure = false); + + OCTINTERP_API int process_events (bool force = false); + + OCTINTERP_API void enable_event_processing (bool enable = true); + + bool is_handle_visible (const graphics_handle& h) const + { + bool retval = false; + + graphics_object go = get_object (h); + + if (go.valid_object ()) + retval = go.is_handle_visible (); + + return retval; + } + + OCTINTERP_API void close_all_figures (); + + OCTINTERP_API void restore_gcbo (); + + OCTINTERP_API void post_event (const graphics_event& e); + + octave::mutex graphics_lock () + { + return m_graphics_lock; + } + + latex_data get_latex_data (const std::string& key) const + { + latex_data retval; + + const auto it = m_latex_cache.find (key); + + if (it != m_latex_cache.end ()) + retval = it->second; + + return retval; + } + + void set_latex_data (const std::string& key, latex_data val) + { + // Limit the number of cache entries to 500 + if (m_latex_keys.size () >= 500) + { + auto it = m_latex_cache.find (m_latex_keys.front ()); + + if (it != m_latex_cache.end ()) + m_latex_cache.erase (it); + + m_latex_keys.pop_front (); + } + + m_latex_cache[key] = val; + m_latex_keys.push_back (key); + } + +private: + + typedef std::map::iterator iterator; + typedef std::map::const_iterator + const_iterator; + + typedef std::set::iterator free_list_iterator; + typedef std::set::const_iterator const_free_list_iterator; + + typedef std::list::iterator figure_list_iterator; + typedef std::list::const_iterator const_figure_list_iterator; + + octave::interpreter& m_interpreter; + + // A map of handles to graphics objects. + std::map m_handle_map; + + // The available graphics handles. + std::set m_handle_free_list; + + // The next handle available if m_handle_free_list is empty. + double m_next_handle; + + // The allocated figure handles. Top of the stack is most recently + // created. + std::list m_figure_list; + + // The lock for accessing the graphics sytsem. + octave::mutex m_graphics_lock; + + // The list of events queued by graphics toolkits. + std::list m_event_queue; + + // The stack of callback objects. + std::list m_callback_objects; + + // A flag telling whether event processing must be constantly on. + int m_event_processing; + + // Cache of already parsed latex strings. Store a separate list of keys + // to allow for erasing oldest entries if cache size becomes too large. + std::unordered_map m_latex_cache; + std::list m_latex_keys; +}; + +OCTAVE_END_NAMESPACE(octave) + +#endif diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/gl-render.cc --- a/libinterp/corefcn/gl-render.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/gl-render.cc Fri May 12 08:03:14 2023 +0200 @@ -40,6 +40,7 @@ #include "oct-locbuf.h" #include "errwarn.h" +#include "gh-manager.h" #include "gl-render.h" #include "interpreter-private.h" #include "oct-opengl.h" @@ -113,7 +114,9 @@ m_tx (double(m_w)/m_tw), m_ty (double(m_h)/m_th), m_valid (true) { } - ~texture_rep (void) + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (texture_rep) + + ~texture_rep () { if (m_valid) m_glfcns.glDeleteTextures (1, &m_id); @@ -141,6 +144,8 @@ public: + opengl_texture () = delete; + opengl_texture (opengl_functions& glfcns) : m_rep (new texture_rep (glfcns)) { } @@ -150,11 +155,7 @@ : m_rep (new texture_rep (glfcns, id, w, h, tw, th)) { } - opengl_texture (const opengl_texture&) = default; - - ~opengl_texture (void) = default; - - opengl_texture& operator = (const opengl_texture&) = default; + OCTAVE_DEFAULT_COPY_DELETE (opengl_texture) static opengl_texture create (opengl_functions& glfcns, const octave_value& data); @@ -163,7 +164,7 @@ void tex_coord (double q, double r) const { m_rep->tex_coord (q, r); } - bool is_valid (void) const { return m_rep->m_valid; } + bool is_valid () const { return m_rep->m_valid; } private: @@ -345,20 +346,16 @@ #if defined (HAVE_FRAMEWORK_OPENGL) && defined (HAVE_GLUTESSCALLBACK_THREEDOTS) typedef GLvoid (CALLBACK *fcn) (...); #else - typedef void (CALLBACK *fcn) (void); + typedef void (CALLBACK *fcn) (); #endif public: - opengl_tessellator (void) : m_glu_tess (nullptr), m_fill () { init (); } - - // No copying! - - opengl_tessellator (const opengl_tessellator&) = delete; - - opengl_tessellator operator = (const opengl_tessellator&) = delete; - - virtual ~opengl_tessellator (void) + opengl_tessellator () : m_glu_tess (nullptr), m_fill () { init (); } + + OCTAVE_DISABLE_COPY_MOVE (opengl_tessellator) + + virtual ~opengl_tessellator () { if (m_glu_tess) gluDeleteTess (m_glu_tess); } void begin_polygon (bool filled = true) @@ -369,13 +366,13 @@ gluTessBeginPolygon (m_glu_tess, this); } - void end_polygon (void) const + void end_polygon () const { gluTessEndPolygon (m_glu_tess); } - void begin_contour (void) const + void begin_contour () const { gluTessBeginContour (m_glu_tess); } - void end_contour (void) const + void end_contour () const { gluTessEndContour (m_glu_tess); } void add_vertex (double *loc, void *data) const @@ -384,7 +381,7 @@ protected: virtual void begin (GLenum /*type*/) { } - virtual void end (void) { } + virtual void end () { } virtual void vertex (void * /*data*/) { } @@ -396,7 +393,7 @@ virtual void error (GLenum err) { ::error ("OpenGL tessellation error (%d)", err); } - virtual void init (void) + virtual void init () { m_glu_tess = gluNewTess (); @@ -414,7 +411,7 @@ reinterpret_cast (tess_error)); } - bool is_filled (void) const { return m_fill; } + bool is_filled () const { return m_fill; } private: static void CALLBACK tess_begin (GLenum type, void *t) @@ -450,7 +447,7 @@ { public: - vertex_data_rep (void) + vertex_data_rep () : m_coords (), m_color (), m_vertex_normal (), m_face_normal (), m_alpha (), m_ambient (), m_diffuse (), m_specular (), m_specular_exp (), m_specular_color_refl () @@ -464,6 +461,10 @@ m_specular (ss), m_specular_exp (se), m_specular_color_refl (scr) { } + OCTAVE_DEFAULT_COPY (vertex_data_rep) + + ~vertex_data_rep () = default; + Matrix m_coords; Matrix m_color; Matrix m_vertex_normal; @@ -479,7 +480,7 @@ public: // Required to instantiate std::list objects. - vertex_data (void) : m_rep (nil_rep ()) { } + vertex_data () : m_rep (nil_rep ()) { } vertex_data (const Matrix& c, const Matrix& col, const Matrix& vn, const Matrix& fn, double a, float as, float ds, float ss, @@ -489,15 +490,15 @@ vertex_data (const vertex_data&) = default; - ~vertex_data (void) = default; + ~vertex_data () = default; vertex_data& operator = (const vertex_data&) = default; - vertex_data_rep * get_rep (void) const { return m_rep.get (); } + vertex_data_rep * get_rep () const { return m_rep.get (); } private: - static std::shared_ptr nil_rep (void) + static std::shared_ptr nil_rep () { static std::shared_ptr nr (new vertex_data_rep ()); @@ -511,6 +512,7 @@ opengl_renderer::patch_tessellator : public opengl_tessellator { public: + patch_tessellator (opengl_renderer *r, int cmode, int lmode, bool fl, float idx = 0.0) : opengl_tessellator (), m_renderer (r), @@ -518,6 +520,10 @@ m_index (idx), m_first (true), m_tmp_vdata () { } + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (patch_tessellator) + + ~patch_tessellator () = default; + protected: void begin (GLenum type) { @@ -537,7 +543,7 @@ glfcns.glBegin (type); } - void end (void) + void end () { opengl_functions& glfcns = m_renderer->get_opengl_functions (); @@ -656,12 +662,8 @@ private: - // No copying! - - patch_tessellator (const patch_tessellator&) = delete; - - patch_tessellator& operator = (const patch_tessellator&) = delete; - + // FIXME: We don't own this object; should it be a shared/weak/unique + // pointer? Managed some other way? opengl_renderer *m_renderer; int m_color_mode; int m_light_mode; @@ -1252,7 +1254,7 @@ } void -opengl_renderer::finish (void) +opengl_renderer::finish () { #if defined (HAVE_OPENGL) @@ -2172,7 +2174,7 @@ { graphics_object go = gh_mgr.get_object (children(i)); - base_properties p = go.get_properties (); + base_properties& p = go.get_properties (); if (p.is_visible () || (m_selecting && p.pickableparts_is ("all"))) @@ -2272,10 +2274,8 @@ m_glfcns.glDisable (GL_DEPTH_TEST); - for (it = obj_list.begin (); it != obj_list.end (); it++) + for (const graphics_object& go : obj_list) { - graphics_object go = (*it); - set_clipping (go.get_properties ().is_clipping ()); draw (go); } @@ -3880,7 +3880,7 @@ } void -opengl_renderer::set_ortho_coordinates (void) +opengl_renderer::set_ortho_coordinates () { #if defined (HAVE_OPENGL) @@ -3905,7 +3905,7 @@ } void -opengl_renderer::restore_previous_coordinates (void) +opengl_renderer::restore_previous_coordinates () { #if defined (HAVE_OPENGL) @@ -4100,7 +4100,7 @@ // Expect RGB data if (dv.ndims () == 3 && (dv(2) == 3 || dv(2) == 4)) { - opengl_texture tex = opengl_texture::create (m_glfcns, cdata); + opengl_texture tex = opengl_texture::create (m_glfcns, cdata); if (tex.is_valid ()) { m_glfcns.glColor4d (1.0, 1.0, 1.0, 1.0); @@ -4191,7 +4191,7 @@ } Matrix -opengl_renderer::get_viewport_scaled (void) const +opengl_renderer::get_viewport_scaled () const { Matrix retval (1, 4, 0.0); @@ -4497,7 +4497,7 @@ } void -opengl_renderer::end_marker (void) +opengl_renderer::end_marker () { #if defined (HAVE_OPENGL) @@ -4573,7 +4573,7 @@ } void -opengl_renderer::init_maxlights (void) +opengl_renderer::init_maxlights () { #if defined (HAVE_OPENGL) diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/gl-render.h --- a/libinterp/corefcn/gl-render.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/gl-render.h Fri May 12 08:03:14 2023 +0200 @@ -43,15 +43,11 @@ opengl_renderer (opengl_functions& glfcns); - // No copying! - - opengl_renderer (const opengl_renderer&) = delete; + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (opengl_renderer) - opengl_renderer& operator = (const opengl_renderer&) = delete; + virtual ~opengl_renderer () = default; - virtual ~opengl_renderer (void) = default; - - opengl_functions& get_opengl_functions (void) const { return m_glfcns; } + opengl_functions& get_opengl_functions () const { return m_glfcns; } virtual void draw (const graphics_object& go, bool toplevel = true); @@ -62,8 +58,8 @@ virtual void set_viewport (int w, int h); virtual void set_device_pixel_ratio (double dpr) { m_devpixratio = dpr; } - virtual Matrix get_viewport_scaled (void) const; - virtual graphics_xform get_transform (void) const { return m_xform; } + virtual Matrix get_viewport_scaled () const; + virtual graphics_xform get_transform () const { return m_xform; } virtual uint8NDArray get_pixels (int width, int height); virtual void draw_zoom_box (int width, int height, @@ -73,7 +69,7 @@ const Matrix& bordercolor, double borderalpha, double borderwidth); - virtual void finish (void); + virtual void finish (); protected: @@ -118,7 +114,7 @@ virtual void init_marker (const std::string& m, double size, float width); virtual void change_marker (const std::string& m, double size); - virtual void end_marker (void); + virtual void end_marker (); virtual void draw_marker (double x, double y, double z, const Matrix& lc, const Matrix& fc, const double la = 1.0, const double fa = 1.0); @@ -180,7 +176,7 @@ class patch_tessellator; - void init_maxlights (void); + void init_maxlights (); std::string get_string (unsigned int id) const; @@ -208,9 +204,9 @@ void set_normal (int bfl_mode, const NDArray& n, int j, int i); - void set_ortho_coordinates (void); + void set_ortho_coordinates (); - void restore_previous_coordinates (void); + void restore_previous_coordinates (); double points_to_pixels (const double val) const; diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/gl2ps-print.cc --- a/libinterp/corefcn/gl2ps-print.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/gl2ps-print.cc Fri May 12 08:03:14 2023 +0200 @@ -47,6 +47,7 @@ #include "unistr-wrappers.h" #include "unwind-prot.h" +#include "gh-manager.h" #include "gl-render.h" #include "interpreter-private.h" #include "oct-opengl.h" @@ -68,7 +69,9 @@ m_fontname (), m_buffer_overflow (false), m_svg_def_index (0) { } - ~gl2ps_renderer (void) = default; + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (gl2ps_renderer) + + ~gl2ps_renderer () = default; // FIXME: should we import the functions from the base class and // overload them here, or should we use a different name so we don't @@ -1009,8 +1012,8 @@ // provide an x coordinate for each character in the string os << "x=\""; std::vector xdata = p->get_xdata (); - for (auto q = xdata.begin (); q != xdata.end (); q++) - os << (*q) << " "; + for (const auto& q : xdata) + os << q << " "; os << '"'; os << '>'; @@ -1021,10 +1024,10 @@ else { const std::string str = p->get_string (); - for (auto q = str.begin (); q != str.end (); q++) + for (const auto& q : str) { std::stringstream chr; - chr << *q; + chr << q; if (chr.str () == "\"") os << """; else if (chr.str () == "'") diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/graphics-toolkit.cc --- a/libinterp/corefcn/graphics-toolkit.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/graphics-toolkit.cc Fri May 12 08:03:14 2023 +0200 @@ -27,6 +27,7 @@ # include "config.h" #endif +#include "gh-manager.h" #include "graphics.h" #include "gtk-manager.h" #include "interpreter-private.h" diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/graphics-toolkit.h --- a/libinterp/corefcn/graphics-toolkit.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/graphics-toolkit.h Fri May 12 08:03:14 2023 +0200 @@ -55,14 +55,16 @@ : m_name (nm) { } - virtual ~base_graphics_toolkit (void) = default; + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (base_graphics_toolkit) - std::string get_name (void) const + virtual ~base_graphics_toolkit () = default; + + std::string get_name () const { return m_name; } - virtual bool is_valid (void) const + virtual bool is_valid () const { return false; } @@ -96,13 +98,13 @@ return Matrix (1, 2, 0.0); } - virtual double get_screen_resolution (void) const + virtual double get_screen_resolution () const { gripe_if_tkit_invalid ("get_screen_resolution"); return 72.0; } - virtual Matrix get_screen_size (void) const + virtual Matrix get_screen_size () const { gripe_if_tkit_invalid ("get_screen_size"); return Matrix (1, 2, 0.0); @@ -146,7 +148,7 @@ void finalize (const graphics_handle&); // Close the graphics toolkit. - virtual void close (void) + virtual void close () { gripe_if_tkit_invalid ("base_graphics_toolkit::close"); } @@ -183,14 +185,14 @@ graphics_toolkit& operator = (const graphics_toolkit& b) = default; - ~graphics_toolkit (void) = default; + ~graphics_toolkit () = default; - operator bool (void) const + operator bool () const { return m_rep->is_valid (); } - std::string get_name (void) const + std::string get_name () const { return m_rep->get_name (); } @@ -222,12 +224,12 @@ return m_rep->get_canvas_size (fh); } - double get_screen_resolution (void) const + double get_screen_resolution () const { return m_rep->get_screen_resolution (); } - Matrix get_screen_size (void) const + Matrix get_screen_size () const { return m_rep->get_screen_size (); } @@ -273,7 +275,7 @@ } // Close the graphics toolkit. - void close (void) + void close () { m_rep->close (); } diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/graphics-utils.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libinterp/corefcn/graphics-utils.cc Fri May 12 08:03:14 2023 +0200 @@ -0,0 +1,181 @@ +//////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2007-2023 The Octave Project Developers +// +// See the file COPYRIGHT.md in the top-level directory of this +// distribution or . +// +// 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 +// . +// +//////////////////////////////////////////////////////////////////////// + +#if defined (HAVE_CONFIG_H) +# include "config.h" +#endif + +#include "caseless-str.h" + +#include "gh-manager.h" +#include "graphics-utils.h" +#include "graphics.h" +#include "input.h" +#include "interpreter-private.h" +#include "ov.h" + +OCTAVE_BEGIN_NAMESPACE(octave) + +// Flag to stop redraws due to callbacks while deletion is in progress. +bool delete_executing = false; + +void +xset (const graphics_handle& h, const caseless_str& pname, + const octave_value& val) +{ + gh_manager& gh_mgr = octave::__get_gh_manager__ (); + + graphics_object go = gh_mgr.get_object (h); + + go.set (pname, val); +} + +void +xset (const graphics_handle& h, const octave_value_list& args) +{ + if (args.length () > 0) + { + gh_manager& gh_mgr = octave::__get_gh_manager__ (); + + graphics_object go = gh_mgr.get_object (h); + + go.set (args); + } +} + +octave_value +xget (const graphics_handle& h, const caseless_str& pname) +{ + gh_manager& gh_mgr = octave::__get_gh_manager__ (); + + graphics_object go = gh_mgr.get_object (h); + + return go.get (pname); +} + +bool isfigure (double val) +{ + gh_manager& gh_mgr = octave::__get_gh_manager__ (); + + graphics_object go = gh_mgr.get_object (val); + + return go && go.isa ("figure"); +} + +graphics_handle +reparent (const octave_value& ov, const std::string& who, + const std::string& pname, const graphics_handle& new_parent, + bool adopt) +{ + double hv = ov.xdouble_value ("%s: %s must be a graphics handle", + who.c_str (), pname.c_str ()); + + gh_manager& gh_mgr = octave::__get_gh_manager__ (); + + graphics_handle h = gh_mgr.lookup (hv); + + if (! h.ok ()) + error ("%s: invalid graphics handle (= %g) for %s", + who.c_str (), hv, pname.c_str ()); + + graphics_object go = gh_mgr.get_object (h); + + graphics_handle parent_h = go.get_parent (); + + graphics_object parent_go = gh_mgr.get_object (parent_h); + + parent_go.remove_child (h); + + if (adopt) + go.set ("parent", new_parent.value ()); + else + go.reparent (new_parent); + + return h; +} + +void +delete_graphics_object (const graphics_handle& h, bool from_root) +{ + if (h.ok ()) + { + gh_manager& gh_mgr = octave::__get_gh_manager__ (); + + graphics_object go = gh_mgr.get_object (h); + + // Don't do recursive deleting, due to callbacks + if (! go.get_properties ().is_beingdeleted ()) + { + // NOTE: Freeing the handle also calls any deletefcn. It also calls + // the parent's delete_child function. + + gh_mgr.free (h, from_root || go.isa ("figure")); + + Vdrawnow_requested = true; + } + } +} + +void +delete_graphics_object (double val, bool from_root) +{ + gh_manager& gh_mgr = octave::__get_gh_manager__ (); + + delete_graphics_object (gh_mgr.lookup (val), from_root || isfigure (val)); +} + +void +delete_graphics_objects (const NDArray vals, bool from_root) +{ + // Prevent redraw of partially deleted objects. + octave::unwind_protect_var restore_var (delete_executing, true); + + for (octave_idx_type i = 0; i < vals.numel (); i++) + delete_graphics_object (vals.elem (i), from_root); +} + +void +close_figure (const graphics_handle& h) +{ + octave_value closerequestfcn = xget (h, "closerequestfcn"); + + gh_manager& gh_mgr = octave::__get_gh_manager__ (); + + gh_mgr.execute_callback (h, closerequestfcn); +} + +void +force_close_figure (const graphics_handle& h) +{ + // Remove the deletefcn and closerequestfcn callbacks + // and delete the object directly. + + xset (h, "deletefcn", Matrix ()); + xset (h, "closerequestfcn", Matrix ()); + + delete_graphics_object (h, true); +} + +OCTAVE_END_NAMESPACE(octave) diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/graphics-utils.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libinterp/corefcn/graphics-utils.h Fri May 12 08:03:14 2023 +0200 @@ -0,0 +1,75 @@ +//////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2007-2023 The Octave Project Developers +// +// See the file COPYRIGHT.md in the top-level directory of this +// distribution or . +// +// 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 +// . +// +//////////////////////////////////////////////////////////////////////// + +#if ! defined (octave_graphics_utils_h) +#define octave_graphics_utils_h 1 + +// The functions defined here are private and should not be exported. +// This header file should not be installed. + +#include "octave-config.h" + +#include + +#include "graphics-handle.h" + +class caseless_str; +class octave_value; +class NDArray; + +OCTAVE_BEGIN_NAMESPACE(octave) + +// Flag to stop redraws due to callbacks while deletion is in progress. +extern bool delete_executing; + +extern void xset (const graphics_handle& h, const caseless_str& pname, + const octave_value& val); + +extern void xset (const graphics_handle& h, const octave_value_list& args); + +extern octave_value xget (const graphics_handle& h, const caseless_str& pname); + +extern bool isfigure (double val); + +extern graphics_handle +reparent (const octave_value& ov, const std::string& who, + const std::string& pname, const graphics_handle& new_parent, + bool adopt = true); + +extern void +delete_graphics_object (const graphics_handle& h, bool from_root = false); + +extern void delete_graphics_object (double val, bool from_root = false); + +extern void +delete_graphics_objects (const NDArray vals, bool from_root = false); + +extern void close_figure (const graphics_handle& h); + +extern void force_close_figure (const graphics_handle& h); + +OCTAVE_END_NAMESPACE(octave) + +#endif diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/graphics.cc --- a/libinterp/corefcn/graphics.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/graphics.cc Fri May 12 08:03:14 2023 +0200 @@ -44,6 +44,7 @@ #include "cmd-edit.h" #include "file-ops.h" #include "file-stat.h" +#include "lo-sysdep.h" #include "oct-locbuf.h" #include "oct-time.h" @@ -51,6 +52,8 @@ #include "defun.h" #include "display.h" #include "error.h" +#include "gh-manager.h" +#include "graphics-utils.h" #include "graphics.h" #include "input.h" #include "interpreter-private.h" @@ -60,7 +63,6 @@ #include "oct-map.h" #include "ov-fcn-handle.h" #include "pager.h" -#include "parse.h" #include "text-engine.h" #include "text-renderer.h" #include "unwind-prot.h" @@ -69,9 +71,6 @@ OCTAVE_BEGIN_NAMESPACE(octave) -// forward declarations -static octave_value xget (const graphics_handle& h, const caseless_str& name); - OCTAVE_NORETURN static void err_set_invalid (const std::string& pname) @@ -138,7 +137,7 @@ } static Matrix -viridis_colormap (void) +viridis_colormap () { // The values below have been produced by viridis (64)(:) // It would be nice to be able to feval the @@ -222,7 +221,7 @@ } static double -default_screendepth (void) +default_screendepth () { octave::display_info& dpy_info = octave::__get_display_info__ (); @@ -230,7 +229,7 @@ } static Matrix -default_screensize (void) +default_screensize () { Matrix retval (1, 4); @@ -245,7 +244,7 @@ } static double -default_screenpixelsperinch (void) +default_screenpixelsperinch () { octave::display_info& dpy_info = octave::__get_display_info__ (); @@ -253,7 +252,7 @@ } static Matrix -default_colororder (void) +default_colororder () { Matrix retval (7, 3, 0.0); @@ -307,7 +306,7 @@ } static Matrix -default_data (void) +default_data () { Matrix retval (1, 2); @@ -318,7 +317,7 @@ } static Matrix -default_data_lim (void) +default_data_lim () { Matrix retval (1, 4); @@ -331,7 +330,7 @@ } static Matrix -default_image_cdata (void) +default_image_cdata () { Matrix m (64, 64); @@ -347,7 +346,7 @@ } static Matrix -default_surface_xdata (void) +default_surface_xdata () { Matrix m (3, 3); @@ -359,7 +358,7 @@ } static Matrix -default_surface_ydata (void) +default_surface_ydata () { Matrix m (3, 3); @@ -371,7 +370,7 @@ } static Matrix -default_surface_zdata (void) +default_surface_zdata () { Matrix m (3, 3, 0.0); @@ -382,13 +381,13 @@ } static Matrix -default_surface_cdata (void) +default_surface_cdata () { return default_surface_zdata (); } static Matrix -default_patch_faces (void) +default_patch_faces () { Matrix m (1, 3); @@ -400,7 +399,7 @@ } static Matrix -default_patch_vertices (void) +default_patch_vertices () { Matrix m (3, 2, 0.0); @@ -412,7 +411,7 @@ } static Matrix -default_patch_xdata (void) +default_patch_xdata () { Matrix m (3, 1, 0.0); @@ -422,7 +421,7 @@ } static Matrix -default_patch_ydata (void) +default_patch_ydata () { Matrix m (3, 1, 1.0); @@ -432,7 +431,7 @@ } static Matrix -default_axes_position (void) +default_axes_position () { Matrix m (1, 4); @@ -445,7 +444,7 @@ } static Matrix -default_axes_outerposition (void) +default_axes_outerposition () { Matrix m (1, 4); @@ -458,7 +457,7 @@ } static Matrix -default_axes_view (void) +default_axes_view () { Matrix m (1, 2); @@ -469,7 +468,7 @@ } static Matrix -default_axes_tick (void) +default_axes_tick () { Matrix m (1, 6); @@ -484,7 +483,7 @@ } static Matrix -default_axes_ticklength (void) +default_axes_ticklength () { Matrix m (1, 2); @@ -495,7 +494,7 @@ } static Matrix -default_figure_position (void) +default_figure_position () { Matrix m (1, 4); @@ -508,7 +507,7 @@ } static Matrix -default_figure_papersize (void) +default_figure_papersize () { Matrix m (1, 2); @@ -519,7 +518,7 @@ } static Matrix -default_figure_paperposition (void) +default_figure_paperposition () { Matrix m (1, 4); @@ -533,7 +532,7 @@ } static std::string -default_graphics_toolkit (void) +default_graphics_toolkit () { octave::gtk_manager& gtk_mgr = octave::__get_gtk_manager__ (); @@ -541,7 +540,7 @@ } static Matrix -default_control_position (void) +default_control_position () { Matrix retval (1, 4); @@ -554,7 +553,7 @@ } static Matrix -default_control_sliderstep (void) +default_control_sliderstep () { Matrix retval (1, 2); @@ -565,7 +564,7 @@ } static Matrix -default_panel_position (void) +default_panel_position () { Matrix retval (1, 4); @@ -578,7 +577,7 @@ } static Matrix -default_light_position (void) +default_light_position () { Matrix m (1, 3); @@ -590,7 +589,7 @@ } static Matrix -default_table_position (void) +default_table_position () { Matrix retval (1, 4); @@ -603,7 +602,7 @@ } static Matrix -default_table_backgroundcolor (void) +default_table_backgroundcolor () { Matrix retval (2, 3); retval(0, 0) = 1; @@ -922,7 +921,7 @@ // This function always returns the screensize in pixels static Matrix -screen_size_pixels (void) +screen_size_pixels () { gh_manager& gh_mgr = octave::__get_gh_manager__ (); @@ -1202,10 +1201,10 @@ return result; } -static base_graphics_object * +base_graphics_object * make_graphics_object_from_type (const caseless_str& type, - const graphics_handle& h = graphics_handle (), - const graphics_handle& p = graphics_handle ()) + const graphics_handle& h, + const graphics_handle& p) { base_graphics_object *go = nullptr; @@ -1330,7 +1329,7 @@ } std::string -radio_values::values_as_string (void) const +radio_values::values_as_string () const { std::string retval; @@ -1359,7 +1358,7 @@ } Cell -radio_values::values_as_cell (void) const +radio_values::values_as_cell () const { octave_idx_type i = 0; Cell retval (nelem (), 1); @@ -1725,7 +1724,7 @@ } void -array_property::get_data_limits (void) +array_property::get_data_limits () { m_min_val = m_min_pos = octave::numeric_limits::Inf (); m_max_val = m_max_neg = -octave::numeric_limits::Inf (); @@ -1937,15 +1936,13 @@ { public: - callback_props (void) : m_set () { } - - callback_props (const callback_props&) = delete; - - callback_props& operator = (const callback_props&) = delete; - - ~callback_props (void) = default; - - bool empty (void) const { return m_set.empty (); } + callback_props () : m_set () { } + + OCTAVE_DISABLE_COPY_MOVE (callback_props) + + ~callback_props () = default; + + bool empty () const { return m_set.empty (); } void insert (const callback_property *ptr) { @@ -2023,8 +2020,7 @@ if (args.length () < 1) error ("addproperty: missing possible values for radio property"); - std::string sv = args( - 0).xstring_value ("addproperty: argument for radio property must be a string"); + std::string sv = args(0).xstring_value ("addproperty: argument for radio property must be a string"); retval = property (new radio_property (name, h, sv)); @@ -2235,7 +2231,7 @@ } void -figure::properties::update_handlevisibility (void) +figure::properties::update_handlevisibility () { if (! is_handle_visible ()) { @@ -2294,7 +2290,7 @@ } void -figure::properties::update___device_pixel_ratio__ (void) +figure::properties::update___device_pixel_ratio__ () { update_text_pos (get___myhandle__ ()); } @@ -2544,18 +2540,18 @@ { octave_scalar_map m; - for (auto p = begin (); p != end (); p++) - { - std::string prefix = prefix_arg + p->first; - - for (const auto& prop_val : p->second) + for (const auto& p : *this) + { + std::string prefix = prefix_arg + p.first; + + for (const auto& prop_val : p.second) m.assign (prefix + prop_val.first, prop_val.second); } return m; } -// Set properties given as a cs-list of name, value pairs. +// Set property given as either cs-list of name/value pairs or a struct. void graphics_object::set (const octave_value_list& args) @@ -2567,7 +2563,7 @@ for (int i = 0; i < nargin; ) { - if (args(i).isstruct () ) + if (args(i).isstruct ()) { set (args(i).map_value ()); i++; @@ -2681,41 +2677,6 @@ } /* -## test set ticklabels for compatibility -%!test -%! hf = figure ("visible", "off"); -%! set (gca (), "xticklabel", [0, 0.2, 0.4, 0.6, 0.8, 1]); -%! xticklabel = get (gca (), "xticklabel"); -%! close (hf); -%! assert (class (xticklabel), "char"); -%! assert (size (xticklabel), [6, 3]); - -%!test -%! hf = figure ("visible", "off"); -%! set (gca (), "xticklabel", "0|0.2|0.4|0.6|0.8|1"); -%! xticklabel = get (gca (), "xticklabel"); -%! close (hf); -%! assert (class (xticklabel), "char"); -%! assert (size (xticklabel), [6, 3]); - -%!test -%! hf = figure ("visible", "off"); -%! set (gca (), "xticklabel", ["0 "; "0.2"; "0.4"; "0.6"; "0.8"; "1 "]); -%! xticklabel = get (gca (), "xticklabel"); -%! close (hf); -%! assert (class (xticklabel), "char"); -%! assert (size (xticklabel), [6, 3]); - -%!test -%! hf = figure ("visible", "off"); -%! set (gca (), "xticklabel", {"0", "0.2", "0.4", "0.6", "0.8", "1"}); -%! xticklabel = get (gca (), "xticklabel"); -%! close (hf); -%! assert (class (xticklabel), "cell"); -%! assert (size (xticklabel), [6, 1]); -*/ - -/* ## test set with struct arguments %!test %! hf = figure ("visible", "off"); @@ -2818,226 +2779,9 @@ %! end_unwind_protect */ -static double -make_handle_fraction (void) -{ - static double maxrand = RAND_MAX + 2.0; - - return (rand () + 1.0) / maxrand; -} - -graphics_handle -gh_manager::get_handle (bool integer_figure_handle) -{ - graphics_handle retval; - - if (integer_figure_handle) - { - // Figure handles are positive integers corresponding - // to the figure number. - - // We always want the lowest unused figure number. - - retval = 1; - - while (m_handle_map.find (retval) != m_handle_map.end ()) - retval++; - } - else - { - // Other graphics handles are negative integers plus some random - // fractional part. To avoid running out of integers, we recycle the - // integer part but tack on a new random part each time. - - auto p = m_handle_free_list.begin (); - - if (p != m_handle_free_list.end ()) - { - retval = *p; - m_handle_free_list.erase (p); - } - else - { - retval = graphics_handle (m_next_handle); - - m_next_handle = std::ceil (m_next_handle) - 1.0 - make_handle_fraction (); - } - } - - return retval; -} - -static bool -isfigure (double val) -{ - gh_manager& gh_mgr = octave::__get_gh_manager__ (); - - graphics_object go = gh_mgr.get_object (val); - - return go && go.isa ("figure"); -} - -void -gh_manager::free (const graphics_handle& h, bool from_root) -{ - if (h.ok ()) - { - if (h.value () == 0) - error ("graphics_handle::free: can't delete root object"); - - auto p = m_handle_map.find (h); - - if (p == m_handle_map.end ()) - error ("graphics_handle::free: invalid object %g", h.value ()); - - base_properties& bp = p->second.get_properties (); - - if (! p->second.valid_object () || bp.is_beingdeleted ()) - return; - - graphics_handle parent_h = p->second.get_parent (); - graphics_object parent_go = nullptr; - if (! from_root || isfigure (h.value ())) - parent_go = get_object (parent_h); - - bp.set_beingdeleted (true); - - // delete listeners before invalidating object - p->second.remove_all_listeners (); - - bp.delete_children (true, from_root); - - // NOTE: Call the delete function while the object's state is still valid. - octave_value val = bp.get_deletefcn (); - - bp.execute_deletefcn (); - - // Notify graphics toolkit. - p->second.finalize (); - - - // NOTE: Call remove_child before erasing the go from the map if not - // removing from groot. - // A callback function might have already deleted the parent - if ((! from_root || isfigure (h.value ())) && parent_go.valid_object () - && h.ok ()) - parent_go.remove_child (h); - - // Note: this will be valid only for first explicitly deleted - // object. All its children will then have an - // unknown graphics toolkit. - - // Graphics handles for non-figure objects are negative - // integers plus some random fractional part. To avoid - // running out of integers, we recycle the integer part - // but tack on a new random part each time. - - m_handle_map.erase (p); - - if (h.value () < 0) - m_handle_free_list.insert - (std::ceil (h.value ()) - make_handle_fraction ()); - } -} - -void -gh_manager::renumber_figure (const graphics_handle& old_gh, - const graphics_handle& new_gh) -{ - auto p = m_handle_map.find (old_gh); - - if (p == m_handle_map.end ()) - error ("graphics_handle::free: invalid object %g", old_gh.value ()); - - graphics_object go = p->second; - - m_handle_map.erase (p); - - m_handle_map[new_gh] = go; - - if (old_gh.value () < 0) - m_handle_free_list.insert (std::ceil (old_gh.value ()) - - make_handle_fraction ()); - - for (auto& hfig : m_figure_list) - { - if (hfig == old_gh) - { - hfig = new_gh; - break; - } - } -} - -static void -xset (const graphics_handle& h, const caseless_str& pname, - const octave_value& val) -{ - gh_manager& gh_mgr = octave::__get_gh_manager__ (); - - graphics_object go = gh_mgr.get_object (h); - - go.set (pname, val); -} - -static void -xset (const graphics_handle& h, const octave_value_list& args) -{ - if (args.length () > 0) - { - gh_manager& gh_mgr = octave::__get_gh_manager__ (); - - graphics_object go = gh_mgr.get_object (h); - - go.set (args); - } -} - -static octave_value -xget (const graphics_handle& h, const caseless_str& pname) -{ - gh_manager& gh_mgr = octave::__get_gh_manager__ (); - - graphics_object go = gh_mgr.get_object (h); - - return go.get (pname); -} - -static graphics_handle -reparent (const octave_value& ov, const std::string& who, - const std::string& pname, const graphics_handle& new_parent, - bool adopt = true) -{ - double hv = ov.xdouble_value ("%s: %s must be a graphics handle", - who.c_str (), pname.c_str ()); - - gh_manager& gh_mgr = octave::__get_gh_manager__ (); - - graphics_handle h = gh_mgr.lookup (hv); - - if (! h.ok ()) - error ("%s: invalid graphics handle (= %g) for %s", - who.c_str (), hv, pname.c_str ()); - - graphics_object go = gh_mgr.get_object (h); - - graphics_handle parent_h = go.get_parent (); - - graphics_object parent_go = gh_mgr.get_object (parent_h); - - parent_go.remove_child (h); - - if (adopt) - go.set ("parent", new_parent.value ()); - else - go.reparent (new_parent); - - return h; -} - // This function is NOT equivalent to the scripting language function gcf. graphics_handle -gcf (void) +gcf () { octave_value val = xget (0, "currentfigure"); @@ -3047,7 +2791,7 @@ // This function is NOT equivalent to the scripting language function gca. graphics_handle -gca (void) +gca () { octave_value val = xget (gcf (), "currentaxes"); @@ -3056,115 +2800,6 @@ } static void -delete_graphics_object (const graphics_handle& h, bool from_root = false) -{ - if (h.ok ()) - { - gh_manager& gh_mgr = octave::__get_gh_manager__ (); - - graphics_object go = gh_mgr.get_object (h); - - // Don't do recursive deleting, due to callbacks - if (! go.get_properties ().is_beingdeleted ()) - { - // NOTE: Freeing the handle also calls any deletefcn. It also calls - // the parent's delete_child function. - - gh_mgr.free (h, from_root || go.isa ("figure")); - - Vdrawnow_requested = true; - } - } -} - -static void -delete_graphics_object (double val, bool from_root = false) -{ - gh_manager& gh_mgr = octave::__get_gh_manager__ (); - - delete_graphics_object (gh_mgr.lookup (val), from_root || isfigure (val)); -} - -// Flag to stop redraws due to callbacks while deletion is in progress. -static bool delete_executing = false; - -static void -delete_graphics_objects (const NDArray vals, bool from_root = false) -{ - // Prevent redraw of partially deleted objects. - octave::unwind_protect_var restore_var (delete_executing, true); - - for (octave_idx_type i = 0; i < vals.numel (); i++) - delete_graphics_object (vals.elem (i), from_root); -} - -static void -close_figure (const graphics_handle& h) -{ - octave_value closerequestfcn = xget (h, "closerequestfcn"); - - gh_manager& gh_mgr = octave::__get_gh_manager__ (); - - gh_mgr.execute_callback (h, closerequestfcn); -} - -static void -force_close_figure (const graphics_handle& h) -{ - // Remove the deletefcn and closerequestfcn callbacks - // and delete the object directly. - - xset (h, "deletefcn", Matrix ()); - xset (h, "closerequestfcn", Matrix ()); - - delete_graphics_object (h, true); -} - -void -gh_manager::close_all_figures (void) -{ - // FIXME: should we process or discard pending events? - - m_event_queue.clear (); - - // Don't use m_figure_list_iterator because we'll be removing elements - // from the list elsewhere. - - Matrix hlist = figure_handle_list (true); - - for (octave_idx_type i = 0; i < hlist.numel (); i++) - { - graphics_handle h = lookup (hlist(i)); - - if (h.ok ()) - close_figure (h); - } - - // They should all be closed now. If not, force them to close. - - hlist = figure_handle_list (true); - - for (octave_idx_type i = 0; i < hlist.numel (); i++) - { - graphics_handle h = lookup (hlist(i)); - - if (h.ok ()) - force_close_figure (h); - } - - // None left now, right? - - hlist = figure_handle_list (true); - - if (hlist.numel () != 0) - warning ("gh_manager::close_all_figures: some graphics elements failed to close"); - - // Clear all callback objects from our list. - - m_callback_objects.clear (); -} - -static void adopt (const graphics_handle& parent_h, const graphics_handle& h) { gh_manager& gh_mgr = octave::__get_gh_manager__ (); @@ -3360,16 +2995,15 @@ { octave_scalar_map m; - for (std::map::const_iterator - it = m_all_props.begin (); it != m_all_props.end (); ++it) - if (all || ! it->second.is_hidden ()) - m.assign (it->second.get_name (), it->second.get ()); + for (const auto& it : m_all_props) + if (all || ! it.second.is_hidden ()) + m.assign (it.second.get_name (), it.second.get ()); return m; } std::set -base_properties::dynamic_property_names (void) const +base_properties::dynamic_property_names () const { return m_dynamic_properties; } @@ -3462,7 +3096,7 @@ */ void -base_properties::mark_modified (void) +base_properties::mark_modified () { // Mark existing object as modified m___modified__ = "on"; @@ -3512,7 +3146,7 @@ } void -base_properties::update_contextmenu (void) const +base_properties::update_contextmenu () const { if (m_contextmenu.get ().isempty ()) return; @@ -3530,14 +3164,14 @@ } bool -base_properties::is_handle_visible (void) const +base_properties::is_handle_visible () const { return (m_handlevisibility.is ("on") || (! executing_callbacks.empty () && ! m_handlevisibility.is ("off"))); } octave::graphics_toolkit -base_properties::get_toolkit (void) const +base_properties::get_toolkit () const { gh_manager& gh_mgr = octave::__get_gh_manager__ (); @@ -3550,7 +3184,7 @@ } void -base_properties::update_boundingbox (void) +base_properties::update_boundingbox () { Matrix kids = get_children (); @@ -3577,7 +3211,7 @@ } void -base_properties::update_handlevisibility (void) +base_properties::update_handlevisibility () { if (is_handle_visible ()) return; @@ -3726,7 +3360,7 @@ } void -base_graphics_object::remove_all_listeners (void) +base_graphics_object::remove_all_listeners () { int state = toggle_warn ("Octave:deprecated-property", false); octave_map m = get (true).map_value (); @@ -3785,7 +3419,7 @@ } void -base_graphics_object::reset_default_properties (void) +base_graphics_object::reset_default_properties () { if (valid_object ()) { @@ -3800,7 +3434,7 @@ } std::string -base_graphics_object::values_as_string (void) +base_graphics_object::values_as_string () { if (! valid_object ()) error ("base_graphics_object::values_as_string: invalid graphics object"); @@ -3864,7 +3498,7 @@ } octave_scalar_map -base_graphics_object::values_as_struct (void) +base_graphics_object::values_as_struct () { octave_scalar_map retval; @@ -4020,7 +3654,7 @@ // FIXME: This should update monitorpositions and pointerlocation, but as these // properties aren't yet used, it doesn't matter that they aren't set either. void -root_figure::properties::update_units (void) +root_figure::properties::update_units () { std::string xunits = get_units (); @@ -4125,7 +3759,7 @@ } void -root_figure::reset_default_properties (void) +root_figure::reset_default_properties () { // empty list of local defaults m_default_properties = property_list (); @@ -4179,7 +3813,7 @@ } octave_value -figure::properties::get_number (void) const +figure::properties::get_number () const { if (m_integerhandle.is_on ()) return m___myhandle__.value (); @@ -4188,7 +3822,7 @@ } octave::graphics_toolkit -figure::properties::get_toolkit (void) const +figure::properties::get_toolkit () const { return m_toolkit; } @@ -4572,7 +4206,7 @@ } Matrix -figure::properties::get_auto_paperposition (void) +figure::properties::get_auto_paperposition () { Matrix pos = get_position ().matrix_value (); Matrix sz; @@ -4742,7 +4376,7 @@ } void -figure::properties::update_papertype (void) +figure::properties::update_papertype () { std::string typ = get_papertype (); if (typ != "") @@ -4760,7 +4394,7 @@ } void -figure::properties::update_papersize (void) +figure::properties::update_papersize () { Matrix sz = get_papersize ().matrix_value (); if (sz(0) > sz(1)) @@ -4928,7 +4562,7 @@ */ void -figure::properties::update_paperorientation (void) +figure::properties::update_paperorientation () { std::string porient = get_paperorientation (); Matrix sz = get_papersize ().matrix_value (); @@ -5011,7 +4645,7 @@ */ std::string -figure::properties::get_title (void) const +figure::properties::get_title () const { std::string title; if (! get_number ().isempty () && is_numbertitle ()) @@ -5056,7 +4690,7 @@ } void -figure::reset_default_properties (void) +figure::reset_default_properties () { // empty list of local defaults m_default_properties = property_list (); @@ -5076,7 +4710,7 @@ // --------------------------------------------------------------------- void -axes::properties::init (void) +axes::properties::init () { m_position.add_constraint (dim_vector (1, 4)); m_outerposition.add_constraint (dim_vector (1, 4)); @@ -5274,7 +4908,7 @@ } void -axes::properties::sync_positions (void) +axes::properties::sync_positions () { // First part is equivalent to 'update_tightinset ()' if (m_positionconstraint.is ("innerposition")) @@ -5666,7 +5300,7 @@ } octave_value -axes::properties::get_colormap (void) const +axes::properties::get_colormap () const { if (m___colormap__.get ().isempty ()) { @@ -5783,7 +5417,7 @@ } inline Matrix -xform_matrix (void) +xform_matrix () { Matrix m (4, 4, 0.0); @@ -5794,7 +5428,7 @@ } inline ColumnVector -xform_vector (void) +xform_vector () { ColumnVector v (4, 0.0); @@ -5913,7 +5547,7 @@ } inline Matrix -unit_cube (void) +unit_cube () { static double data[32] = { @@ -5950,7 +5584,7 @@ } void -axes::properties::update_camera (void) +axes::properties::update_camera () { double xd = (xdir_is ("normal") ? 1 : -1); double yd = (ydir_is ("normal") ? 1 : -1); @@ -6166,7 +5800,7 @@ static bool updating_axes_layout = false; void -axes::properties::update_axes_layout (void) +axes::properties::update_axes_layout () { if (updating_axes_layout) return; @@ -6329,7 +5963,7 @@ } void -axes::properties::update_ticklength (void) +axes::properties::update_ticklength () { bool mode2D = (((m_xstate > AXE_DEPTH_DIR ? 1 : 0) + (m_ystate > AXE_DEPTH_DIR ? 1 : 0) + @@ -6416,7 +6050,7 @@ static bool updating_xlabel_position = false; void -axes::properties::update_xlabel_position (void) +axes::properties::update_xlabel_position () { if (updating_xlabel_position) return; @@ -6520,7 +6154,7 @@ static bool updating_ylabel_position = false; void -axes::properties::update_ylabel_position (void) +axes::properties::update_ylabel_position () { if (updating_ylabel_position) return; @@ -6624,7 +6258,7 @@ static bool updating_zlabel_position = false; void -axes::properties::update_zlabel_position (void) +axes::properties::update_zlabel_position () { if (updating_zlabel_position) return; @@ -6750,7 +6384,7 @@ static bool updating_title_position = false; void -axes::properties::update_title_position (void) +axes::properties::update_title_position () { if (updating_title_position) return; @@ -6851,7 +6485,7 @@ static std::set updating_aspectratios; void -axes::properties::update_aspectratios (void) +axes::properties::update_aspectratios () { if (updating_aspectratios.find (get___myhandle__ ().value ()) != updating_aspectratios.end ()) @@ -7360,7 +6994,7 @@ } Matrix -graphics_xform::xform_eye (void) +graphics_xform::xform_eye () { return octave::xform_matrix (); } @@ -7491,7 +7125,7 @@ } void -axes::properties::update_outerposition (void) +axes::properties::update_outerposition () { set_positionconstraint ("outerposition"); caseless_str old_units = get_units (); @@ -7550,7 +7184,7 @@ } void -axes::properties::update_position (void) +axes::properties::update_position () { set_positionconstraint ("innerposition"); caseless_str old_units = get_units (); @@ -7598,7 +7232,7 @@ } void -axes::properties::update_looseinset (void) +axes::properties::update_looseinset () { caseless_str old_units = get_units (); set_units ("normalized"); @@ -8275,7 +7909,7 @@ { Matrix values = ticks.get ().matrix_value (); Matrix lims = axis_lims.get ().matrix_value (); - Cell c (values.dims ()); + Cell c (dim_vector (values.numel (), 1)); // column vector for ML compat. std::ostringstream os; // omit tick labels depending on location of other axis @@ -9050,7 +8684,7 @@ } void -axes::properties::push_zoom_stack (void) +axes::properties::push_zoom_stack () { if (m_zoom_stack.empty ()) { @@ -9276,7 +8910,7 @@ } void -axes::properties::unzoom (void) +axes::properties::unzoom () { if (m_zoom_stack.size () >= 7) { @@ -9312,7 +8946,7 @@ } void -axes::properties::update_handlevisibility (void) +axes::properties::update_handlevisibility () { if (! is_handle_visible ()) { @@ -9341,7 +8975,7 @@ } void -figure::properties::init_toolkit (void) +figure::properties::init_toolkit () { octave::gtk_manager& gtk_mgr = octave::__get_gtk_manager__ (); @@ -9361,7 +8995,7 @@ } void -axes::properties::trigger_normals_calc (void) +axes::properties::trigger_normals_calc () { // Find all patch (and surface) objects within axes std::list children_list; @@ -9390,7 +9024,7 @@ } void -axes::reset_default_properties (void) +axes::reset_default_properties () { // empty list of local defaults m_default_properties = property_list (); @@ -9421,7 +9055,7 @@ // --------------------------------------------------------------------- Matrix -line::properties::compute_xlim (void) const +line::properties::compute_xlim () const { Matrix m (1, 4); @@ -9434,7 +9068,7 @@ } Matrix -line::properties::compute_ylim (void) const +line::properties::compute_ylim () const { Matrix m (1, 4); @@ -9449,7 +9083,7 @@ // --------------------------------------------------------------------- Matrix -text::properties::get_data_position (void) const +text::properties::get_data_position () const { Matrix pos = get_position ().matrix_value (); @@ -9504,7 +9138,7 @@ } octave_value -text::properties::get_extent (void) const +text::properties::get_extent () const { // FIXME: This doesn't work right for 3D plots. // (It doesn't in Matlab either, at least not in version 6.5.) @@ -9561,7 +9195,7 @@ } void -text::properties::update_font (void) +text::properties::update_font () { double dpr = device_pixel_ratio (get___myhandle__ ()); @@ -9583,7 +9217,7 @@ } void -text::properties::update_text_extent (void) +text::properties::update_text_extent () { int halign = 0; int valign = 0; @@ -9628,7 +9262,7 @@ } void -text::properties::request_autopos (void) +text::properties::request_autopos () { if (__autopos_tag___is ("xlabel") || __autopos_tag___is ("ylabel") || __autopos_tag___is ("zlabel") || __autopos_tag___is ("title")) @@ -9636,7 +9270,7 @@ } void -text::properties::update_units (void) +text::properties::update_units () { if (! units_is ("data")) { @@ -9693,7 +9327,7 @@ // --------------------------------------------------------------------- octave_value -image::properties::get_color_data (void) const +image::properties::get_color_data () const { return convert_cdata (*this, get_cdata (), cdatamapping_is ("scaled"), 3); } @@ -9712,7 +9346,7 @@ } void -light::properties::update_visible (void) +light::properties::update_visible () { gh_manager& gh_mgr = octave::__get_gh_manager__ (); @@ -9729,7 +9363,7 @@ // --------------------------------------------------------------------- bool -patch::properties::get_do_lighting (void) const +patch::properties::get_do_lighting () const { gh_manager& gh_mgr = octave::__get_gh_manager__ (); @@ -9742,7 +9376,7 @@ } octave_value -patch::properties::get_color_data (void) const +patch::properties::get_color_data () const { octave_value fvc = get_facevertexcdata (); if (fvc.is_undefined () || fvc.isempty ()) @@ -9754,7 +9388,7 @@ static bool updating_patch_data = false; void -patch::properties::update_fvc (void) +patch::properties::update_fvc () { if (updating_patch_data) return; @@ -9933,7 +9567,7 @@ } void -patch::properties::update_data (void) +patch::properties::update_data () { if (updating_patch_data) return; @@ -10314,7 +9948,7 @@ void -patch::reset_default_properties (void) +patch::reset_default_properties () { // empty list of local defaults m_default_properties = property_list (); @@ -10329,7 +9963,7 @@ // --------------------------------------------------------------------- octave_value -scatter::properties::get_color_data (void) const +scatter::properties::get_color_data () const { octave_value c = get_cdata (); if (c.is_undefined () || c.isempty ()) @@ -10339,7 +9973,7 @@ } void -scatter::properties::update_data (void) +scatter::properties::update_data () { Matrix xd = get_xdata ().matrix_value (); Matrix yd = get_ydata ().matrix_value (); @@ -10379,7 +10013,7 @@ static bool updating_scatter_cdata = false; void -scatter::properties::update_color (void) +scatter::properties::update_color () { if (updating_scatter_cdata) return; @@ -10442,13 +10076,13 @@ // --------------------------------------------------------------------- octave_value -surface::properties::get_color_data (void) const +surface::properties::get_color_data () const { return convert_cdata (*this, get_cdata (), cdatamapping_is ("scaled"), 3); } bool -surface::properties::get_do_lighting (void) const +surface::properties::get_do_lighting () const { gh_manager& gh_mgr = octave::__get_gh_manager__ (); @@ -10774,7 +10408,7 @@ } void -hggroup::properties::update_limits (void) const +hggroup::properties::update_limits () const { gh_manager& gh_mgr = octave::__get_gh_manager__ (); @@ -11008,7 +10642,7 @@ // --------------------------------------------------------------------- void -uicontextmenu::properties::update_beingdeleted (void) +uicontextmenu::properties::update_beingdeleted () { // Clear the uicontextmenu property of dependent objects if (m_beingdeleted.is ("on")) @@ -11058,7 +10692,7 @@ // --------------------------------------------------------------------- octave_value -uicontrol::properties::get_extent (void) const +uicontrol::properties::get_extent () const { Matrix m = m_extent.get ().matrix_value (); @@ -11073,7 +10707,7 @@ } void -uicontrol::properties::update_text_extent (void) +uicontrol::properties::update_text_extent () { // FIXME: support multiline text @@ -11085,7 +10719,7 @@ } void -uicontrol::properties::update_units (void) +uicontrol::properties::update_units () { Matrix pos = get_position ().matrix_value (); @@ -11823,14 +11457,14 @@ } Matrix -uitable::properties::get_backgroundcolor_rgb (void) +uitable::properties::get_backgroundcolor_rgb () { Matrix bg = m_backgroundcolor.get ().matrix_value (); return bg.row (0); } Matrix -uitable::properties::get_alternatebackgroundcolor_rgb (void) +uitable::properties::get_alternatebackgroundcolor_rgb () { int i = 0; Matrix bg = m_backgroundcolor.get ().matrix_value (); @@ -11841,13 +11475,13 @@ } Matrix -uitable::properties::get_extent_matrix (void) const +uitable::properties::get_extent_matrix () const { return m_extent.get ().matrix_value (); } octave_value -uitable::properties::get_extent (void) const +uitable::properties::get_extent () const { // FIXME: Is it really acceptable to just let the toolkit update the extent? Matrix m = m_extent.get ().matrix_value (); @@ -11889,7 +11523,7 @@ } void -uitoolbar::reset_default_properties (void) +uitoolbar::reset_default_properties () { // empty list of local defaults m_default_properties = property_list (); @@ -11922,118 +11556,6 @@ return parent_go.get_factory_default (type () + name); } -// We use a random value for the handle to avoid issues with plots and -// scalar values for the first argument. -gh_manager::gh_manager (octave::interpreter& interp) - : m_interpreter (interp), m_handle_map (), m_handle_free_list (), - m_next_handle (-1.0 - (rand () + 1.0) / (RAND_MAX + 2.0)), - m_figure_list (), m_graphics_lock (), m_event_queue (), - m_callback_objects (), m_event_processing (0) -{ - m_handle_map[0] = graphics_object (new root_figure ()); - - octave::gtk_manager& gtk_mgr = octave::__get_gtk_manager__ (); - - // Make sure the default graphics toolkit is registered. - gtk_mgr.default_toolkit (); -} - -graphics_handle -gh_manager::make_graphics_handle (const std::string& go_name, - const graphics_handle& p, - bool integer_figure_handle, - bool call_createfcn, bool notify_toolkit) -{ - graphics_handle h = get_handle (integer_figure_handle); - - base_graphics_object *bgo = make_graphics_object_from_type (go_name, h, p); - - if (! bgo) - error ("gh_manager::make_graphics_handle: invalid object type '%s'", - go_name.c_str ()); - - graphics_object go (bgo); - - m_handle_map[h] = go; - - if (go_name == "axes") - { - // Handle defaults for labels since overriding defaults for - // them can't work before the axes object is fully - // constructed. - - axes::properties& props - = dynamic_cast (go.get_properties ()); - - graphics_object tgo; - - tgo = get_object (props.get_xlabel ()); - tgo.override_defaults (); - - tgo = get_object (props.get_ylabel ()); - tgo.override_defaults (); - - tgo = get_object (props.get_zlabel ()); - tgo.override_defaults (); - - tgo = get_object (props.get_title ()); - tgo.override_defaults (); - } - - // Overriding defaults will work now because the handle is valid - // and we can find parent objects (not just handles). - go.override_defaults (); - - if (call_createfcn) - bgo->get_properties ().execute_createfcn (); - - // Notify graphics toolkit. - if (notify_toolkit) - go.initialize (); - - return h; -} - -graphics_handle -gh_manager::make_figure_handle (double val, bool notify_toolkit) -{ - graphics_handle h = val; - - base_graphics_object *bgo = new figure (h, 0); - graphics_object go (bgo); - - m_handle_map[h] = go; - - // Notify graphics toolkit. - if (notify_toolkit) - go.initialize (); - - go.override_defaults (); - - return h; -} - -void -gh_manager::push_figure (const graphics_handle& h) -{ - pop_figure (h); - - m_figure_list.push_front (h); -} - -void -gh_manager::pop_figure (const graphics_handle& h) -{ - for (auto it = m_figure_list.begin (); it != m_figure_list.end (); it++) - { - if (*it == h) - { - m_figure_list.erase (it); - break; - } - } -} - class callback_event : public base_graphics_event { @@ -12050,7 +11572,11 @@ : base_graphics_event (busyaction), m_handle (h), m_callback_name (), m_callback (cb), m_callback_data (data) { } - void execute (void) + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (callback_event) + + ~callback_event () = default; + + void execute () { gh_manager& gh_mgr = octave::__get_gh_manager__ (); @@ -12061,12 +11587,6 @@ } private: - callback_event (void) - : base_graphics_event (), m_handle (), m_callback_name (), - m_callback_data () - { } - -private: graphics_handle m_handle; std::string m_callback_name; octave_value m_callback; @@ -12082,7 +11602,11 @@ : base_graphics_event (busyaction), m_handle (h), m_mcode (cmd) { } - void execute (void) + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (mcode_event) + + ~mcode_event () = default; + + void execute () { if (! m_mcode.empty ()) { @@ -12099,11 +11623,6 @@ } private: - mcode_event (void) - : base_graphics_event (), m_handle (), m_mcode () - { } - -private: graphics_handle m_handle; std::string m_mcode; }; @@ -12113,21 +11632,15 @@ { public: - // function_event objects must be created with at least a function. - - function_event (void) = delete; - function_event (graphics_event::event_fcn fcn, void *data = nullptr) : base_graphics_event (), m_function (fcn), m_function_data (data) { } - // No copying! - - function_event (const function_event&) = delete; - - function_event& operator = (const function_event&) = delete; - - void execute (void) + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (function_event) + + ~function_event () = default; + + void execute () { m_function (m_function_data); } @@ -12151,7 +11664,11 @@ m_redraw_figure (redraw_figure) { } - void execute (void) + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (set_event) + + ~set_event () = default; + + void execute () { gh_manager& gh_mgr = octave::__get_gh_manager__ (); @@ -12203,11 +11720,6 @@ } private: - set_event (void) - : base_graphics_event (), m_handle (), m_property_name (), m_property_value () - { } - -private: graphics_handle m_handle; std::string m_property_name; octave_value m_property_value; @@ -12258,375 +11770,8 @@ redraw_figure)); } -static void -xset_gcbo (const graphics_handle& h) -{ - gh_manager& gh_mgr = octave::__get_gh_manager__ (); - - graphics_object go = gh_mgr.get_object (0); - - root_figure::properties& props - = dynamic_cast (go.get_properties ()); - - props.set_callbackobject (h.as_octave_value ()); -} - -void -gh_manager::restore_gcbo (void) -{ - octave::autolock guard (m_graphics_lock); - - m_callback_objects.pop_front (); - - xset_gcbo (m_callback_objects.empty () - ? graphics_handle () : m_callback_objects.front ().get_handle ()); -} - -void -gh_manager::execute_listener (const graphics_handle& h, const octave_value& l) -{ - if (octave::thread::is_thread ()) - execute_callback (h, l, octave_value ()); - else - { - octave::autolock guard (m_graphics_lock); - - post_event (graphics_event::create_callback_event (h, l)); - } -} - -void -gh_manager::execute_callback (const graphics_handle& h, - const octave_value& cb_arg, - const octave_value& data) -{ - if (cb_arg.is_defined () && ! cb_arg.isempty ()) - { - octave_value_list args; - octave_value ov_fcn; - octave_function *fcn = nullptr; - - args(0) = h.as_octave_value (); - if (data.is_defined ()) - args(1) = data; - else - args(1) = Matrix (); - - octave::unwind_action_safe restore_gcbo_action - (&gh_manager::restore_gcbo, this); - - graphics_object go (get_object (h)); - if (go) - { - // FIXME: Is the lock necessary when we're only calling a - // const "get" method? - octave::autolock guard (m_graphics_lock); - m_callback_objects.push_front (go); - xset_gcbo (h); - } - - // Copy CB because "function_value" method is non-const. - octave_value cb = cb_arg; - - if (cb.is_function ()) - fcn = cb.function_value (); - else if (cb.is_function_handle ()) - ov_fcn = cb; - else if (cb.is_string ()) - { - int status; - std::string s = cb.string_value (); - - try - { - m_interpreter.eval_string (s, false, status, 0); - } - catch (const octave::execution_exception& ee) - { - m_interpreter.handle_exception (ee); - } - } - else if (cb.iscell () && cb.length () > 0 - && (cb.rows () == 1 || cb.columns () == 1) - && (cb.cell_value ()(0).is_function () - || cb.cell_value ()(0).is_function_handle ())) - { - Cell c = cb.cell_value (); - - ov_fcn = c(0); - - for (int i = 1; i < c.numel () ; i++) - args(1+i) = c(i); - } - else - { - std::string nm = cb.class_name (); - error ("trying to execute non-executable object (class = %s)", - nm.c_str ()); - } - - if (fcn || ov_fcn.is_defined ()) - try - { - if (ov_fcn.is_defined ()) - octave::feval (ov_fcn, args); - else - octave::feval (fcn, args); - } - catch (const octave::execution_exception& ee) - { - m_interpreter.handle_exception (ee); - } - - // Redraw after interacting with a user-interface (ui*) object. - if (Vdrawnow_requested) - { - if (go) - { - std::string go_name - = go.get_properties ().graphics_object_name (); - - if (go_name.length () > 1 - && go_name[0] == 'u' && go_name[1] == 'i') - { - Fdrawnow (m_interpreter); - Vdrawnow_requested = false; - } - } - } - } -} - -static int -process_graphics_events (void) -{ - gh_manager& gh_mgr = octave::__get_gh_manager__ (); - - return gh_mgr.process_events (); -} - -void -gh_manager::post_event (const graphics_event& e) -{ - m_event_queue.push_back (e); - - octave::command_editor::add_event_hook (process_graphics_events); -} - -void -gh_manager::post_callback (const graphics_handle& h, const std::string& name, - const octave_value& data) -{ - octave::autolock guard (m_graphics_lock); - - graphics_object go = get_object (h); - - if (go.valid_object ()) - { - caseless_str cname (name); - int busyaction = base_graphics_event::QUEUE; - - if (cname == "deletefcn" || cname == "createfcn" - || cname == "closerequestfcn" - || ((go.isa ("figure") || go.isa ("uipanel") - || go.isa ("uibuttongroup")) - && (cname == "resizefcn" || cname == "sizechangedfcn"))) - busyaction = base_graphics_event::INTERRUPT; - else if (go.get_properties ().get_busyaction () == "cancel") - busyaction = base_graphics_event::CANCEL; - - // The "closerequestfcn" callback must be executed once the figure has - // been made current. Let "close" do the job. - if (cname == "closerequestfcn") - { - std::string cmd ("close (gcbf ());"); - post_event (graphics_event::create_mcode_event (h, cmd, busyaction)); - } - else - post_event (graphics_event::create_callback_event (h, name, data, - busyaction)); - } -} - -void -gh_manager::post_function (graphics_event::event_fcn fcn, void *fcn_data) -{ - octave::autolock guard (m_graphics_lock); - - post_event (graphics_event::create_function_event (fcn, fcn_data)); -} - -void -gh_manager::post_set (const graphics_handle& h, const std::string& name, - const octave_value& value, bool notify_toolkit, - bool redraw_figure) -{ - octave::autolock guard (m_graphics_lock); - - post_event (graphics_event::create_set_event (h, name, value, notify_toolkit, - redraw_figure)); -} - -int -gh_manager::process_events (bool force) -{ - graphics_event e; - bool old_Vdrawnow_requested = Vdrawnow_requested; - bool events_executed = false; - - do - { - e = graphics_event (); - - { - octave::autolock guard (m_graphics_lock); - - if (! m_event_queue.empty ()) - { - if (m_callback_objects.empty () || force) - { - e = m_event_queue.front (); - - m_event_queue.pop_front (); - } - else - { - const graphics_object& go = m_callback_objects.front (); - - if (go.get_properties ().is_interruptible ()) - { - e = m_event_queue.front (); - - m_event_queue.pop_front (); - } - else - { - std::list::iterator p = m_event_queue.begin (); - - while (p != m_event_queue.end ()) - if (p->get_busyaction () == base_graphics_event::CANCEL) - { - p = m_event_queue.erase (p); - } - else if (p->get_busyaction () - == base_graphics_event::INTERRUPT) - { - e = (*p); - m_event_queue.erase (p); - break; - } - else - p++; - } - } - } - } - - if (e.ok ()) - { - e.execute (); - events_executed = true; - } - } - while (e.ok ()); - - { - octave::autolock guard (m_graphics_lock); - - if (m_event_queue.empty () && m_event_processing == 0) - octave::command_editor::remove_event_hook (process_graphics_events); - } - - if (events_executed) - octave::flush_stdout (); - - if (Vdrawnow_requested && ! old_Vdrawnow_requested) - { - Fdrawnow (m_interpreter); - - Vdrawnow_requested = false; - } - - return 0; -} - - -/* -## Test interruptible/busyaction properties -%!function cb (h, ~) -%! setappdata (gcbf (), "cb_exec", [getappdata(gcbf (), "cb_exec") h]); -%! drawnow (); -%! setappdata (gcbf (), "cb_exec", [getappdata(gcbf (), "cb_exec") h]); -%!endfunction -%! -%!testif HAVE_OPENGL, HAVE_QT; have_window_system () && any (strcmp ("qt", available_graphics_toolkits ())) -%! hf = figure ("visible", "off", "resizefcn", @cb); -%! graphics_toolkit (hf, "qt"); -%! unwind_protect -%! ## Default -%! hui1 = uicontrol ("parent", hf, "interruptible", "on", "callback", @cb); -%! hui2 = uicontrol ("parent", hf, "busyaction", "queue", "callback", @cb); -%! hui3 = uicontrol ("parent", hf, "busyaction", "queue", "callback", @cb); -%! __go_post_callback__ (hui1, "callback"); -%! __go_post_callback__ (hui2, "callback"); -%! __go_post_callback__ (hui3, "callback"); -%! -%! assert (getappdata (hf, "cb_exec"), []); -%! drawnow (); -%! assert (getappdata (hf, "cb_exec"), [hui1 hui2 hui3 hui3 hui2 hui1]); -%! -%! ## Interruptible off -%! setappdata (hf, "cb_exec", []); -%! set (hui1, "interruptible", "off"); -%! __go_post_callback__ (hui1, "callback"); -%! __go_post_callback__ (hui2, "callback"); -%! __go_post_callback__ (hui3, "callback"); -%! drawnow (); -%! assert (getappdata (hf, "cb_exec"), [hui1 hui1 hui2 hui3 hui3 hui2]); -%! -%! ## "resizefcn" callback interrupts regardless of interruptible property -%! setappdata (hf, "cb_exec", []); -%! __go_post_callback__ (hui1, "callback"); -%! __go_post_callback__ (hf, "resizefcn"); -%! drawnow (); -%! assert (getappdata (hf, "cb_exec"), [hui1 hf hf hui1]); -%! -%! ## test "busyaction" "cancel" -%! setappdata (hf, "cb_exec", []); -%! set (hui2, "busyaction", "cancel"); -%! __go_post_callback__ (hui1, "callback"); -%! __go_post_callback__ (hui2, "callback"); -%! __go_post_callback__ (hui3, "callback"); -%! __go_post_callback__ (hf, "resizefcn"); -%! drawnow (); -%! assert (getappdata (hf, "cb_exec"), [hui1 hf hui3 hui3 hf hui1]); -%! unwind_protect_cleanup -%! close (hf) -%! end_unwind_protect -*/ - -void -gh_manager::enable_event_processing (bool enable) -{ - octave::autolock guard (m_graphics_lock); - - if (enable) - { - m_event_processing++; - - octave::command_editor::add_event_hook (process_graphics_events); - } - else - { - m_event_processing--; - - if (m_event_queue.empty () && m_event_processing == 0) - octave::command_editor::remove_event_hook (process_graphics_events); - } -} - property_list::plist_map_type -root_figure::init_factory_properties (void) +root_figure::init_factory_properties () { property_list::plist_map_type plist_map; @@ -12957,6 +12102,8 @@ @end example @end itemize +The three syntaxes for setting properties may appear in any combination. + @code{set} is also used to query the list of values a named property will take. @code{@var{clist} = set (@var{h}, "property")} will return the list of possible values for @qcode{"property"} in the cell list @var{clist}. @@ -12969,7 +12116,10 @@ property. If no output variable is used then the list is formatted and printed to the screen. -For example, +When querying properties only a single graphics handle @var{h} for a single +graphics object is permitted. + +Example Query @example @group @@ -12985,23 +12135,85 @@ @seealso{get} @end deftypefn */) { - gh_manager& gh_mgr = interp.get_gh_manager (); - - octave::autolock guard (gh_mgr.graphics_lock ()); - int nargin = args.length (); if (nargin == 0) print_usage (); - octave_value retval; - // get vector of graphics handles ColumnVector hcv = args(0).xvector_value ("set: H must be a graphics handle"); + gh_manager& gh_mgr = interp.get_gh_manager (); + + octave::autolock guard (gh_mgr.graphics_lock ()); + + octave_value retval; + + // Process requests for default value(s) + if (nargin == 1) + { + if (hcv.numel () > 1) + error ("set: H must be a single graphics handle when querying properties"); + + graphics_object go = gh_mgr.get_object (hcv(0)); + if (! go) + error ("set: invalid handle (= %g)", hcv(0)); + + if (nargout > 0) + retval = go.values_as_struct (); + else + { + std::string s = go.values_as_string (); + + octave_stdout << s; + } + + return retval; + } + else if (nargin == 2 && args(1).is_string ()) + { + if (hcv.numel () > 1) + error ("set: H must be a single graphics handle when querying properties"); + + std::string property = args(1).string_value (); + std::transform (property.begin (), property.end (), + property.begin (), tolower); + + graphics_object go = gh_mgr.get_object (hcv(0)); + + if (! go) + error ("set: invalid handle (= %g)", hcv(0)); + + octave_map pmap = go.values_as_struct (); + + if (go.has_readonly_property (property)) + { + if (nargout > 0) + retval = Matrix (); + else + octave_stdout << "set: " << property << " is read-only" + << std::endl; + } + else if (pmap.isfield (property)) + { + if (nargout != 0) + retval = pmap.getfield (property)(0); + else + { + std::string s = go.value_as_string (property); + + octave_stdout << s; + } + } + else + error (R"(set: unknown property "%s")", property.c_str ()); + + return retval; + } + bool request_drawnow = false; - // loop over graphics objects + // Loop over graphics objects for (octave_idx_type n = 0; n < hcv.numel (); n++) { graphics_object go = gh_mgr.get_object (hcv(n)); @@ -13009,62 +12221,40 @@ if (! go) error ("set: invalid handle (= %g)", hcv(n)); - if (nargin == 3 && args(1).iscellstr () && args(2).iscell ()) - { - if (args(2).cell_value ().rows () == 1) - go.set (args(1).cellstr_value (), args(2).cell_value (), 0); - else if (hcv.numel () == args(2).cell_value ().rows ()) - go.set (args(1).cellstr_value (), args(2).cell_value (), n); - else - error ("set: number of graphics handles must match number of " - "value rows (%" OCTAVE_IDX_TYPE_FORMAT " != " - "%" OCTAVE_IDX_TYPE_FORMAT ")", - hcv.numel (), args(2).cell_value ().rows ()); - } - else if (nargin == 2 && args(1).isstruct ()) - go.set (args(1).map_value ()); - else if (nargin == 2 && args(1).is_string ()) - { - std::string property = args(1).string_value (); - std::transform (property.begin (), property.end (), - property.begin (), tolower); - - octave_map pmap = go.values_as_struct (); - - if (go.has_readonly_property (property)) - if (nargout != 0) - retval = Matrix (); - else - octave_stdout << "set: " << property - <<" is read-only" << std::endl; - else if (pmap.isfield (property)) - { - if (nargout != 0) - retval = pmap.getfield (property)(0); + // Loop over input arguments + for (octave_idx_type i = 1; i < args.length (); ) + { + if (args(i).is_string ()) + { + if (i == nargin - 1) + error ("set: PROPERTY name must be followed by a VALUE"); + const caseless_str pname = args(i).string_value (); + const octave_value val = args(i+1); + go.set_value_or_default (pname, val); + i += 2; + } + else if (args(i).iscellstr ()) + { + if ((i == nargin - 1) || ! args(i+1).iscell ()) + error ("set: cell array of PROPERTIES must be followed by cell array of VALUES"); + if (args(i+1).cell_value ().rows () == 1) + go.set (args(i).cellstr_value (), args(i+1).cell_value (), 0); + else if (hcv.numel () == args(i+1).cell_value ().rows ()) + go.set (args(i).cellstr_value (), args(i+1).cell_value (), n); else - { - std::string s = go.value_as_string (property); - - octave_stdout << s; - } + error ("set: number of graphics handles must match number of " + "value rows (%" OCTAVE_IDX_TYPE_FORMAT " != " + "%" OCTAVE_IDX_TYPE_FORMAT ")", + hcv.numel (), args(i+1).cell_value ().rows ()); + i += 2; + } + else if (args(i).isstruct ()) + { + go.set (args(i).map_value ()); + i += 1; } else - error (R"(set: unknown property "%s")", property.c_str ()); - } - else if (nargin == 1) - { - if (nargout != 0) - retval = go.values_as_struct (); - else - { - std::string s = go.values_as_string (); - - octave_stdout << s; - } - } - else - { - go.set (args.splice (0, 1)); + error ("set: invalid syntax"); } request_drawnow = true; @@ -13076,6 +12266,41 @@ return retval; } +/* +## test setting ticklabels for compatibility +%!test +%! hf = figure ("visible", "off"); +%! set (gca (), "xticklabel", [0, 0.2, 0.4, 0.6, 0.8, 1]); +%! xticklabel = get (gca (), "xticklabel"); +%! close (hf); +%! assert (class (xticklabel), "char"); +%! assert (size (xticklabel), [6, 3]); + +%!test +%! hf = figure ("visible", "off"); +%! set (gca (), "xticklabel", "0|0.2|0.4|0.6|0.8|1"); +%! xticklabel = get (gca (), "xticklabel"); +%! close (hf); +%! assert (class (xticklabel), "char"); +%! assert (size (xticklabel), [6, 3]); + +%!test +%! hf = figure ("visible", "off"); +%! set (gca (), "xticklabel", ["0 "; "0.2"; "0.4"; "0.6"; "0.8"; "1 "]); +%! xticklabel = get (gca (), "xticklabel"); +%! close (hf); +%! assert (class (xticklabel), "char"); +%! assert (size (xticklabel), [6, 3]); + +%!test +%! hf = figure ("visible", "off"); +%! set (gca (), "xticklabel", {"0", "0.2", "0.4", "0.6", "0.8", "1"}); +%! xticklabel = get (gca (), "xticklabel"); +%! close (hf); +%! assert (class (xticklabel), "cell"); +%! assert (size (xticklabel), [6, 1]); +*/ + static std::string get_graphics_object_type (double val) { @@ -13168,8 +12393,7 @@ caseless_str property; if (nargin > 1) - property = args( - 1).xstring_value ("get: second argument must be property name or cell array of property names"); + property = args(1).xstring_value ("get: second argument must be property name or cell array of property names"); vals.resize (dim_vector (hcv_len, 1)); @@ -14025,9 +13249,7 @@ { std::string dirname = file.substr (0, pos+1); - octave::sys::file_stat fs (dirname); - - if (! fs || ! fs.is_dir ()) + if (! octave::sys::dir_exists (dirname)) error ("drawnow: nonexistent directory '%s'", dirname.c_str ()); @@ -14326,14 +13548,15 @@ } static bool -compare_property_values (const octave_value& ov1, const octave_value& ov2) +compare_property_values (octave::interpreter& interp, + const octave_value& ov1, const octave_value& ov2) { octave_value_list args(2); args(0) = ov1; args(1) = ov2; - octave_value_list result = octave::feval ("isequal", args, 1); + octave_value_list result = interp.feval ("isequal", args, 1); if (result.length () > 0) return result(0).bool_value (); @@ -14391,7 +13614,7 @@ cleanup_waitfor_predelete_listener (const octave_value& listener) { do_cleanup_waitfor_listener (listener, GCB_PREDELETE); } -DECLARE_STATIC_FUNX (waitfor_listener, args, ) +DECLARE_STATIC_METHODX (waitfor_listener, interp, args, ) { if (args.length () > 3) { @@ -14414,7 +13637,7 @@ graphics_object go = gh_mgr.get_object (gh); octave_value pvalue = go.get (pname); - if (compare_property_values (pvalue, args(5))) + if (compare_property_values (interp, pvalue, args(5))) waitfor_results[id] = true; } } @@ -14568,7 +13791,7 @@ graphics_object go = gh_mgr.get_object (gh); if (max_arg_index >= 2 - && compare_property_values (go.get (pname), args(2))) + && compare_property_values (interp, go.get (pname), args(2))) waitfor_results[id] = true; else { diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/graphics.in.h --- a/libinterp/corefcn/graphics.in.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/graphics.in.h Fri May 12 08:03:14 2023 +0200 @@ -66,9 +66,10 @@ class OCTINTERP_API base_scaler { public: - base_scaler (void) { } - - virtual ~base_scaler (void) = default; + + OCTAVE_DEFAULT_CONSTRUCT_COPY_MOVE (base_scaler) + + virtual ~base_scaler () = default; virtual Matrix scale (const Matrix&) const { @@ -93,14 +94,15 @@ virtual base_scaler * clone () const { return new base_scaler (); } - virtual bool is_linear (void) const + virtual bool is_linear () const { return false; } }; class lin_scaler : public base_scaler { public: - lin_scaler (void) { } + + OCTAVE_DEFAULT_CONSTRUCT_COPY_MOVE_DELETE (lin_scaler) Matrix scale (const Matrix& m) const { return m; } @@ -110,15 +112,16 @@ double unscale (double d) const { return d; } - base_scaler * clone (void) const { return new lin_scaler (); } - - bool is_linear (void) const { return true; } + base_scaler * clone () const { return new lin_scaler (); } + + bool is_linear () const { return true; } }; class log_scaler : public base_scaler { public: - log_scaler (void) { } + + OCTAVE_DEFAULT_CONSTRUCT_COPY_MOVE_DELETE (log_scaler) Matrix scale (const Matrix& m) const { @@ -144,7 +147,7 @@ double unscale (double d) const { return std::pow (10.0, d); } - base_scaler * clone (void) const + base_scaler * clone () const { return new log_scaler (); } private: @@ -158,7 +161,8 @@ class OCTINTERP_API neg_log_scaler : public base_scaler { public: - neg_log_scaler (void) { } + + OCTAVE_DEFAULT_CONSTRUCT_COPY_MOVE_DELETE (neg_log_scaler) Matrix scale (const Matrix& m) const { @@ -184,7 +188,7 @@ double unscale (double d) const { return -std::pow (10.0, -d); } - base_scaler * clone (void) const + base_scaler * clone () const { return new neg_log_scaler (); } private: @@ -198,7 +202,8 @@ class OCTINTERP_API scaler { public: - scaler (void) : m_rep (new base_scaler ()) { } + + scaler () : m_rep (new base_scaler ()) { } scaler (const scaler& s) : m_rep (s.m_rep->clone ()) { } @@ -212,7 +217,7 @@ : new base_scaler ()))) { } - ~scaler (void) { delete m_rep; } + ~scaler () { delete m_rep; } Matrix scale (const Matrix& m) const { return m_rep->scale (m); } @@ -226,7 +231,7 @@ double unscale (double d) const { return m_rep->unscale (d); } - bool is_linear (void) const + bool is_linear () const { return m_rep->is_linear (); } scaler& operator = (const scaler& s) @@ -286,7 +291,7 @@ friend class property; public: - base_property (void) + base_property () : m_id (-1), m_count (1), m_name (), m_parent (), m_hidden (), m_listeners () { } @@ -301,25 +306,28 @@ m_hidden (p.m_hidden), m_listeners () { } - virtual ~base_property (void) = default; - - bool ok (void) const { return m_parent.ok (); } - - std::string get_name (void) const { return m_name; } + // FIXME: should we define assignment? + base_property& operator = (const base_property&) = delete; + + virtual ~base_property () = default; + + bool ok () const { return m_parent.ok (); } + + std::string get_name () const { return m_name; } void set_name (const std::string& s) { m_name = s; } - graphics_handle get_parent (void) const { return m_parent; } + graphics_handle get_parent () const { return m_parent; } void set_parent (const graphics_handle& h) { m_parent = h; } - bool is_hidden (void) const { return m_hidden; } + bool is_hidden () const { return m_hidden; } void set_hidden (bool flag) { m_hidden = flag; } - virtual bool is_radio (void) const { return false; } - - int get_id (void) const { return m_id; } + virtual bool is_radio () const { return false; } + + int get_id () const { return m_id; } void set_id (int d) { m_id = d; } @@ -328,17 +336,17 @@ OCTINTERP_API bool set (const octave_value& v, bool do_run = true, bool do_notify_toolkit = true); - virtual octave_value get (void) const + virtual octave_value get () const { error (R"(get: invalid property "%s")", m_name.c_str ()); } - virtual std::string values_as_string (void) const + virtual std::string values_as_string () const { error (R"(values_as_string: invalid property "%s")", m_name.c_str ()); } - virtual Cell values_as_cell (void) const + virtual Cell values_as_cell () const { error (R"(values_as_cell: invalid property "%s")", m_name.c_str ()); } @@ -408,7 +416,7 @@ OCTINTERP_API void run_listeners (listener_mode mode = GCB_POSTSET); - virtual base_property * clone (void) const + virtual base_property * clone () const { return new base_property (*this); } protected: @@ -438,17 +446,24 @@ class OCTINTERP_API string_property : public base_property { public: + + string_property () = delete; + string_property (const std::string& s, const graphics_handle& h, const std::string& val = "") : base_property (s, h), m_str (val) { } - string_property (const string_property& p) - : base_property (p), m_str (p.m_str) { } - - octave_value get (void) const + string_property (const string_property&) = default; + + // FIXME: should we define assignment? + string_property& operator = (const string_property&) = delete; + + ~string_property () = default; + + octave_value get () const { return octave_value (m_str); } - std::string string_value (void) const { return m_str; } + std::string string_value () const { return m_str; } string_property& operator = (const octave_value& val) { @@ -456,7 +471,7 @@ return *this; } - base_property * clone (void) const { return new string_property (*this); } + base_property * clone () const { return new string_property (*this); } protected: bool do_set (const octave_value& val) @@ -486,6 +501,8 @@ public: enum desired_enum { string_t, cell_t }; + string_array_property () = delete; + string_array_property (const std::string& s, const graphics_handle& h, const std::string& val = "", const char& sep = '|', const desired_enum& typ = string_t) @@ -526,11 +543,14 @@ m_str = strings; } - string_array_property (const string_array_property& p) - : base_property (p), m_desired_type (p.m_desired_type), - m_separator (p.m_separator), m_str (p.m_str) { } - - octave_value get (void) const + string_array_property (const string_array_property&) = default; + + // FIXME: should we define assignment? + string_array_property& operator = (const string_array_property&) = delete; + + ~string_array_property () = default; + + octave_value get () const { if (m_desired_type == string_t) return octave_value (string_value ()); @@ -538,7 +558,7 @@ return octave_value (cell_value ()); } - std::string string_value (void) const + std::string string_value () const { std::string s; @@ -552,9 +572,9 @@ return s; } - Cell cell_value (void) const {return Cell (m_str);} - - string_vector string_vector_value (void) const { return m_str; } + Cell cell_value () const {return Cell (m_str);} + + string_vector string_vector_value () const { return m_str; } string_array_property& operator = (const octave_value& val) { @@ -562,7 +582,7 @@ return *this; } - base_property * clone (void) const + base_property * clone () const { return new string_array_property (*this); } protected: @@ -686,6 +706,8 @@ public: enum type { char_t, cellstr_t }; + text_label_property () = delete; + text_label_property (const std::string& s, const graphics_handle& h, const std::string& val = "") : base_property (s, h), m_value (val), m_stored_type (char_t) @@ -732,17 +754,20 @@ } } - text_label_property (const text_label_property& p) - : base_property (p), m_value (p.m_value), m_stored_type (p.m_stored_type) - { } - - bool empty (void) const + text_label_property (const text_label_property&) = default; + + // FIXME: should we define assignment? + text_label_property& operator = (const text_label_property&) = delete; + + ~text_label_property () = default; + + bool empty () const { octave_value tmp = get (); return tmp.isempty (); } - octave_value get (void) const + octave_value get () const { if (m_stored_type == char_t) return octave_value (char_value ()); @@ -750,16 +775,16 @@ return octave_value (cell_value ()); } - std::string string_value (void) const + std::string string_value () const { return m_value.empty () ? "" : m_value[0]; } - string_vector string_vector_value (void) const { return m_value; } - - charMatrix char_value (void) const { return charMatrix (m_value, ' '); } - - Cell cell_value (void) const {return Cell (m_value); } + string_vector string_vector_value () const { return m_value; } + + charMatrix char_value () const { return charMatrix (m_value, ' '); } + + Cell cell_value () const {return Cell (m_value); } text_label_property& operator = (const octave_value& val) { @@ -767,7 +792,7 @@ return *this; } - base_property * clone (void) const { return new text_label_property (*this); } + base_property * clone () const { return new text_label_property (*this); } protected: @@ -848,21 +873,9 @@ public: OCTINTERP_API radio_values (const std::string& opt_string = ""); - radio_values (const radio_values& a) - : m_default_val (a.m_default_val), m_possible_vals (a.m_possible_vals) { } - - radio_values& operator = (const radio_values& a) - { - if (&a != this) - { - m_default_val = a.m_default_val; - m_possible_vals = a.m_possible_vals; - } - - return *this; - } - - std::string default_value (void) const { return m_default_val; } + OCTAVE_DEFAULT_COPY_MOVE_DELETE (radio_values) + + std::string default_value () const { return m_default_val; } bool validate (const std::string& val, std::string& match) { @@ -913,11 +926,11 @@ return false; } - OCTINTERP_API std::string values_as_string (void) const; - - OCTINTERP_API Cell values_as_cell (void) const; - - octave_idx_type nelem (void) const { return m_possible_vals.size (); } + OCTINTERP_API std::string values_as_string () const; + + OCTINTERP_API Cell values_as_cell () const; + + octave_idx_type nelem () const { return m_possible_vals.size (); } private: // Might also want to cache @@ -928,6 +941,9 @@ class OCTINTERP_API radio_property : public base_property { public: + + radio_property () = delete; + radio_property (const std::string& nm, const graphics_handle& h, const radio_values& v = radio_values ()) : base_property (nm, h), @@ -943,22 +959,24 @@ : base_property (nm, h), m_vals (v), m_current_val (def) { } - radio_property (const radio_property& p) - : base_property (p), m_vals (p.m_vals), m_current_val (p.m_current_val) { } - - octave_value get (void) const { return octave_value (m_current_val); } - - const std::string& current_value (void) const { return m_current_val; } - - std::string values_as_string (void) const + OCTAVE_DEFAULT_COPY_MOVE_CTOR (radio_property) + OCTAVE_DISABLE_COPY_MOVE_ASGN (radio_property) + + ~radio_property () = default; + + octave_value get () const { return octave_value (m_current_val); } + + const std::string& current_value () const { return m_current_val; } + + std::string values_as_string () const { return m_vals.values_as_string (); } - Cell values_as_cell (void) const { return m_vals.values_as_cell (); } + Cell values_as_cell () const { return m_vals.values_as_cell (); } bool is (const caseless_str& v) const { return v.compare (m_current_val); } - bool is_radio (void) const { return true; } + bool is_radio () const { return true; } radio_property& operator = (const octave_value& val) { @@ -966,7 +984,7 @@ return *this; } - base_property * clone (void) const { return new radio_property (*this); } + base_property * clone () const { return new radio_property (*this); } protected: bool do_set (const octave_value& newval) @@ -1023,17 +1041,7 @@ error ("invalid color specification: %s", str.c_str ()); } - color_values (const color_values& c) - : m_rgb (c.m_rgb) - { } - - color_values& operator = (const color_values& c) - { - if (&c != this) - m_rgb = c.m_rgb; - - return *this; - } + OCTAVE_DEFAULT_COPY_MOVE_DELETE (color_values) bool operator == (const color_values& c) const { @@ -1045,11 +1053,11 @@ bool operator != (const color_values& c) const { return ! (*this == c); } - Matrix rgb (void) const { return m_rgb; } - - operator octave_value (void) const { return m_rgb; } - - void validate (void) const + Matrix rgb () const { return m_rgb; } + + operator octave_value () const { return m_rgb; } + + void validate () const { for (int i = 0; i < 3; i++) { @@ -1067,6 +1075,9 @@ class OCTINTERP_API color_property : public base_property { public: + + color_property () = delete; + color_property (const color_values& c, const radio_values& v) : base_property ("", graphics_handle ()), m_current_type (color_t), m_color_val (c), m_radio_val (v), @@ -1108,12 +1119,12 @@ m_radio_val (v.m_radio_val), m_current_val (v.m_current_val) { } - color_property (const color_property& p) - : base_property (p), m_current_type (p.m_current_type), - m_color_val (p.m_color_val), m_radio_val (p.m_radio_val), - m_current_val (p.m_current_val) { } - - octave_value get (void) const + OCTAVE_DEFAULT_COPY_MOVE_CTOR (color_property) + OCTAVE_DISABLE_COPY_MOVE_ASGN (color_property) + + ~color_property () = default; + + octave_value get () const { if (m_current_type == color_t) return m_color_val.rgb (); @@ -1121,14 +1132,14 @@ return m_current_val; } - bool is_rgb (void) const { return (m_current_type == color_t); } - - bool is_radio (void) const { return (m_current_type == radio_t); } + bool is_rgb () const { return (m_current_type == color_t); } + + bool is_radio () const { return (m_current_type == radio_t); } bool is (const std::string& v) const { return (is_radio () && m_current_val == v); } - Matrix rgb (void) const + Matrix rgb () const { if (m_current_type != color_t) error ("color has no RGB value"); @@ -1136,7 +1147,7 @@ return m_color_val.rgb (); } - const std::string& current_value (void) const + const std::string& current_value () const { if (m_current_type != radio_t) error ("color has no radio value"); @@ -1150,14 +1161,14 @@ return *this; } - operator octave_value (void) const { return get (); } - - base_property * clone (void) const { return new color_property (*this); } - - std::string values_as_string (void) const + operator octave_value () const { return get (); } + + base_property * clone () const { return new color_property (*this); } + + std::string values_as_string () const { return m_radio_val.values_as_string (); } - Cell values_as_cell (void) const { return m_radio_val.values_as_cell (); } + Cell values_as_cell () const { return m_radio_val.values_as_cell (); } protected: OCTINTERP_API bool do_set (const octave_value& newval); @@ -1182,6 +1193,9 @@ class OCTINTERP_API double_property : public base_property { public: + + double_property () = delete; + double_property (const std::string& nm, const graphics_handle& h, double d = 0) : base_property (nm, h), @@ -1195,9 +1209,14 @@ m_minval (std::pair (octave_NaN, true)), m_maxval (std::pair (octave_NaN, true)) { } - octave_value get (void) const { return octave_value (m_current_val); } - - double double_value (void) const { return m_current_val; } + // FIXME: should we define assignment? + double_property& operator = (const double_property&) = delete; + + ~double_property () = default; + + octave_value get () const { return octave_value (m_current_val); } + + double double_value () const { return m_current_val; } double_property& operator = (const octave_value& val) { @@ -1205,7 +1224,7 @@ return *this; } - base_property * clone (void) const + base_property * clone () const { double_property *p = new double_property (*this); @@ -1294,6 +1313,9 @@ class OCTINTERP_API double_radio_property : public base_property { public: + + double_radio_property () = delete; + double_radio_property (double d, const radio_values& v) : base_property ("", graphics_handle ()), m_current_type (double_t), m_dval (d), m_radio_val (v), @@ -1314,12 +1336,12 @@ m_radio_val (v.m_radio_val), m_current_val (v.m_current_val) { } - double_radio_property (const double_radio_property& p) - : base_property (p), m_current_type (p.m_current_type), - m_dval (p.m_dval), m_radio_val (p.m_radio_val), - m_current_val (p.m_current_val) { } - - octave_value get (void) const + OCTAVE_DEFAULT_COPY_MOVE_CTOR (double_radio_property) + OCTAVE_DISABLE_COPY_MOVE_ASGN (double_radio_property) + + ~double_radio_property () = default; + + octave_value get () const { if (m_current_type == double_t) return m_dval; @@ -1327,14 +1349,14 @@ return m_current_val; } - bool is_double (void) const { return (m_current_type == double_t); } - - bool is_radio (void) const { return (m_current_type == radio_t); } + bool is_double () const { return (m_current_type == double_t); } + + bool is_radio () const { return (m_current_type == radio_t); } bool is (const std::string& v) const { return (is_radio () && m_current_val == v); } - double double_value (void) const + double double_value () const { if (m_current_type != double_t) error ("%s: property has no double", get_name ().c_str ()); @@ -1342,7 +1364,7 @@ return m_dval; } - const std::string& current_value (void) const + const std::string& current_value () const { if (m_current_type != radio_t) error ("%s: property has no radio value", get_name ().c_str ()); @@ -1356,9 +1378,9 @@ return *this; } - operator octave_value (void) const { return get (); } - - base_property * clone (void) const + operator octave_value () const { return get (); } + + base_property * clone () const { return new double_radio_property (*this); } protected: @@ -1376,7 +1398,7 @@ class OCTINTERP_API array_property : public base_property { public: - array_property (void) + array_property () : base_property ("", graphics_handle ()), m_data (Matrix ()), m_min_val (), m_max_val (), m_min_pos (), m_max_neg (), m_type_constraints (), m_size_constraints (), @@ -1412,7 +1434,12 @@ m_maxval (std::pair (octave_NaN, true)) { } - octave_value get (void) const { return m_data; } + // FIXME: Should we define assignment? + array_property& operator = (const array_property&) = delete; + + ~array_property () = default; + + octave_value get () const { return m_data; } void add_constraint (const std::string& type) { m_type_constraints.insert (type); } @@ -1431,12 +1458,12 @@ m_maxval = std::pair (val, inclusive); } - double min_val (void) const { return m_min_val; } - double max_val (void) const { return m_max_val; } - double min_pos (void) const { return m_min_pos; } - double max_neg (void) const { return m_max_neg; } - - Matrix get_limits (void) const + double min_val () const { return m_min_val; } + double max_val () const { return m_max_val; } + double min_pos () const { return m_min_pos; } + double max_neg () const { return m_max_neg; } + + Matrix get_limits () const { Matrix m (1, 4); @@ -1454,7 +1481,7 @@ return *this; } - base_property * clone (void) const + base_property * clone () const { array_property *p = new array_property (*this); @@ -1494,7 +1521,7 @@ OCTINTERP_API bool is_equal (const octave_value& v) const; - OCTINTERP_API void get_data_limits (void); + OCTINTERP_API void get_data_limits (); protected: octave_value m_data; @@ -1511,6 +1538,9 @@ class OCTINTERP_API row_vector_property : public array_property { public: + + row_vector_property () = delete; + row_vector_property (const std::string& nm, const graphics_handle& h, const octave_value& m) : array_property (nm, h, m) @@ -1528,6 +1558,11 @@ add_constraint (dim_vector (0, 0)); } + // FIXME: should we define assignment? + row_vector_property& operator = (const row_vector_property&) = delete; + + ~row_vector_property () = default; + void add_constraint (const std::string& type) { array_property::add_constraint (type); @@ -1564,7 +1599,7 @@ return *this; } - base_property * clone (void) const + base_property * clone () const { row_vector_property *p = new row_vector_property (*this); @@ -1605,6 +1640,9 @@ class OCTINTERP_API bool_property : public radio_property { public: + + bool_property () = delete; + bool_property (const std::string& nm, const graphics_handle& h, bool val) : radio_property (nm, h, radio_values (val ? "{on}|off" : "on|{off}")) @@ -1616,10 +1654,12 @@ "{on}|off" : "on|{off}"), val) { } - bool_property (const bool_property& p) - : radio_property (p) { } - - bool is_on (void) const { return is ("on"); } + OCTAVE_DEFAULT_COPY_MOVE_CTOR (bool_property) + OCTAVE_DISABLE_COPY_MOVE_ASGN (bool_property) + + ~bool_property () = default; + + bool is_on () const { return is ("on"); } bool_property& operator = (const octave_value& val) { @@ -1627,7 +1667,7 @@ return *this; } - base_property * clone (void) const { return new bool_property (*this); } + base_property * clone () const { return new bool_property (*this); } protected: bool do_set (const octave_value& val) @@ -1644,17 +1684,24 @@ class OCTINTERP_API handle_property : public base_property { public: + + handle_property () = delete; + handle_property (const std::string& nm, const graphics_handle& h, const graphics_handle& val = graphics_handle ()) : base_property (nm, h), m_current_val (val) { } - handle_property (const handle_property& p) - : base_property (p), m_current_val (p.m_current_val) { } - - octave_value get (void) const { return m_current_val.as_octave_value (); } - - graphics_handle handle_value (void) const { return m_current_val; } + handle_property (const handle_property&) = default; + + // FIXME: should we define assignment? + handle_property& operator = (const handle_property&) = delete; + + ~handle_property () = default; + + octave_value get () const { return m_current_val.as_octave_value (); } + + graphics_handle handle_value () const { return m_current_val; } handle_property& operator = (const octave_value& val) { @@ -1668,10 +1715,10 @@ return *this; } - void invalidate (void) + void invalidate () { m_current_val = octave::numeric_limits::NaN (); } - base_property * clone (void) const { return new handle_property (*this); } + base_property * clone () const { return new handle_property (*this); } void add_constraint (const std::string& type) { m_type_constraints.insert (type); } @@ -1689,14 +1736,19 @@ class OCTINTERP_API any_property : public base_property { public: + + any_property () = delete; + any_property (const std::string& nm, const graphics_handle& h, const octave_value& m = Matrix ()) : base_property (nm, h), m_data (m) { } - any_property (const any_property& p) - : base_property (p), m_data (p.m_data) { } - - octave_value get (void) const { return m_data; } + OCTAVE_DEFAULT_COPY_MOVE_CTOR (any_property) + OCTAVE_DISABLE_COPY_MOVE_ASGN (any_property) + + ~any_property () = default; + + octave_value get () const { return m_data; } any_property& operator = (const octave_value& val) { @@ -1704,7 +1756,7 @@ return *this; } - base_property * clone (void) const { return new any_property (*this); } + base_property * clone () const { return new any_property (*this); } protected: bool do_set (const octave_value& v) @@ -1722,7 +1774,7 @@ class OCTINTERP_API children_property : public base_property { public: - children_property (void) + children_property () : base_property ("", graphics_handle ()), m_children_list () { do_init_children (Matrix ()); @@ -1747,7 +1799,12 @@ return *this; } - base_property * clone (void) const { return new children_property (*this); } + // FIXME: should we define assignment? + children_property& operator = (const children_property&) = delete; + + ~children_property () = default; + + base_property * clone () const { return new children_property (*this); } bool remove_child (double val) { @@ -1759,22 +1816,22 @@ do_adopt_child (val); } - Matrix get_children (void) const + Matrix get_children () const { return do_get_children (false); } - Matrix get_hidden (void) const + Matrix get_hidden () const { return do_get_children (true); } - Matrix get_all (void) const + Matrix get_all () const { return do_get_all_children (); } - octave_value get (void) const + octave_value get () const { return octave_value (get_children ()); } @@ -1877,7 +1934,7 @@ OCTINTERP_API Matrix do_get_children (bool return_hidden) const; - Matrix do_get_all_children (void) const + Matrix do_get_all_children () const { Matrix retval (m_children_list.size (), 1); octave_idx_type i = 0; @@ -1914,18 +1971,25 @@ class OCTINTERP_API callback_property : public base_property { public: + + callback_property () = delete; + callback_property (const std::string& nm, const graphics_handle& h, const octave_value& m) : base_property (nm, h), m_callback (m) { } - callback_property (const callback_property& p) - : base_property (p), m_callback (p.m_callback) { } - - octave_value get (void) const { return m_callback; } + callback_property (const callback_property&) = default; + + // FIXME: should we define assignment? + callback_property& operator = (const callback_property&) = delete; + + ~callback_property () = default; + + octave_value get () const { return m_callback; } OCTINTERP_API void execute (const octave_value& data = octave_value ()) const; - bool is_defined (void) const + bool is_defined () const { return (m_callback.is_defined () && ! m_callback.isempty ()); } @@ -1936,7 +2000,7 @@ return *this; } - base_property * clone (void) const { return new callback_property (*this); } + base_property * clone () const { return new callback_property (*this); } protected: bool do_set (const octave_value& v) @@ -1962,7 +2026,7 @@ class OCTINTERP_API property { public: - property (void) : m_rep (new base_property ("", graphics_handle ())) + property () : m_rep (new base_property ("", graphics_handle ())) { } property (base_property *bp, bool persist = false) : m_rep (bp) @@ -1973,53 +2037,53 @@ m_rep->m_count++; } - ~property (void) + ~property () { if (--m_rep->m_count == 0) delete m_rep; } - bool ok (void) const + bool ok () const { return m_rep->ok (); } - std::string get_name (void) const + std::string get_name () const { return m_rep->get_name (); } void set_name (const std::string& name) { m_rep->set_name (name); } - graphics_handle get_parent (void) const + graphics_handle get_parent () const { return m_rep->get_parent (); } void set_parent (const graphics_handle& h) { m_rep->set_parent (h); } - bool is_hidden (void) const + bool is_hidden () const { return m_rep->is_hidden (); } void set_hidden (bool flag) { m_rep->set_hidden (flag); } - bool is_radio (void) const + bool is_radio () const { return m_rep->is_radio (); } - int get_id (void) const + int get_id () const { return m_rep->get_id (); } void set_id (int d) { m_rep->set_id (d); } - octave_value get (void) const + octave_value get () const { return m_rep->get (); } bool set (const octave_value& val, bool do_run = true, bool do_notify_toolkit = true) { return m_rep->set (val, do_run, do_notify_toolkit); } - std::string values_as_string (void) const + std::string values_as_string () const { return m_rep->values_as_string (); } - Cell values_as_cell (void) const + Cell values_as_cell () const { return m_rep->values_as_cell (); } property& operator = (const octave_value& val) @@ -2053,29 +2117,9 @@ create (const std::string& name, const graphics_handle& parent, const caseless_str& type, const octave_value_list& args); - property clone (void) const + property clone () const { return property (m_rep->clone ()); } -#if 0 - const string_property& as_string_property (void) const - { return *(dynamic_cast (m_rep)); } - - const radio_property& as_radio_property (void) const - { return *(dynamic_cast (m_rep)); } - - const color_property& as_color_property (void) const - { return *(dynamic_cast (m_rep)); } - - const double_property& as_double_property (void) const - { return *(dynamic_cast (m_rep)); } - - const bool_property& as_bool_property (void) const - { return *(dynamic_cast (m_rep)); } - - const handle_property& as_handle_property (void) const - { return *(dynamic_cast (m_rep)); } -#endif - private: base_property *m_rep; }; @@ -2163,17 +2207,17 @@ property_list (const plist_map_type& m = plist_map_type ()) : m_plist_map (m) { } - ~property_list (void) = default; + OCTAVE_DEFAULT_COPY_MOVE_DELETE (property_list) OCTINTERP_API void set (const caseless_str& name, const octave_value& val); OCTINTERP_API octave_value lookup (const caseless_str& name) const; - plist_map_iterator begin (void) { return m_plist_map.begin (); } - plist_map_const_iterator begin (void) const { return m_plist_map.begin (); } - - plist_map_iterator end (void) { return m_plist_map.end (); } - plist_map_const_iterator end (void) const { return m_plist_map.end (); } + plist_map_iterator begin () { return m_plist_map.begin (); } + plist_map_const_iterator begin () const { return m_plist_map.begin (); } + + plist_map_iterator end () { return m_plist_map.end (); } + plist_map_const_iterator end () const { return m_plist_map.end (); } plist_map_iterator find (const std::string& go_name) { @@ -2204,11 +2248,13 @@ const graphics_handle& mh = graphics_handle (), const graphics_handle& p = graphics_handle ()); - virtual ~base_properties (void) = default; - - virtual std::string graphics_object_name (void) const { return "unknown"; } - - OCTINTERP_API void mark_modified (void); + OCTAVE_DISABLE_COPY_MOVE (base_properties) + + virtual ~base_properties () = default; + + virtual std::string graphics_object_name () const { return "unknown"; } + + OCTINTERP_API void mark_modified (); OCTINTERP_API void override_defaults (base_graphics_object& obj); @@ -2257,7 +2303,7 @@ return false; } - bool is_modified (void) const { return is___modified__ (); } + bool is_modified () const { return is___modified__ (); } virtual void remove_child (const graphics_handle& h, bool = false) { @@ -2275,14 +2321,14 @@ mark_modified (); } - virtual octave::graphics_toolkit get_toolkit (void) const; + virtual octave::graphics_toolkit get_toolkit () const; virtual Matrix get_boundingbox (bool /* finternal */ = false, const Matrix& /* parent_pix_size */ = Matrix ()) const { return Matrix (1, 4, 0.0); } - virtual void update_boundingbox (void); + virtual void update_boundingbox (); virtual void update_autopos (const std::string& elem_type); @@ -2302,17 +2348,17 @@ OCTINTERP_API void set_parent (const octave_value& val); - Matrix get_children (void) const + Matrix get_children () const { return m_children.get_children (); } - Matrix get_all_children (void) const + Matrix get_all_children () const { return m_children.get_all (); } - Matrix get_hidden_children (void) const + Matrix get_hidden_children () const { return m_children.get_hidden (); } @@ -2328,7 +2374,7 @@ // Redirect calls to "uicontextmenu" to "contextmenu". - graphics_handle get_uicontextmenu (void) const + graphics_handle get_uicontextmenu () const { return get_contextmenu (); } @@ -2348,7 +2394,7 @@ virtual void update_axis_limits (const std::string& axis_type, const graphics_handle& h) const; - virtual void update_contextmenu (void) const; + virtual void update_contextmenu () const; virtual void delete_children (bool clear = false, bool from_root = false) { @@ -2365,28 +2411,28 @@ m_parent = new_gh; } - static OCTINTERP_API property_list::pval_map_type factory_defaults (void); + static OCTINTERP_API property_list::pval_map_type factory_defaults (); // FIXME: These functions should be generated automatically by the // genprops.awk script. // // EMIT_BASE_PROPERTIES_GET_FUNCTIONS - virtual octave_value get_alim (void) const { return octave_value (); } - virtual octave_value get_clim (void) const { return octave_value (); } - virtual octave_value get_xlim (void) const { return octave_value (); } - virtual octave_value get_ylim (void) const { return octave_value (); } - virtual octave_value get_zlim (void) const { return octave_value (); } - - virtual bool is_aliminclude (void) const { return false; } - virtual bool is_climinclude (void) const { return false; } - virtual bool is_xliminclude (void) const { return false; } - virtual bool is_yliminclude (void) const { return false; } - virtual bool is_zliminclude (void) const { return false; } - - OCTINTERP_API bool is_handle_visible (void) const; - - OCTINTERP_API std::set dynamic_property_names (void) const; + virtual octave_value get_alim () const { return octave_value (); } + virtual octave_value get_clim () const { return octave_value (); } + virtual octave_value get_xlim () const { return octave_value (); } + virtual octave_value get_ylim () const { return octave_value (); } + virtual octave_value get_zlim () const { return octave_value (); } + + virtual bool is_aliminclude () const { return false; } + virtual bool is_climinclude () const { return false; } + virtual bool is_xliminclude () const { return false; } + virtual bool is_yliminclude () const { return false; } + virtual bool is_zliminclude () const { return false; } + + OCTINTERP_API bool is_handle_visible () const; + + OCTINTERP_API std::set dynamic_property_names () const; OCTINTERP_API bool has_dynamic_property (const std::string& pname) const; @@ -2431,11 +2477,11 @@ graphics_handle __myhandle__ fhrs , mh END_PROPERTIES - virtual void update_beingdeleted (void) { }; - - virtual void update_handlevisibility (void); - - virtual void update_visible (void) { }; + virtual void update_beingdeleted () { }; + + virtual void update_handlevisibility (); + + virtual void update_visible () { }; protected: struct cmp_caseless_str @@ -2456,7 +2502,7 @@ protected: - virtual void init (void) + virtual void init () { m_contextmenu.add_constraint ("uicontextmenu"); } @@ -2467,17 +2513,13 @@ public: friend class graphics_object; - base_graphics_object (void) : m_toolkit_flag (false) { } - - // No copying! - - base_graphics_object (const base_graphics_object&) = delete; - - base_graphics_object& operator = (const base_graphics_object&) = delete; - - virtual ~base_graphics_object (void) = default; - - virtual void mark_modified (void) + base_graphics_object () : m_toolkit_flag (false) { } + + OCTAVE_DISABLE_COPY_MOVE (base_graphics_object) + + virtual ~base_graphics_object () = default; + + virtual void mark_modified () { if (! valid_object ()) error ("base_graphics_object::mark_modified: invalid graphics object"); @@ -2539,12 +2581,12 @@ virtual octave_value get_factory_default (const caseless_str&) const; - virtual octave_value get_defaults (void) const + virtual octave_value get_defaults () const { error ("base_graphics_object::get_defaults: invalid graphics object"); } - virtual property_list get_defaults_list (void) const + virtual property_list get_defaults_list () const { if (! valid_object ()) error ("base_graphics_object::get_defaults_list: invalid graphics object"); @@ -2552,12 +2594,12 @@ return property_list (); } - virtual octave_value get_factory_defaults (void) const + virtual octave_value get_factory_defaults () const { error ("base_graphics_object::get_factory_defaults: invalid graphics object"); } - virtual property_list get_factory_defaults_list (void) const + virtual property_list get_factory_defaults_list () const { error ("base_graphics_object::get_factory_defaults_list: invalid graphics object"); } @@ -2569,7 +2611,7 @@ // FIXME: It seems like this function should be const, but that is // currently not possible. - virtual std::string values_as_string (void); + virtual std::string values_as_string (); // FIXME: It seems like this function should be const, but that is // currently not possible. @@ -2577,9 +2619,9 @@ // FIXME: It seems like this function should be const, but that is // currently not possible. - virtual octave_scalar_map values_as_struct (void); - - virtual graphics_handle get_parent (void) const + virtual octave_scalar_map values_as_struct (); + + virtual graphics_handle get_parent () const { if (! valid_object ()) error ("base_graphics_object::get_parent: invalid graphics object"); @@ -2587,7 +2629,7 @@ return get_properties ().get_parent (); } - graphics_handle get_handle (void) const + graphics_handle get_handle () const { if (! valid_object ()) error ("base_graphics_object::get_handle: invalid graphics object"); @@ -2619,7 +2661,7 @@ get_properties ().reparent (np); } - virtual void defaults (void) const + virtual void defaults () const { if (! valid_object ()) error ("base_graphics_object::default: invalid graphics object"); @@ -2628,14 +2670,14 @@ err_not_implemented (msg.c_str ()); } - virtual base_properties& get_properties (void) + virtual base_properties& get_properties () { static base_properties properties; warning ("base_graphics_object::get_properties: invalid graphics object"); return properties; } - virtual const base_properties& get_properties (void) const + virtual const base_properties& get_properties () const { static base_properties properties; warning ("base_graphics_object::get_properties: invalid graphics object"); @@ -2647,11 +2689,11 @@ virtual void update_axis_limits (const std::string& axis_type, const graphics_handle& h); - virtual bool valid_object (void) const { return false; } - - bool valid_toolkit_object (void) const { return m_toolkit_flag; } - - virtual std::string type (void) const + virtual bool valid_object () const { return false; } + + bool valid_toolkit_object () const { return m_toolkit_flag; } + + virtual std::string type () const { return (valid_object () ? get_properties ().graphics_object_name () : "unknown"); @@ -2662,7 +2704,7 @@ return type () == go_name; } - virtual octave::graphics_toolkit get_toolkit (void) const + virtual octave::graphics_toolkit get_toolkit () const { if (! valid_object ()) error ("base_graphics_object::get_toolkit: invalid graphics object"); @@ -2686,9 +2728,9 @@ get_properties ().delete_listener (nm, v, mode); } - virtual void remove_all_listeners (void); - - virtual void reset_default_properties (void); + virtual void remove_all_listeners (); + + virtual void reset_default_properties (); protected: virtual void initialize (const graphics_object& go) @@ -2723,7 +2765,7 @@ { public: - graphics_object (void) : m_rep (new base_graphics_object ()) { } + graphics_object () : m_rep (new base_graphics_object ()) { } graphics_object (base_graphics_object *new_rep) : m_rep (new_rep) { } @@ -2731,16 +2773,16 @@ graphics_object& operator = (const graphics_object&) = default; - ~graphics_object (void) = default; - - void mark_modified (void) { m_rep->mark_modified (); } + ~graphics_object () = default; + + void mark_modified () { m_rep->mark_modified (); } void override_defaults (base_graphics_object& obj) { m_rep->override_defaults (obj); } - void override_defaults (void) + void override_defaults () { m_rep->override_defaults (*m_rep); } @@ -2800,19 +2842,19 @@ return m_rep->get_factory_default (name); } - octave_value get_defaults (void) const { return m_rep->get_defaults (); } - - property_list get_defaults_list (void) const + octave_value get_defaults () const { return m_rep->get_defaults (); } + + property_list get_defaults_list () const { return m_rep->get_defaults_list (); } - octave_value get_factory_defaults (void) const + octave_value get_factory_defaults () const { return m_rep->get_factory_defaults (); } - property_list get_factory_defaults_list (void) const + property_list get_factory_defaults_list () const { return m_rep->get_factory_defaults_list (); } @@ -2824,7 +2866,7 @@ // FIXME: It seems like this function should be const, but that is // currently not possible. - std::string values_as_string (void) { return m_rep->values_as_string (); } + std::string values_as_string () { return m_rep->values_as_string (); } // FIXME: It seems like this function should be const, but that is // currently not possible. @@ -2835,11 +2877,11 @@ // FIXME: It seems like this function should be const, but that is // currently not possible. - octave_map values_as_struct (void) { return m_rep->values_as_struct (); } - - graphics_handle get_parent (void) const { return m_rep->get_parent (); } - - graphics_handle get_handle (void) const { return m_rep->get_handle (); } + octave_map values_as_struct () { return m_rep->values_as_struct (); } + + graphics_handle get_parent () const { return m_rep->get_parent (); } + + graphics_handle get_handle () const { return m_rep->get_handle (); } OCTINTERP_API graphics_object get_ancestor (const std::string& type) const; @@ -2849,13 +2891,13 @@ void reparent (const graphics_handle& h) { m_rep->reparent (h); } - void defaults (void) const { m_rep->defaults (); } + void defaults () const { m_rep->defaults (); } bool isa (const std::string& go_name) const { return m_rep->isa (go_name); } - base_properties& get_properties (void) { return m_rep->get_properties (); } - - const base_properties& get_properties (void) const + base_properties& get_properties () { return m_rep->get_properties (); } + + const base_properties& get_properties () const { return m_rep->get_properties (); } @@ -2871,51 +2913,51 @@ m_rep->update_axis_limits (axis_type, h); } - bool valid_object (void) const { return m_rep->valid_object (); } - - std::string type (void) const { return m_rep->type (); } - - operator bool (void) const { return m_rep->valid_object (); } + bool valid_object () const { return m_rep->valid_object (); } + + std::string type () const { return m_rep->type (); } + + operator bool () const { return m_rep->valid_object (); } // FIXME: These functions should be generated automatically by the // genprops.awk script. // // EMIT_GRAPHICS_OBJECT_GET_FUNCTIONS - octave_value get_alim (void) const + octave_value get_alim () const { return get_properties ().get_alim (); } - octave_value get_clim (void) const + octave_value get_clim () const { return get_properties ().get_clim (); } - octave_value get_xlim (void) const + octave_value get_xlim () const { return get_properties ().get_xlim (); } - octave_value get_ylim (void) const + octave_value get_ylim () const { return get_properties ().get_ylim (); } - octave_value get_zlim (void) const + octave_value get_zlim () const { return get_properties ().get_zlim (); } - bool is_aliminclude (void) const + bool is_aliminclude () const { return get_properties ().is_aliminclude (); } - bool is_climinclude (void) const + bool is_climinclude () const { return get_properties ().is_climinclude (); } - bool is_xliminclude (void) const + bool is_xliminclude () const { return get_properties ().is_xliminclude (); } - bool is_yliminclude (void) const + bool is_yliminclude () const { return get_properties ().is_yliminclude (); } - bool is_zliminclude (void) const + bool is_zliminclude () const { return get_properties ().is_zliminclude (); } - bool is_handle_visible (void) const + bool is_handle_visible () const { return get_properties ().is_handle_visible (); } - octave::graphics_toolkit get_toolkit (void) const + octave::graphics_toolkit get_toolkit () const { return m_rep->get_toolkit (); } void add_property_listener (const std::string& nm, const octave_value& v, @@ -2926,15 +2968,15 @@ listener_mode mode = GCB_POSTSET) { m_rep->delete_property_listener (nm, v, mode); } - void remove_all_listeners (void) { m_rep->remove_all_listeners (); } - - void initialize (void) { m_rep->initialize (*this); } - - void finalize (void) { m_rep->finalize (*this); } + void remove_all_listeners () { m_rep->remove_all_listeners (); } + + void initialize () { m_rep->initialize (*this); } + + void finalize () { m_rep->finalize (*this); } void update (int id) { m_rep->update (*this, id); } - void reset_default_properties (void) + void reset_default_properties () { m_rep->reset_default_properties (); } private: @@ -3001,20 +3043,18 @@ protected: - root_figure (void) + root_figure () : m_properties (0, graphics_handle ()), m_default_properties (), m_factory_properties (init_factory_properties ()) { } public: - ~root_figure (void) = default; - - root_figure (const root_figure&) = delete; - - root_figure& operator = (const root_figure&) = delete; - - void mark_modified (void) { } + OCTAVE_DISABLE_COPY_MOVE (root_figure) + + ~root_figure () = default; + + void mark_modified () { } void override_defaults (base_graphics_object& obj) { @@ -3077,33 +3117,33 @@ return retval; } - octave_value get_defaults (void) const + octave_value get_defaults () const { return m_default_properties.as_struct ("default"); } - property_list get_defaults_list (void) const + property_list get_defaults_list () const { return m_default_properties; } - octave_value get_factory_defaults (void) const + octave_value get_factory_defaults () const { return m_factory_properties.as_struct ("factory"); } - property_list get_factory_defaults_list (void) const + property_list get_factory_defaults_list () const { return m_factory_properties; } - base_properties& get_properties (void) { return m_properties; } - - const base_properties& get_properties (void) const { return m_properties; } - - bool valid_object (void) const { return true; } - - OCTINTERP_API void reset_default_properties (void); + base_properties& get_properties () { return m_properties; } + + const base_properties& get_properties () const { return m_properties; } + + bool valid_object () const { return true; } + + OCTINTERP_API void reset_default_properties (); bool has_readonly_property (const caseless_str& pname) const { @@ -3120,7 +3160,7 @@ property_list m_factory_properties; static OCTINTERP_API property_list::plist_map_type - init_factory_properties (void); + init_factory_properties (); }; // --------------------------------------------------------------------- @@ -3142,7 +3182,7 @@ OCTINTERP_API void set_visible (const octave_value& val); - OCTINTERP_API octave::graphics_toolkit get_toolkit (void) const; + OCTINTERP_API octave::graphics_toolkit get_toolkit () const; OCTINTERP_API void set_toolkit (const octave::graphics_toolkit& b); @@ -3151,7 +3191,7 @@ OCTINTERP_API void adopt (const graphics_handle& h); // Alias "innerposition" to "position". - octave_value get_innerposition (void) const + octave_value get_innerposition () const { return get_position (); } @@ -3185,7 +3225,7 @@ OCTINTERP_API void update_paperunits (const caseless_str& old_paperunits); - OCTINTERP_API std::string get_title (void) const; + OCTINTERP_API std::string get_title () const; // See the genprops.awk script for an explanation of the // properties declarations. @@ -3270,7 +3310,7 @@ END_PROPERTIES protected: - void init (void) + void init () { m_alphamap.add_constraint (dim_vector (-1, 1)); m_alphamap.add_constraint (dim_vector (1, -1)); @@ -3292,17 +3332,17 @@ } private: - OCTINTERP_API Matrix get_auto_paperposition (void); - - void update_paperpositionmode (void) + OCTINTERP_API Matrix get_auto_paperposition (); + + void update_paperpositionmode () { if (m_paperpositionmode.is ("auto")) m_paperposition.set (get_auto_paperposition ()); } - OCTINTERP_API void update_handlevisibility (void); - - OCTINTERP_API void init_toolkit (void); + OCTINTERP_API void update_handlevisibility (); + + OCTINTERP_API void init_toolkit (); octave::graphics_toolkit m_toolkit; }; @@ -3311,11 +3351,14 @@ properties m_properties; public: + figure (const graphics_handle& mh, const graphics_handle& p) : base_graphics_object (), m_properties (mh, p), m_default_properties () { } - ~figure (void) = default; + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (figure) + + ~figure () = default; void override_defaults (base_graphics_object& obj) { @@ -3356,23 +3399,23 @@ OCTINTERP_API octave_value get_default (const caseless_str& name) const; - octave_value get_defaults (void) const + octave_value get_defaults () const { return m_default_properties.as_struct ("default"); } - property_list get_defaults_list (void) const + property_list get_defaults_list () const { return m_default_properties; } - base_properties& get_properties (void) { return m_properties; } - - const base_properties& get_properties (void) const { return m_properties; } - - bool valid_object (void) const { return true; } - - OCTINTERP_API void reset_default_properties (void); + base_properties& get_properties () { return m_properties; } + + const base_properties& get_properties () const { return m_properties; } + + bool valid_object () const { return true; } + + OCTINTERP_API void reset_default_properties (); bool has_readonly_property (const caseless_str& pname) const { @@ -3392,7 +3435,7 @@ { public: - graphics_xform (void) + graphics_xform () : m_xform (xform_eye ()), m_xform_inv (xform_eye ()), m_sx ("linear"), m_sy ("linear"), m_sz ("linear"), m_zlim (1, 2, 0.0) { @@ -3410,7 +3453,7 @@ : m_xform (g.m_xform), m_xform_inv (g.m_xform_inv), m_sx (g.m_sx), m_sy (g.m_sy), m_sz (g.m_sz), m_zlim (g.m_zlim) { } - ~graphics_xform (void) = default; + ~graphics_xform () = default; graphics_xform& operator = (const graphics_xform& g) { @@ -3426,7 +3469,7 @@ static OCTINTERP_API ColumnVector xform_vector (double x, double y, double z); - static OCTINTERP_API Matrix xform_eye (void); + static OCTINTERP_API Matrix xform_eye (); OCTINTERP_API ColumnVector transform (double x, double y, double z, bool use_scale = true) const; @@ -3495,9 +3538,9 @@ OCTINTERP_API void adopt (const graphics_handle& h); - const scaler& get_x_scaler (void) const { return m_sx; } - const scaler& get_y_scaler (void) const { return m_sy; } - const scaler& get_z_scaler (void) const { return m_sz; } + const scaler& get_x_scaler () const { return m_sx; } + const scaler& get_y_scaler () const { return m_sy; } + const scaler& get_z_scaler () const { return m_sz; } OCTINTERP_API Matrix get_boundingbox (bool internal = false, @@ -3509,7 +3552,7 @@ OCTINTERP_API double get___fontsize_points__ (double box_pix_height = 0) const; - void update_boundingbox (void) + void update_boundingbox () { if (units_is ("normalized")) { @@ -3518,21 +3561,21 @@ } } - OCTINTERP_API void update_camera (void); - OCTINTERP_API void update_axes_layout (void); - OCTINTERP_API void update_aspectratios (void); - void update_transform (void) + OCTINTERP_API void update_camera (); + OCTINTERP_API void update_axes_layout (); + OCTINTERP_API void update_aspectratios (); + void update_transform () { update_aspectratios (); update_camera (); update_axes_layout (); } - OCTINTERP_API void sync_positions (void); + OCTINTERP_API void sync_positions (); // Redirect calls to "activepositionproperty" to "positionconstraint". - std::string get_activepositionproperty (void) const + std::string get_activepositionproperty () const { std::string cur_val; @@ -3557,7 +3600,7 @@ // Redirect calls to "innerposition" to "position". - octave_value get_innerposition (void) const + octave_value get_innerposition () const { return get_position (); } @@ -3568,63 +3611,63 @@ } OCTINTERP_API void update_autopos (const std::string& elem_type); - OCTINTERP_API void update_xlabel_position (void); - OCTINTERP_API void update_ylabel_position (void); - OCTINTERP_API void update_zlabel_position (void); - OCTINTERP_API void update_title_position (void); - - graphics_xform get_transform (void) const + OCTINTERP_API void update_xlabel_position (); + OCTINTERP_API void update_ylabel_position (); + OCTINTERP_API void update_zlabel_position (); + OCTINTERP_API void update_title_position (); + + graphics_xform get_transform () const { return graphics_xform (m_x_render, m_x_render_inv, m_sx, m_sy, m_sz, m_x_zlim); } - Matrix get_transform_matrix (void) const { return m_x_render; } - Matrix get_inverse_transform_matrix (void) const { return m_x_render_inv; } - Matrix get_opengl_matrix_1 (void) const { return m_x_gl_mat1; } - Matrix get_opengl_matrix_2 (void) const { return m_x_gl_mat2; } - Matrix get_transform_zlim (void) const { return m_x_zlim; } - - int get_xstate (void) const { return m_xstate; } - int get_ystate (void) const { return m_ystate; } - int get_zstate (void) const { return m_zstate; } - double get_xPlane (void) const { return m_xPlane; } - double get_xPlaneN (void) const { return m_xPlaneN; } - double get_yPlane (void) const { return m_yPlane; } - double get_yPlaneN (void) const { return m_yPlaneN; } - double get_zPlane (void) const { return m_zPlane; } - double get_zPlaneN (void) const { return m_zPlaneN; } - double get_xpTick (void) const { return m_xpTick; } - double get_xpTickN (void) const { return m_xpTickN; } - double get_ypTick (void) const { return m_ypTick; } - double get_ypTickN (void) const { return m_ypTickN; } - double get_zpTick (void) const { return m_zpTick; } - double get_zpTickN (void) const { return m_zpTickN; } - double get_x_min (void) const { return std::min (m_xPlane, m_xPlaneN); } - double get_x_max (void) const { return std::max (m_xPlane, m_xPlaneN); } - double get_y_min (void) const { return std::min (m_yPlane, m_yPlaneN); } - double get_y_max (void) const { return std::max (m_yPlane, m_yPlaneN); } - double get_z_min (void) const { return std::min (m_zPlane, m_zPlaneN); } - double get_z_max (void) const { return std::max (m_zPlane, m_zPlaneN); } - double get_fx (void) const { return m_fx; } - double get_fy (void) const { return m_fy; } - double get_fz (void) const { return m_fz; } - double get_xticklen (void) const { return m_xticklen; } - double get_yticklen (void) const { return m_yticklen; } - double get_zticklen (void) const { return m_zticklen; } - double get_xtickoffset (void) const { return m_xtickoffset; } - double get_ytickoffset (void) const { return m_ytickoffset; } - double get_ztickoffset (void) const { return m_ztickoffset; } - bool get_x2Dtop (void) const { return m_x2Dtop; } - bool get_y2Dright (void) const { return m_y2Dright; } - bool get_layer2Dtop (void) const { return m_layer2Dtop; } + Matrix get_transform_matrix () const { return m_x_render; } + Matrix get_inverse_transform_matrix () const { return m_x_render_inv; } + Matrix get_opengl_matrix_1 () const { return m_x_gl_mat1; } + Matrix get_opengl_matrix_2 () const { return m_x_gl_mat2; } + Matrix get_transform_zlim () const { return m_x_zlim; } + + int get_xstate () const { return m_xstate; } + int get_ystate () const { return m_ystate; } + int get_zstate () const { return m_zstate; } + double get_xPlane () const { return m_xPlane; } + double get_xPlaneN () const { return m_xPlaneN; } + double get_yPlane () const { return m_yPlane; } + double get_yPlaneN () const { return m_yPlaneN; } + double get_zPlane () const { return m_zPlane; } + double get_zPlaneN () const { return m_zPlaneN; } + double get_xpTick () const { return m_xpTick; } + double get_xpTickN () const { return m_xpTickN; } + double get_ypTick () const { return m_ypTick; } + double get_ypTickN () const { return m_ypTickN; } + double get_zpTick () const { return m_zpTick; } + double get_zpTickN () const { return m_zpTickN; } + double get_x_min () const { return std::min (m_xPlane, m_xPlaneN); } + double get_x_max () const { return std::max (m_xPlane, m_xPlaneN); } + double get_y_min () const { return std::min (m_yPlane, m_yPlaneN); } + double get_y_max () const { return std::max (m_yPlane, m_yPlaneN); } + double get_z_min () const { return std::min (m_zPlane, m_zPlaneN); } + double get_z_max () const { return std::max (m_zPlane, m_zPlaneN); } + double get_fx () const { return m_fx; } + double get_fy () const { return m_fy; } + double get_fz () const { return m_fz; } + double get_xticklen () const { return m_xticklen; } + double get_yticklen () const { return m_yticklen; } + double get_zticklen () const { return m_zticklen; } + double get_xtickoffset () const { return m_xtickoffset; } + double get_ytickoffset () const { return m_ytickoffset; } + double get_ztickoffset () const { return m_ztickoffset; } + bool get_x2Dtop () const { return m_x2Dtop; } + bool get_y2Dright () const { return m_y2Dright; } + bool get_layer2Dtop () const { return m_layer2Dtop; } bool get_is2D (bool include_kids = false) const { return (include_kids ? (m_is2D && ! m_has3Dkids) : m_is2D); } void set_has3Dkids (bool val) { m_has3Dkids = val; } - bool get_xySym (void) const { return m_xySym; } - bool get_xyzSym (void) const { return m_xyzSym; } - bool get_zSign (void) const { return m_zSign; } - bool get_nearhoriz (void) const { return m_nearhoriz; } + bool get_xySym () const { return m_xySym; } + bool get_xyzSym () const { return m_xyzSym; } + bool get_zSign () const { return m_zSign; } + bool get_nearhoriz () const { return m_nearhoriz; } ColumnVector pixel2coord (double px, double py) const { @@ -3662,9 +3705,9 @@ rotate_view (double delta_az, double delta_el, bool push_to_zoom_stack = true); - OCTINTERP_API void unzoom (void); - OCTINTERP_API void update_handlevisibility (void); - OCTINTERP_API void push_zoom_stack (void); + OCTINTERP_API void unzoom (); + OCTINTERP_API void update_handlevisibility (); + OCTINTERP_API void push_zoom_stack (); OCTINTERP_API void clear_zoom_stack (bool do_unzoom = true); OCTINTERP_API void update_units (const caseless_str& old_units); @@ -3673,9 +3716,9 @@ OCTINTERP_API void update_fontunits (const caseless_str& old_fontunits); - void increase_num_lights (void) { m_num_lights++; } - void decrease_num_lights (void) { m_num_lights--; } - unsigned int get_num_lights (void) const { return m_num_lights; } + void increase_num_lights () { m_num_lights++; } + void decrease_num_lights () { m_num_lights--; } + unsigned int get_num_lights () const { return m_num_lights; } private: @@ -3908,7 +3951,7 @@ END_PROPERTIES protected: - OCTINTERP_API void init (void); + OCTINTERP_API void init (); private: @@ -3923,67 +3966,67 @@ return retval; } - void update_xscale (void) + void update_xscale () { m_sx = get_scale (get_xscale (), m_xlim.get ().matrix_value ()); } - void update_yscale (void) + void update_yscale () { m_sy = get_scale (get_yscale (), m_ylim.get ().matrix_value ()); } - void update_zscale (void) + void update_zscale () { m_sz = get_scale (get_zscale (), m_zlim.get ().matrix_value ()); } OCTINTERP_API void update_label_color (handle_property label, color_property col); - void update_xcolor (void) + void update_xcolor () { update_label_color (m_xlabel, m_xcolor); } - void update_ycolor (void) + void update_ycolor () { update_label_color (m_ylabel, m_ycolor); } - void update_zcolor (void) + void update_zcolor () { update_label_color (m_zlabel, m_zcolor); } - void update_view (void) { sync_positions (); } - - void update_cameraposition (void) { update_transform (); } - void update_cameratarget (void) { update_transform (); } - void update_cameraupvector (void) { update_transform (); } - void update_cameraviewangle (void) { update_transform (); } - - void update_camerapositionmode (void) + void update_view () { sync_positions (); } + + void update_cameraposition () { update_transform (); } + void update_cameratarget () { update_transform (); } + void update_cameraupvector () { update_transform (); } + void update_cameraviewangle () { update_transform (); } + + void update_camerapositionmode () { if (camerapositionmode_is ("auto")) update_cameraposition (); } - void update_cameratargetmode (void) + void update_cameratargetmode () { if (cameratargetmode_is ("auto")) update_cameratarget (); } - void update_cameraupvectormode (void) + void update_cameraupvectormode () { if (cameraupvectormode_is ("auto")) update_cameraupvector (); } - void update_cameraviewanglemode (void) + void update_cameraviewanglemode () { if (cameraviewanglemode_is ("auto")) update_cameraviewangle (); } - void update_dataaspectratio (void) { sync_positions (); } - void update_dataaspectratiomode (void) { sync_positions (); } - void update_plotboxaspectratio (void) { sync_positions (); } - void update_plotboxaspectratiomode (void) { sync_positions (); } - - void update_layer (void) { update_axes_layout (); } - void update_box (void) + void update_dataaspectratio () { sync_positions (); } + void update_dataaspectratiomode () { sync_positions (); } + void update_plotboxaspectratio () { sync_positions (); } + void update_plotboxaspectratiomode () { sync_positions (); } + + void update_layer () { update_axes_layout (); } + void update_box () { if (m_xticklabelmode.is ("auto")) calc_ticklabels (m_xtick, m_xticklabel, m_xscale.is ("log"), @@ -4000,7 +4043,7 @@ (xaxislocation_is ("bottom") ? -1 : 1)), m_ylim); } - void update_yaxislocation (void) + void update_yaxislocation () { sync_positions (); update_axes_layout (); @@ -4020,7 +4063,7 @@ m_ylim); update_ylabel_position (); } - void update_xaxislocation (void) + void update_xaxislocation () { sync_positions (); update_axes_layout (); @@ -4041,15 +4084,15 @@ update_xlabel_position (); } - void update_xdir (void) { update_camera (); update_axes_layout (); } - void update_ydir (void) { update_camera (); update_axes_layout (); } - void update_zdir (void) { update_camera (); update_axes_layout (); } - - void update_ticklength (void); - void update_tickdir (void) { update_ticklength (); } - void update_tickdirmode (void) { update_ticklength (); } - - void update_ticklabelinterpreter (void) + void update_xdir () { update_camera (); update_axes_layout (); } + void update_ydir () { update_camera (); update_axes_layout (); } + void update_zdir () { update_camera (); update_axes_layout (); } + + void update_ticklength (); + void update_tickdir () { update_ticklength (); } + void update_tickdirmode () { update_ticklength (); } + + void update_ticklabelinterpreter () { update_xtick (false); update_ytick (false); @@ -4104,23 +4147,23 @@ sync_positions (); } - void update_xtickmode (void) + void update_xtickmode () { if (m_xtickmode.is ("auto")) update_xtick (); } - void update_ytickmode (void) + void update_ytickmode () { if (m_ytickmode.is ("auto")) update_ytick (); } - void update_ztickmode (void) + void update_ztickmode () { if (m_ztickmode.is ("auto")) update_ztick (); } - void update_xticklabelmode (void) + void update_xticklabelmode () { if (m_xticklabelmode.is ("auto")) calc_ticklabels (m_xtick, m_xticklabel, m_xscale.is ("log"), @@ -4130,7 +4173,7 @@ (yaxislocation_is ("left") ? -1 : 1)), m_xlim); } - void update_yticklabelmode (void) + void update_yticklabelmode () { if (m_yticklabelmode.is ("auto")) calc_ticklabels (m_ytick, m_yticklabel, m_yscale.is ("log"), @@ -4140,61 +4183,61 @@ (xaxislocation_is ("bottom") ? -1 : 1)), m_ylim); } - void update_zticklabelmode (void) + void update_zticklabelmode () { if (m_zticklabelmode.is ("auto")) calc_ticklabels (m_ztick, m_zticklabel, m_zscale.is ("log"), false, 2, m_zlim); } - void update_fontname (void) + void update_fontname () { update_font ("fontname"); sync_positions (); } - void update_fontsize (void) + void update_fontsize () { update_font ("fontsize"); sync_positions (); } - void update_fontsmoothing (void) + void update_fontsmoothing () { update_font ("fontsmoothing"); } - void update_fontangle (void) + void update_fontangle () { update_font ("fontangle"); sync_positions (); } - void update_fontweight (void) + void update_fontweight () { update_font ("fontweight"); sync_positions (); } - void update_titlefontsizemultiplier (void) + void update_titlefontsizemultiplier () { // update_font handles title and axis labels update_font ("fontsize"); sync_positions (); } - void update_labelfontsizemultiplier (void) + void update_labelfontsizemultiplier () { update_font ("fontsize"); sync_positions (); } - void update_titlefontweight (void) + void update_titlefontweight () { // update_font handles title and axis labels update_font ("fontweight"); sync_positions (); } - OCTINTERP_API void update_outerposition (void); - OCTINTERP_API void update_position (void); - OCTINTERP_API void update_looseinset (void); + OCTINTERP_API void update_outerposition (); + OCTINTERP_API void update_position (); + OCTINTERP_API void update_looseinset (); OCTINTERP_API double calc_tick_sep (double minval, double maxval); OCTINTERP_API void @@ -4239,12 +4282,12 @@ set___colormap__ (val); } - void update___colormap__ (void) + void update___colormap__ () { m_colormap.run_listeners (GCB_POSTSET); } - OCTINTERP_API octave_value get_colormap (void) const; + OCTINTERP_API octave_value get_colormap () const; public: OCTINTERP_API Matrix @@ -4284,7 +4327,7 @@ update_xlim (); } - void update_ylim (void) + void update_ylim () { update_axis_limits ("ylim"); @@ -4312,7 +4355,7 @@ update_ylim (); } - void update_zlim (void) + void update_zlim () { update_axis_limits ("zlim"); @@ -4336,7 +4379,7 @@ update_zlim (); } - void trigger_normals_calc (void); + void trigger_normals_calc (); }; @@ -4350,7 +4393,9 @@ m_properties.update_transform (); } - ~axes (void) = default; + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (axes) + + ~axes () = default; void override_defaults (base_graphics_object& obj) { @@ -4397,28 +4442,28 @@ OCTINTERP_API octave_value get_default (const caseless_str& name) const; - octave_value get_defaults (void) const + octave_value get_defaults () const { return m_default_properties.as_struct ("default"); } - property_list get_defaults_list (void) const + property_list get_defaults_list () const { return m_default_properties; } - base_properties& get_properties (void) { return m_properties; } - - const base_properties& get_properties (void) const { return m_properties; } + base_properties& get_properties () { return m_properties; } + + const base_properties& get_properties () const { return m_properties; } OCTINTERP_API void update_axis_limits (const std::string& axis_type); OCTINTERP_API void update_axis_limits (const std::string& axis_type, const graphics_handle& h); - bool valid_object (void) const { return true; } - - OCTINTERP_API void reset_default_properties (void); + bool valid_object () const { return true; } + + OCTINTERP_API void reset_default_properties (); bool has_readonly_property (const caseless_str& pname) const { @@ -4476,21 +4521,21 @@ END_PROPERTIES protected: - void init (void) + void init () { m_linewidth.add_constraint ("min", 0, false); m_markersize.add_constraint ("min", 0, false); } private: - OCTINTERP_API Matrix compute_xlim (void) const; - OCTINTERP_API Matrix compute_ylim (void) const; - - void update_xdata (void) { set_xlim (compute_xlim ()); } - - void update_ydata (void) { set_ylim (compute_ylim ()); } - - void update_zdata (void) { set_zlim (m_zdata.get_limits ()); } + OCTINTERP_API Matrix compute_xlim () const; + OCTINTERP_API Matrix compute_ylim () const; + + void update_xdata () { set_xlim (compute_xlim ()); } + + void update_ydata () { set_ylim (compute_ylim ()); } + + void update_zdata () { set_zlim (m_zdata.get_limits ()); } }; private: @@ -4501,13 +4546,15 @@ : base_graphics_object (), m_properties (mh, p) { } - ~line (void) = default; - - base_properties& get_properties (void) { return m_properties; } - - const base_properties& get_properties (void) const { return m_properties; } - - bool valid_object (void) const { return true; } + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (line) + + ~line () = default; + + base_properties& get_properties () { return m_properties; } + + const base_properties& get_properties () const { return m_properties; } + + bool valid_object () const { return true; } bool has_readonly_property (const caseless_str& pname) const { @@ -4531,9 +4578,9 @@ OCTINTERP_API double get___fontsize_points__ (double box_pix_height = 0) const; - OCTINTERP_API void update_text_extent (void); - - OCTINTERP_API void update_font (void); + OCTINTERP_API void update_text_extent (); + + OCTINTERP_API void update_font (); void set_position (const octave_value& val) { @@ -4601,15 +4648,15 @@ double_property __fontsize_points__ hgr , 0 END_PROPERTIES - OCTINTERP_API Matrix get_data_position (void) const; + OCTINTERP_API Matrix get_data_position () const; OCTINTERP_API Matrix get_extent_matrix (bool rotated = false) const; - const uint8NDArray& get_pixels (void) const { return m_pixels; } + const uint8NDArray& get_pixels () const { return m_pixels; } // Text renderer, used for calculation of text size octave::text_renderer m_txt_renderer; protected: - void init (void) + void init () { m_position.add_constraint (dim_vector (1, 3)); m_fontsize.add_constraint ("min", 0.0, false); @@ -4620,7 +4667,7 @@ } private: - void update_position (void) + void update_position () { Matrix pos = get_data_position (); Matrix lim; @@ -4646,19 +4693,19 @@ } } - OCTINTERP_API void request_autopos (void); - void update_positionmode (void) { request_autopos (); } - void update_rotationmode (void) { request_autopos (); } - void update_horizontalalignmentmode (void) { request_autopos (); } - void update_verticalalignmentmode (void) { request_autopos (); } - - void update_string (void) { request_autopos (); update_text_extent (); } - void update_rotation (void) { update_text_extent (); } - void update_fontname (void) { update_font (); update_text_extent (); } - void update_fontsize (void) { update_font (); update_text_extent (); } - void update_fontsmoothing (void) { update_font (); update_text_extent (); } - - void update_color (void) + OCTINTERP_API void request_autopos (); + void update_positionmode () { request_autopos (); } + void update_rotationmode () { request_autopos (); } + void update_horizontalalignmentmode () { request_autopos (); } + void update_verticalalignmentmode () { request_autopos (); } + + void update_string () { request_autopos (); update_text_extent (); } + void update_rotation () { update_text_extent (); } + void update_fontname () { update_font (); update_text_extent (); } + void update_fontsize () { update_font (); update_text_extent (); } + void update_fontsmoothing () { update_font (); update_text_extent (); } + + void update_color () { if (! m_color.is ("none")) { @@ -4667,18 +4714,18 @@ } } - void update_fontangle (void) + void update_fontangle () { update_font (); update_text_extent (); } - void update_fontweight (void) { update_font (); update_text_extent (); } - - void update_interpreter (void) { update_text_extent (); } - void update_horizontalalignment (void) { update_text_extent (); } - void update_verticalalignment (void) { update_text_extent (); } - - OCTINTERP_API void update_units (void); + void update_fontweight () { update_font (); update_text_extent (); } + + void update_interpreter () { update_text_extent (); } + void update_horizontalalignment () { update_text_extent (); } + void update_verticalalignment () { update_text_extent (); } + + OCTINTERP_API void update_units (); OCTINTERP_API void update_fontunits (const caseless_str& old_fontunits); private: @@ -4696,13 +4743,15 @@ m_properties.set_clipping ("off"); } - ~text (void) = default; - - base_properties& get_properties (void) { return m_properties; } - - const base_properties& get_properties (void) const { return m_properties; } - - bool valid_object (void) const { return true; } + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (text) + + ~text () = default; + + base_properties& get_properties () { return m_properties; } + + const base_properties& get_properties () const { return m_properties; } + + bool valid_object () const { return true; } bool has_readonly_property (const caseless_str& pname) const { @@ -4723,19 +4772,19 @@ { public: - bool is_aliminclude (void) const + bool is_aliminclude () const { return (m_aliminclude.is_on () && m_alphadatamapping.is ("scaled")); } - std::string get_aliminclude (void) const + std::string get_aliminclude () const { return m_aliminclude.current_value (); } - bool is_climinclude (void) const + bool is_climinclude () const { return (m_climinclude.is_on () && m_cdatamapping.is ("scaled")); } - std::string get_climinclude (void) const + std::string get_climinclude () const { return m_climinclude.current_value (); } - OCTINTERP_API octave_value get_color_data (void) const; - - void initialize_data (void) { update_cdata (); } + OCTINTERP_API octave_value get_color_data () const; + + void initialize_data () { update_cdata (); } // See the genprops.awk script for an explanation of the // properties declarations. @@ -4762,7 +4811,7 @@ END_PROPERTIES protected: - void init (void) + void init () { m_xdata.add_constraint (2); m_xdata.add_constraint (dim_vector (0, 0)); @@ -4788,7 +4837,7 @@ } private: - void update_alphadata (void) + void update_alphadata () { if (alphadatamapping_is ("scaled")) set_alim (m_alphadata.get_limits ()); @@ -4796,7 +4845,7 @@ m_alim = m_alphadata.get_limits (); } - void update_cdata (void) + void update_cdata () { if (cdatamapping_is ("scaled")) set_clim (m_cdata.get_limits ()); @@ -4810,7 +4859,7 @@ update_ydata (); } - void update_xdata (void) + void update_xdata () { if (m_xdata.get ().isempty ()) set_xdatamode ("auto"); @@ -4829,7 +4878,7 @@ set_xlim (limits); } - void update_ydata (void) + void update_ydata () { if (m_ydata.get ().isempty ()) set_ydatamode ("auto"); @@ -4848,7 +4897,7 @@ set_ylim (limits); } - Matrix get_auto_xdata (void) + Matrix get_auto_xdata () { dim_vector dv = get_cdata ().dims (); Matrix data; @@ -4860,7 +4909,7 @@ return data; } - Matrix get_auto_ydata (void) + Matrix get_auto_ydata () { dim_vector dv = get_cdata ().dims (); Matrix data; @@ -4890,12 +4939,12 @@ } public: - float pixel_xsize (void) + float pixel_xsize () { return pixel_size ((get_cdata ().dims ())(1), m_xdata.get_limits ()); } - float pixel_ysize (void) + float pixel_ysize () { return pixel_size ((get_cdata ().dims ())(0), m_ydata.get_limits ()); } @@ -4911,13 +4960,15 @@ m_properties.initialize_data (); } - ~image (void) = default; - - base_properties& get_properties (void) { return m_properties; } - - const base_properties& get_properties (void) const { return m_properties; } - - bool valid_object (void) const { return true; } + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (image) + + ~image () = default; + + base_properties& get_properties () { return m_properties; } + + const base_properties& get_properties () const { return m_properties; } + + bool valid_object () const { return true; } bool has_readonly_property (const caseless_str& pname) const { @@ -4947,13 +4998,13 @@ END_PROPERTIES protected: - void init (void) + void init () { m_position.add_constraint (dim_vector (1, 3)); } private: - OCTINTERP_API void update_visible (void); + OCTINTERP_API void update_visible (); }; private: @@ -4964,13 +5015,15 @@ : base_graphics_object (), m_properties (mh, p) { } - ~light (void) = default; - - base_properties& get_properties (void) { return m_properties; } - - const base_properties& get_properties (void) const { return m_properties; } - - bool valid_object (void) const { return true; } + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (light) + + ~light () = default; + + base_properties& get_properties () { return m_properties; } + + const base_properties& get_properties () const { return m_properties; } + + bool valid_object () const { return true; } bool has_readonly_property (const caseless_str& pname) const { @@ -4994,7 +5047,7 @@ { public: - octave_value get_color_data (void) const; + octave_value get_color_data () const; // Matlab allows incoherent data to be stored into patch properties. // The patch should then be ignored by the renderer. @@ -5004,17 +5057,17 @@ return ! msg.empty (); } - bool is_aliminclude (void) const + bool is_aliminclude () const { return (m_aliminclude.is_on () && m_alphadatamapping.is ("scaled")); } - std::string get_aliminclude (void) const + std::string get_aliminclude () const { return m_aliminclude.current_value (); } - bool is_climinclude (void) const + bool is_climinclude () const { return (m_climinclude.is_on () && m_cdatamapping.is ("scaled")); } - std::string get_climinclude (void) const + std::string get_climinclude () const { return m_climinclude.current_value (); } - OCTINTERP_API bool get_do_lighting (void) const; + OCTINTERP_API bool get_do_lighting () const; std::vector> m_coplanar_last_idx; @@ -5071,7 +5124,7 @@ END_PROPERTIES protected: - void init (void) + void init () { m_xdata.add_constraint (dim_vector (-1, -1)); m_ydata.add_constraint (dim_vector (-1, -1)); @@ -5127,15 +5180,15 @@ private: std::string m_bad_data_msg; - void update_faces (void) { update_data ();} - - void update_vertices (void) { update_data ();} - - void update_facevertexcdata (void) { update_data ();} - - OCTINTERP_API void update_fvc (void); - - void update_xdata (void) + void update_faces () { update_data ();} + + void update_vertices () { update_data ();} + + void update_facevertexcdata () { update_data ();} + + OCTINTERP_API void update_fvc (); + + void update_xdata () { if (get_xdata ().isempty ()) { @@ -5156,7 +5209,7 @@ set_xlim (m_xdata.get_limits ()); } - void update_ydata (void) + void update_ydata () { if (get_ydata ().isempty ()) { @@ -5174,14 +5227,14 @@ set_ylim (m_ydata.get_limits ()); } - void update_zdata (void) + void update_zdata () { update_fvc (); update_normals (true); set_zlim (m_zdata.get_limits ()); } - void update_cdata (void) + void update_cdata () { update_fvc (); update_normals (false); @@ -5192,33 +5245,33 @@ m_clim = m_cdata.get_limits (); } - OCTINTERP_API void update_data (void); + OCTINTERP_API void update_data (); OCTINTERP_API void calc_face_normals (Matrix& normals); OCTINTERP_API void update_face_normals (bool reset, bool force = false); OCTINTERP_API void update_vertex_normals (bool reset, bool force = false); - void update_edgelighting (void) + void update_edgelighting () { update_normals (false); } - void update_facelighting (void) + void update_facelighting () { update_normals (false); } - void update_facenormalsmode (void) + void update_facenormalsmode () { update_face_normals (false); } - void update_vertexnormalsmode (void) + void update_vertexnormalsmode () { update_vertex_normals (false); } - void update_visible (void) + void update_visible () { if (is_visible ()) update_normals (false); @@ -5234,13 +5287,15 @@ : base_graphics_object (), m_properties (mh, p) { } - ~patch (void) = default; - - base_properties& get_properties (void) { return m_properties; } - - const base_properties& get_properties (void) const { return m_properties; } - - bool valid_object (void) const { return true; } + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (patch) + + ~patch () = default; + + base_properties& get_properties () { return m_properties; } + + const base_properties& get_properties () const { return m_properties; } + + bool valid_object () const { return true; } bool has_readonly_property (const caseless_str& pname) const { @@ -5250,7 +5305,7 @@ return retval; } - OCTINTERP_API void reset_default_properties (void); + OCTINTERP_API void reset_default_properties (); protected: OCTINTERP_API void initialize (const graphics_object& go); @@ -5267,7 +5322,7 @@ { public: - OCTINTERP_API octave_value get_color_data (void) const; + OCTINTERP_API octave_value get_color_data () const; // Matlab allows incoherent data to be stored in scatter properties. // The scatter object should then be ignored by the renderer. @@ -5277,14 +5332,14 @@ return ! msg.empty (); } - bool is_aliminclude (void) const + bool is_aliminclude () const { return m_aliminclude.is_on (); } - std::string get_aliminclude (void) const + std::string get_aliminclude () const { return m_aliminclude.current_value (); } - bool is_climinclude (void) const + bool is_climinclude () const { return m_climinclude.is_on (); } - std::string get_climinclude (void) const + std::string get_climinclude () const { return m_climinclude.current_value (); } // See the genprops.awk script for an explanation of the @@ -5336,7 +5391,7 @@ END_PROPERTIES protected: - void init (void) + void init () { m_xdata.add_constraint (dim_vector (-1, 1)); m_xdata.add_constraint (dim_vector (1, -1)); @@ -5379,12 +5434,12 @@ } public: - OCTINTERP_API void update_color (void); + OCTINTERP_API void update_color (); private: std::string m_bad_data_msg; - void update_xdata (void) + void update_xdata () { if (get_xdata ().isempty ()) { @@ -5403,7 +5458,7 @@ update_data (); } - void update_ydata (void) + void update_ydata () { if (get_ydata ().isempty ()) { @@ -5420,19 +5475,19 @@ update_data (); } - void update_zdata (void) + void update_zdata () { set_zlim (m_zdata.get_limits ()); update_data (); } - void update_sizedata (void) + void update_sizedata () { update_data (); } - void update_cdata (void) + void update_cdata () { if (get_cdata ().matrix_value ().rows () == 1) set_clim (m_cdata.get_limits ()); @@ -5442,19 +5497,19 @@ update_data (); } - void update_cdatamode (void) + void update_cdatamode () { if (m_cdatamode.is ("auto")) update_color (); } - void update_seriesindex (void) + void update_seriesindex () { if (m_cdatamode.is ("auto")) update_color (); } - void update_data (void); + void update_data (); }; @@ -5470,13 +5525,15 @@ // object is added to the axes. } - ~scatter (void) = default; - - base_properties& get_properties (void) { return m_properties; } - - const base_properties& get_properties (void) const { return m_properties; } - - bool valid_object (void) const { return true; } + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (scatter) + + ~scatter () = default; + + base_properties& get_properties () { return m_properties; } + + const base_properties& get_properties () const { return m_properties; } + + bool valid_object () const { return true; } bool has_readonly_property (const caseless_str& pname) const { @@ -5501,19 +5558,19 @@ { public: - octave_value get_color_data (void) const; - - bool is_aliminclude (void) const + octave_value get_color_data () const; + + bool is_aliminclude () const { return (m_aliminclude.is_on () && m_alphadatamapping.is ("scaled")); } - std::string get_aliminclude (void) const + std::string get_aliminclude () const { return m_aliminclude.current_value (); } - bool is_climinclude (void) const + bool is_climinclude () const { return (m_climinclude.is_on () && m_cdatamapping.is ("scaled")); } - std::string get_climinclude (void) const + std::string get_climinclude () const { return m_climinclude.current_value (); } - OCTINTERP_API bool get_do_lighting (void) const; + OCTINTERP_API bool get_do_lighting () const; // See the genprops.awk script for an explanation of the // properties declarations. @@ -5570,7 +5627,7 @@ END_PROPERTIES protected: - void init (void) + void init () { m_xdata.add_constraint (dim_vector (-1, -1)); m_ydata.add_constraint (dim_vector (-1, -1)); @@ -5619,7 +5676,7 @@ private: - void update_alphadata (void) + void update_alphadata () { if (alphadatamapping_is ("scaled")) set_alim (m_alphadata.get_limits ()); @@ -5627,7 +5684,7 @@ m_alim = m_alphadata.get_limits (); } - void update_cdata (void) + void update_cdata () { if (cdatamapping_is ("scaled")) set_clim (m_cdata.get_limits ()); @@ -5635,19 +5692,19 @@ m_clim = m_cdata.get_limits (); } - void update_xdata (void) + void update_xdata () { update_normals (true); set_xlim (m_xdata.get_limits ()); } - void update_ydata (void) + void update_ydata () { update_normals (true); set_ylim (m_ydata.get_limits ()); } - void update_zdata (void) + void update_zdata () { update_normals (true); set_zlim (m_zdata.get_limits ()); @@ -5656,19 +5713,19 @@ OCTINTERP_API void update_face_normals (bool reset, bool force = false); OCTINTERP_API void update_vertex_normals (bool reset, bool force = false); - void update_facenormalsmode (void) + void update_facenormalsmode () { update_face_normals (false); } - void update_vertexnormalsmode (void) + void update_vertexnormalsmode () { update_vertex_normals (false); } - void update_edgelighting (void) + void update_edgelighting () { update_normals (false); } - void update_facelighting (void) + void update_facelighting () { update_normals (false); } - void update_visible (void) + void update_visible () { if (is_visible ()) update_normals (false); @@ -5684,13 +5741,15 @@ : base_graphics_object (), m_properties (mh, p) { } - ~surface (void) = default; - - base_properties& get_properties (void) { return m_properties; } - - const base_properties& get_properties (void) const { return m_properties; } - - bool valid_object (void) const { return true; } + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (surface) + + ~surface () = default; + + base_properties& get_properties () { return m_properties; } + + const base_properties& get_properties () const { return m_properties; } + + bool valid_object () const { return true; } bool has_readonly_property (const caseless_str& pname) const { @@ -5737,12 +5796,12 @@ END_PROPERTIES private: - OCTINTERP_API void update_limits (void) const; + OCTINTERP_API void update_limits () const; OCTINTERP_API void update_limits (const graphics_handle& h) const; protected: - void init (void) + void init () { } }; @@ -5755,13 +5814,15 @@ : base_graphics_object (), m_properties (mh, p) { } - ~hggroup (void) = default; - - base_properties& get_properties (void) { return m_properties; } - - const base_properties& get_properties (void) const { return m_properties; } - - bool valid_object (void) const { return true; } + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (hggroup) + + ~hggroup () = default; + + base_properties& get_properties () { return m_properties; } + + const base_properties& get_properties () const { return m_properties; } + + bool valid_object () const { return true; } OCTINTERP_API void update_axis_limits (const std::string& axis_type); @@ -5824,7 +5885,7 @@ END_PROPERTIES // Make "Label" an alias for "Text". - std::string get_label (void) const + std::string get_label () const { return get_text (); } @@ -5835,7 +5896,7 @@ } // Make "Callback" an alias for "MenuSelectedFcn". - octave_value get_callback (void) const + octave_value get_callback () const { return get_menuselectedfcn (); } @@ -5846,7 +5907,7 @@ } protected: - void init (void) + void init () { m_position.add_constraint ("min", 0, true); } @@ -5860,13 +5921,15 @@ : base_graphics_object (), m_properties (mh, p) { } - ~uimenu (void) = default; - - base_properties& get_properties (void) { return m_properties; } - - const base_properties& get_properties (void) const { return m_properties; } - - bool valid_object (void) const { return true; } + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (uimenu) + + ~uimenu () = default; + + base_properties& get_properties () { return m_properties; } + + const base_properties& get_properties () const { return m_properties; } + + bool valid_object () const { return true; } bool has_readonly_property (const caseless_str& pname) const { @@ -5894,7 +5957,7 @@ // FIXME: the list may contain duplicates. // Should we return only unique elements? - const std::list get_dependent_obj_list (void) + const std::list get_dependent_obj_list () { return m_dependent_obj_list; } // See the genprops.awk script for an explanation of the @@ -5910,7 +5973,7 @@ END_PROPERTIES protected: - void init (void) + void init () { m_position.add_constraint (dim_vector (1, 2)); m_position.add_constraint (dim_vector (2, 1)); @@ -5921,7 +5984,7 @@ // List of objects that might depend on this uicontextmenu object std::list m_dependent_obj_list; - OCTINTERP_API void update_beingdeleted (void); + OCTINTERP_API void update_beingdeleted (); }; @@ -5933,13 +5996,15 @@ : base_graphics_object (), m_properties (mh, p) { } - ~uicontextmenu (void) = default; - - base_properties& get_properties (void) { return m_properties; } - - const base_properties& get_properties (void) const { return m_properties; } - - bool valid_object (void) const { return true; } + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (uicontextmenu) + + ~uicontextmenu () = default; + + base_properties& get_properties () { return m_properties; } + + const base_properties& get_properties () const { return m_properties; } + + bool valid_object () const { return true; } bool has_readonly_property (const caseless_str& pname) const { @@ -6008,7 +6073,7 @@ std::string m_cached_units; protected: - void init (void) + void init () { m_cdata.add_constraint ("double"); m_cdata.add_constraint ("single"); @@ -6021,20 +6086,20 @@ m_cached_units = get_units (); } - OCTINTERP_API void update_text_extent (void); - - void update_string (void) { update_text_extent (); } - void update_fontname (void) { update_text_extent (); } - void update_fontsize (void) { update_text_extent (); } - void update_fontangle (void) + OCTINTERP_API void update_text_extent (); + + void update_string () { update_text_extent (); } + void update_fontname () { update_text_extent (); } + void update_fontsize () { update_text_extent (); } + void update_fontangle () { update_text_extent (); } - void update_fontweight (void) { update_text_extent (); } + void update_fontweight () { update_text_extent (); } OCTINTERP_API void update_fontunits (const caseless_str& old_units); - OCTINTERP_API void update_units (void); + OCTINTERP_API void update_units (); }; @@ -6046,13 +6111,15 @@ : base_graphics_object (), m_properties (mh, p) { } - ~uicontrol (void) = default; - - base_properties& get_properties (void) { return m_properties; } - - const base_properties& get_properties (void) const { return m_properties; } - - bool valid_object (void) const { return true; } + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (uicontrol) + + ~uicontrol () = default; + + base_properties& get_properties () { return m_properties; } + + const base_properties& get_properties () const { return m_properties; } + + bool valid_object () const { return true; } bool has_readonly_property (const caseless_str& pname) const { @@ -6119,19 +6186,19 @@ END_PROPERTIES protected: - void init (void) + void init () { m_position.add_constraint (dim_vector (1, 4)); m_borderwidth.add_constraint ("min", 0.0, true); m_fontsize.add_constraint ("min", 0.0, false); } - // void update_text_extent (void); - // void update_string (void) { update_text_extent (); } - // void update_fontname (void) { update_text_extent (); } - // void update_fontsize (void) { update_text_extent (); } - // void update_fontangle (void) { update_text_extent (); } - // void update_fontweight (void) { update_fontweight (); } + // void update_text_extent (); + // void update_string () { update_text_extent (); } + // void update_fontname () { update_text_extent (); } + // void update_fontsize () { update_text_extent (); } + // void update_fontangle () { update_text_extent (); } + // void update_fontweight () { update_fontweight (); } OCTINTERP_API void update_units (const caseless_str& old_units); OCTINTERP_API void update_fontunits (const caseless_str& old_units); @@ -6146,13 +6213,15 @@ : base_graphics_object (), m_properties (mh, p) { } - ~uibuttongroup (void) = default; - - base_properties& get_properties (void) { return m_properties; } - - const base_properties& get_properties (void) const { return m_properties; } - - bool valid_object (void) const { return true; } + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (uibuttongroup) + + ~uibuttongroup () = default; + + base_properties& get_properties () { return m_properties; } + + const base_properties& get_properties () const { return m_properties; } + + bool valid_object () const { return true; } bool has_readonly_property (const caseless_str& pname) const { @@ -6211,7 +6280,7 @@ END_PROPERTIES protected: - void init (void) + void init () { m_borderwidth.add_constraint ("min", 0.0, true); m_fontsize.add_constraint ("min", 0.0, false); @@ -6231,13 +6300,15 @@ : base_graphics_object (), m_properties (mh, p) { } - ~uipanel (void) = default; - - base_properties& get_properties (void) { return m_properties; } - - const base_properties& get_properties (void) const { return m_properties; } - - bool valid_object (void) const { return true; } + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (uipanel) + + ~uipanel () = default; + + base_properties& get_properties () { return m_properties; } + + const base_properties& get_properties () const { return m_properties; } + + bool valid_object () const { return true; } bool has_readonly_property (const caseless_str& pname) const { @@ -6303,14 +6374,14 @@ radio_property units S , "normalized|inches|centimeters|points|{pixels}|characters" END_PROPERTIES - OCTINTERP_API Matrix get_extent_matrix (void) const; - - OCTINTERP_API Matrix get_backgroundcolor_rgb (void); - - OCTINTERP_API Matrix get_alternatebackgroundcolor_rgb (void); + OCTINTERP_API Matrix get_extent_matrix () const; + + OCTINTERP_API Matrix get_backgroundcolor_rgb (); + + OCTINTERP_API Matrix get_alternatebackgroundcolor_rgb (); protected: - void init (void) + void init () { m_position.add_constraint (dim_vector (1, 4)); m_extent.add_constraint (dim_vector (1, 4)); @@ -6321,15 +6392,15 @@ OCTINTERP_API void update_units (const caseless_str& old_units); OCTINTERP_API void update_fontunits (const caseless_str& old_units); - void update_table_extent (void) { }; - void update_data (void) { update_table_extent (); } - void update_fontname (void) { update_table_extent (); } - void update_fontsize (void) { update_table_extent (); } - void update_fontangle (void) + void update_table_extent () { }; + void update_data () { update_table_extent (); } + void update_fontname () { update_table_extent (); } + void update_fontsize () { update_table_extent (); } + void update_fontangle () { update_table_extent (); } - void update_fontweight (void) { update_table_extent (); } + void update_fontweight () { update_table_extent (); } }; private: @@ -6340,13 +6411,15 @@ : base_graphics_object (), m_properties (mh, p) { } - ~uitable (void) { } - - base_properties& get_properties (void) { return m_properties; } - - const base_properties& get_properties (void) const { return m_properties; } - - bool valid_object (void) const { return true; } + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (uitable) + + ~uitable () = default; + + base_properties& get_properties () { return m_properties; } + + const base_properties& get_properties () const { return m_properties; } + + bool valid_object () const { return true; } bool has_readonly_property (const caseless_str& pname) const { @@ -6377,7 +6450,7 @@ END_PROPERTIES protected: - void init (void) + void init () { } }; @@ -6389,7 +6462,9 @@ : base_graphics_object (), m_properties (mh, p), m_default_properties () { } - ~uitoolbar (void) = default; + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (uitoolbar) + + ~uitoolbar () = default; void override_defaults (base_graphics_object& obj) { @@ -6430,23 +6505,23 @@ OCTINTERP_API octave_value get_default (const caseless_str& name) const; - octave_value get_defaults (void) const + octave_value get_defaults () const { return m_default_properties.as_struct ("default"); } - property_list get_defaults_list (void) const + property_list get_defaults_list () const { return m_default_properties; } - base_properties& get_properties (void) { return m_properties; } - - const base_properties& get_properties (void) const { return m_properties; } - - bool valid_object (void) const { return true; } - - OCTINTERP_API void reset_default_properties (void); + base_properties& get_properties () { return m_properties; } + + const base_properties& get_properties () const { return m_properties; } + + bool valid_object () const { return true; } + + OCTINTERP_API void reset_default_properties (); bool has_readonly_property (const caseless_str& pname) const { @@ -6487,7 +6562,7 @@ END_PROPERTIES protected: - void init (void) + void init () { m_cdata.add_constraint ("double"); m_cdata.add_constraint ("single"); @@ -6505,13 +6580,15 @@ : base_graphics_object (), m_properties (mh, p) { } - ~uipushtool (void) = default; - - base_properties& get_properties (void) { return m_properties; } - - const base_properties& get_properties (void) const { return m_properties; } - - bool valid_object (void) const { return true; } + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (uipushtool) + + ~uipushtool () = default; + + base_properties& get_properties () { return m_properties; } + + const base_properties& get_properties () const { return m_properties; } + + bool valid_object () const { return true; } bool has_readonly_property (const caseless_str& pname) const { @@ -6553,7 +6630,7 @@ END_PROPERTIES protected: - void init (void) + void init () { m_cdata.add_constraint ("double"); m_cdata.add_constraint ("single"); @@ -6571,13 +6648,15 @@ : base_graphics_object (), m_properties (mh, p) { } - ~uitoggletool (void) = default; - - base_properties& get_properties (void) { return m_properties; } - - const base_properties& get_properties (void) const { return m_properties; } - - bool valid_object (void) const { return true; } + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (uitoggletool) + + ~uitoggletool () = default; + + base_properties& get_properties () { return m_properties; } + + const base_properties& get_properties () const { return m_properties; } + + bool valid_object () const { return true; } bool has_readonly_property (const caseless_str& pname) const { @@ -6611,7 +6690,7 @@ friend class graphics_event; - base_graphics_event (void) + base_graphics_event () : m_busyaction (QUEUE) { }; @@ -6619,11 +6698,13 @@ : m_busyaction (busyaction) { }; - virtual ~base_graphics_event (void) = default; - - int get_busyaction (void) { return m_busyaction; }; - - virtual void execute (void) = 0; + OCTAVE_DEFAULT_COPY_MOVE (base_graphics_event) + + virtual ~base_graphics_event () = default; + + int get_busyaction () { return m_busyaction; }; + + virtual void execute () = 0; private: int m_busyaction; @@ -6637,17 +6718,17 @@ typedef void (*event_fcn) (void *); - graphics_event (void) = default; + graphics_event () = default; graphics_event (base_graphics_event *new_rep) : m_rep (new_rep) { } graphics_event (const graphics_event&) = default; - ~graphics_event (void) = default; + ~graphics_event () = default; graphics_event& operator = (const graphics_event&) = default; - int get_busyaction (void) + int get_busyaction () { if (ok ()) return m_rep->get_busyaction (); @@ -6655,13 +6736,13 @@ error ("graphics_event::busyaction: invalid graphics_event"); } - void execute (void) + void execute () { if (ok ()) m_rep->execute (); } - bool ok (void) const { return (m_rep != nullptr); } + bool ok () const { return (m_rep != nullptr); } static OCTINTERP_API graphics_event create_callback_event (const graphics_handle& h, @@ -6691,255 +6772,10 @@ std::shared_ptr m_rep; }; -class OCTINTERP_API gh_manager -{ -public: - - typedef std::pair latex_data; - - OCTINTERP_API gh_manager (octave::interpreter& interp); - - // FIXME: eventually eliminate these static functions and access - // gh_manager object through the interpreter. - - OCTINTERP_API graphics_handle get_handle (bool integer_figure_handle); - - OCTINTERP_API void free (const graphics_handle& h, bool from_root = false); - - OCTINTERP_API void renumber_figure (const graphics_handle& old_gh, - const graphics_handle& new_gh); - - graphics_handle lookup (double val) const - { - const_iterator p = (octave::math::isnan (val) - ? m_handle_map.end () : m_handle_map.find (val)); - - return (p != m_handle_map.end ()) ? p->first : graphics_handle (); - } - - graphics_handle lookup (const octave_value& val) const - { - return (val.is_real_scalar () - ? lookup (val.double_value ()) : graphics_handle ()); - } - - graphics_object get_object (double val) const - { - return get_object (lookup (val)); - } - - graphics_object get_object (const graphics_handle& h) const - { - const_iterator p = (h.ok () ? m_handle_map.find (h) : m_handle_map.end ()); - - return (p != m_handle_map.end ()) ? p->second : graphics_object (); - } - - OCTINTERP_API graphics_handle - make_graphics_handle (const std::string& go_name, - const graphics_handle& p, - bool integer_figure_handle = false, - bool call_createfcn = true, - bool notify_toolkit = true); - - OCTINTERP_API graphics_handle - make_figure_handle (double val, bool notify_toolkit = true); - - OCTINTERP_API void push_figure (const graphics_handle& h); - - OCTINTERP_API void pop_figure (const graphics_handle& h); - - graphics_handle current_figure (void) const - { - graphics_handle retval; - - for (const auto& hfig : m_figure_list) - { - if (is_handle_visible (hfig)) - retval = hfig; - } - - return retval; - } - - Matrix handle_list (bool show_hidden = false) - { - Matrix retval (1, m_handle_map.size ()); - - octave_idx_type i = 0; - for (const auto& h_iter : m_handle_map) - { - graphics_handle h = h_iter.first; - - if (show_hidden || is_handle_visible (h)) - retval(i++) = h.value (); - } - - retval.resize (1, i); - - return retval; - } - - void lock (void) { m_graphics_lock.lock (); } - - bool try_lock (void) { return m_graphics_lock.try_lock (); } - - void unlock (void) { m_graphics_lock.unlock (); } - - Matrix figure_handle_list (bool show_hidden = false) - { - Matrix retval (1, m_figure_list.size ()); - - octave_idx_type i = 0; - for (const auto& hfig : m_figure_list) - { - if (show_hidden || is_handle_visible (hfig)) - retval(i++) = hfig.value (); - } - - retval.resize (1, i); - - return retval; - } - - OCTINTERP_API void - execute_listener (const graphics_handle& h, const octave_value& l); - - void execute_callback (const graphics_handle& h, - const std::string& name, - const octave_value& data = Matrix ()) - { - octave_value cb; - - if (true) - { - octave::autolock guard (graphics_lock ()); - - graphics_object go = get_object (h); - - if (go.valid_object ()) - cb = go.get (name); - } - - execute_callback (h, cb, data); - } - - OCTINTERP_API void - execute_callback (const graphics_handle& h, const octave_value& cb, - const octave_value& data = Matrix ()); - - OCTINTERP_API void - post_callback (const graphics_handle& h, const std::string& name, - const octave_value& data = Matrix ()); - - OCTINTERP_API void - post_function (graphics_event::event_fcn fcn, void *fcn_data = nullptr); - - OCTINTERP_API void - post_set (const graphics_handle& h, const std::string& name, - const octave_value& value, bool notify_toolkit = true, - bool redraw_figure = false); - - OCTINTERP_API int process_events (bool force = false); - - OCTINTERP_API void enable_event_processing (bool enable = true); - - bool is_handle_visible (const graphics_handle& h) const - { - bool retval = false; - - graphics_object go = get_object (h); - - if (go.valid_object ()) - retval = go.is_handle_visible (); - - return retval; - } - - OCTINTERP_API void close_all_figures (void); - - OCTINTERP_API void restore_gcbo (void); - - OCTINTERP_API void post_event (const graphics_event& e); - - octave::mutex graphics_lock (void) - { - return m_graphics_lock; - } - - latex_data get_latex_data (const std::string& key) const - { - latex_data retval; - - const auto it = m_latex_cache.find (key); - - if (it != m_latex_cache.end ()) - retval = it->second; - - return retval; - } - - void set_latex_data (const std::string& key, latex_data val) - { - // Limit the number of cache entries to 500 - if (m_latex_keys.size () >= 500) - { - auto it = m_latex_cache.find (m_latex_keys.front ()); - - if (it != m_latex_cache.end ()) - m_latex_cache.erase (it); - - m_latex_keys.pop_front (); - } - - m_latex_cache[key] = val; - m_latex_keys.push_back (key); - } - -private: - - typedef std::map::iterator iterator; - typedef std::map::const_iterator - const_iterator; - - typedef std::set::iterator free_list_iterator; - typedef std::set::const_iterator const_free_list_iterator; - - typedef std::list::iterator figure_list_iterator; - typedef std::list::const_iterator const_figure_list_iterator; - - octave::interpreter& m_interpreter; - - // A map of handles to graphics objects. - std::map m_handle_map; - - // The available graphics handles. - std::set m_handle_free_list; - - // The next handle available if m_handle_free_list is empty. - double m_next_handle; - - // The allocated figure handles. Top of the stack is most recently - // created. - std::list m_figure_list; - - // The lock for accessing the graphics sytsem. - octave::mutex m_graphics_lock; - - // The list of events queued by graphics toolkits. - std::list m_event_queue; - - // The stack of callback objects. - std::list m_callback_objects; - - // A flag telling whether event processing must be constantly on. - int m_event_processing; - - // Cache of already parsed latex strings. Store a separate list of keys - // to allow for erasing oldest entries if cache size becomes too large. - std::unordered_map m_latex_cache; - std::list m_latex_keys; -}; +OCTINTERP_API base_graphics_object * +make_graphics_object_from_type (const caseless_str& type, + const graphics_handle& h = graphics_handle (), + const graphics_handle& p = graphics_handle ()); OCTINTERP_API void get_children_limits (double& min_val, double& max_val, @@ -6949,173 +6785,13 @@ OCTINTERP_API int calc_dimensions (const graphics_object& gh); // This function is NOT equivalent to the scripting language function gcf. -OCTINTERP_API graphics_handle gcf (void); +OCTINTERP_API graphics_handle gcf (); // This function is NOT equivalent to the scripting language function gca. -OCTINTERP_API graphics_handle gca (void); - -OCTINTERP_API void close_all_figures (void); +OCTINTERP_API graphics_handle gca (); + +OCTINTERP_API void close_all_figures (); OCTAVE_END_NAMESPACE(octave) -#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS) - -OCTAVE_DEPRECATED (7, "use 'octave::base_scaler' instead") -typedef octave::base_scaler base_scaler; - -OCTAVE_DEPRECATED (7, "use 'octave::lin_scaler' instead") -typedef octave::lin_scaler lin_scaler; - -OCTAVE_DEPRECATED (7, "use 'octave::log_scaler' instead") -typedef octave::log_scaler log_scaler; - -OCTAVE_DEPRECATED (7, "use 'octave::neg_log_scaler' instead") -typedef octave::neg_log_scaler neg_log_scaler; - -OCTAVE_DEPRECATED (7, "use 'octave::scaler' instead") -typedef octave::scaler scaler; - -OCTAVE_DEPRECATED (7, "use 'octave::base_property' instead") -typedef octave::base_property base_property; - -OCTAVE_DEPRECATED (7, "use 'octave::string_property' instead") -typedef octave::string_property string_property; - -OCTAVE_DEPRECATED (7, "use 'octave::string_array_property' instead") -typedef octave::string_array_property string_array_property; - -OCTAVE_DEPRECATED (7, "use 'octave::text_label_property' instead") -typedef octave::text_label_property text_label_property; - -OCTAVE_DEPRECATED (7, "use 'octave::radio_values' instead") -typedef octave::radio_values radio_values; - -OCTAVE_DEPRECATED (7, "use 'octave::radio_property' instead") -typedef octave::radio_property radio_property; - -OCTAVE_DEPRECATED (7, "use 'octave::color_values' instead") -typedef octave::color_values color_values; - -OCTAVE_DEPRECATED (7, "use 'octave::color_property' instead") -typedef octave::color_property color_property; - -OCTAVE_DEPRECATED (7, "use 'octave::double_property' instead") -typedef octave::double_property double_property; - -OCTAVE_DEPRECATED (7, "use 'octave::double_radio_property' instead") -typedef octave::double_radio_property double_radio_property; - -OCTAVE_DEPRECATED (7, "use 'octave::array_property' instead") -typedef octave::array_property array_property; - -OCTAVE_DEPRECATED (7, "use 'octave::row_vector_property' instead") -typedef octave::row_vector_property row_vector_property; - -OCTAVE_DEPRECATED (7, "use 'octave::bool_property' instead") -typedef octave::bool_property bool_property; - -OCTAVE_DEPRECATED (7, "use 'octave::handle_property' instead") -typedef octave::handle_property handle_property; - -OCTAVE_DEPRECATED (7, "use 'octave::any_property' instead") -typedef octave::any_property any_property; - -OCTAVE_DEPRECATED (7, "use 'octave::children_property' instead") -typedef octave::children_property children_property; - -OCTAVE_DEPRECATED (7, "use 'octave::callback_property' instead") -typedef octave::callback_property callback_property; - -OCTAVE_DEPRECATED (7, "use 'octave::property' instead") -typedef octave::property property; - -OCTAVE_DEPRECATED (7, "use 'octave::pval_vector' instead") -typedef octave::pval_vector pval_vector; - -OCTAVE_DEPRECATED (7, "use 'octave::property_list' instead") -typedef octave::property_list property_list; - -OCTAVE_DEPRECATED (7, "use 'octave::base_properties' instead") -typedef octave::base_properties base_properties; - -OCTAVE_DEPRECATED (7, "use 'octave::base_graphics_object' instead") -typedef octave::base_graphics_object base_graphics_object; - -OCTAVE_DEPRECATED (7, "use 'octave::graphics_object' instead") -typedef octave::graphics_object graphics_object; - -OCTAVE_DEPRECATED (7, "use 'octave::root_figure' instead") -typedef octave::root_figure root_figure; - -OCTAVE_DEPRECATED (7, "use 'octave::figure' instead") -typedef octave::figure figure; - -OCTAVE_DEPRECATED (7, "use 'octave::graphics_xform' instead") -typedef octave::graphics_xform graphics_xform; - -OCTAVE_DEPRECATED (7, "use 'octave::axes' instead") -typedef octave::axes axes; - -OCTAVE_DEPRECATED (7, "use 'octave::line' instead") -typedef octave::line line; - -OCTAVE_DEPRECATED (7, "use 'octave::text' instead") -typedef octave::text text; - -OCTAVE_DEPRECATED (7, "use 'octave::image' instead") -typedef octave::image image; - -OCTAVE_DEPRECATED (7, "use 'octave::light' instead") -typedef octave::light light; - -OCTAVE_DEPRECATED (7, "use 'octave::patch' instead") -typedef octave::patch patch; - -OCTAVE_DEPRECATED (7, "use 'octave::scatter' instead") -typedef octave::scatter scatter; - -OCTAVE_DEPRECATED (7, "use 'octave::surface' instead") -typedef octave::surface surface; - -OCTAVE_DEPRECATED (7, "use 'octave::hggroup' instead") -typedef octave::hggroup hggroup; - -OCTAVE_DEPRECATED (7, "use 'octave::uimenu' instead") -typedef octave::uimenu uimenu; - -OCTAVE_DEPRECATED (7, "use 'octave::uicontextmenu' instead") -typedef octave::uicontextmenu uicontextmenu; - -OCTAVE_DEPRECATED (7, "use 'octave::uicontrol' instead") -typedef octave::uicontrol uicontrol; - -OCTAVE_DEPRECATED (7, "use 'octave::uibuttongroup' instead") -typedef octave::uibuttongroup uibuttongroup; - -OCTAVE_DEPRECATED (7, "use 'octave::uipanel' instead") -typedef octave::uipanel uipanel; - -OCTAVE_DEPRECATED (7, "use 'octave::uitable' instead") -typedef octave::uitable uitable; - -OCTAVE_DEPRECATED (7, "use 'octave::uitoolbar' instead") -typedef octave::uitoolbar uitoolbar; - -OCTAVE_DEPRECATED (7, "use 'octave::uipushtool' instead") -typedef octave::uipushtool uipushtool; - -OCTAVE_DEPRECATED (7, "use 'octave::uitoggletool' instead") -typedef octave::uitoggletool uitoggletool; - -OCTAVE_DEPRECATED (7, "use 'octave::base_graphics_event' instead") -typedef octave::base_graphics_event base_graphics_event; - -OCTAVE_DEPRECATED (7, "use 'octave::graphics_event' instead") -typedef octave::graphics_event graphics_event; - -OCTAVE_DEPRECATED (7, "use 'octave::gh_manager' instead") -typedef octave::gh_manager gh_manager; - #endif - -#endif diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/gtk-manager.cc --- a/libinterp/corefcn/gtk-manager.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/gtk-manager.cc Fri May 12 08:03:14 2023 +0200 @@ -28,15 +28,15 @@ #endif #include "error.h" +#include "interpreter.h" #include "graphics-toolkit.h" #include "gtk-manager.h" #include "ovl.h" -#include "parse.h" OCTAVE_BEGIN_NAMESPACE(octave) graphics_toolkit -gtk_manager::get_toolkit (void) const +gtk_manager::get_toolkit () const { graphics_toolkit retval; @@ -55,7 +55,7 @@ octave_value_list args; args(0) = m_dtk; - feval ("graphics_toolkit", args); + m_interpreter.feval ("graphics_toolkit", args); pl = m_loaded_toolkits.find (m_dtk); diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/gtk-manager.h --- a/libinterp/corefcn/gtk-manager.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/gtk-manager.h Fri May 12 08:03:14 2023 +0200 @@ -37,18 +37,22 @@ OCTAVE_BEGIN_NAMESPACE(octave) +class interpreter; + class OCTINTERP_API gtk_manager { public: - gtk_manager (void) { } + gtk_manager (interpreter& interp) : m_interpreter (interp) { } - ~gtk_manager (void) + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (gtk_manager) + + ~gtk_manager () { unload_all_toolkits (); } - graphics_toolkit get_toolkit (void) const; + graphics_toolkit get_toolkit () const; void register_toolkit (const std::string& name); @@ -74,7 +78,7 @@ return graphics_toolkit (); } - Cell available_toolkits_list (void) const + Cell available_toolkits_list () const { Cell m (1, m_available_toolkits.size ()); @@ -85,7 +89,7 @@ return m; } - Cell loaded_toolkits_list (void) const + Cell loaded_toolkits_list () const { Cell m (1, m_loaded_toolkits.size ()); @@ -96,7 +100,7 @@ return m; } - void unload_all_toolkits (void) + void unload_all_toolkits () { while (! m_loaded_toolkits.empty ()) { @@ -112,10 +116,12 @@ } } - std::string default_toolkit (void) const { return m_dtk; } + std::string default_toolkit () const { return m_dtk; } private: + interpreter& m_interpreter; + // The name of the default toolkit. std::string m_dtk; diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/gzfstream.h --- a/libinterp/corefcn/gzfstream.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/gzfstream.h Fri May 12 08:03:14 2023 +0200 @@ -58,11 +58,7 @@ // Default constructor. gzfilebuf (); - // No copying! - - gzfilebuf (const gzfilebuf&) = delete; - - gzfilebuf& operator = (const gzfilebuf&) = delete; + OCTAVE_DISABLE_COPY_MOVE (gzfilebuf) // Destructor. virtual ~gzfilebuf (); @@ -469,11 +465,11 @@ private: // Underlying manipulator function gzofstream& - (*fcn)(gzofstream&, T1, T2); + (*m_fcn)(gzofstream&, T1, T2); // Arguments for manipulator function - T1 val1; - T2 val2; + T1 m_val1; + T2 m_val2; }; // Manipulator function thunks through to stream buffer @@ -490,14 +486,14 @@ gzomanip2::gzomanip2 (gzofstream &(*f)(gzofstream&, T1, T2), T1 v1, T2 v2) - : fcn(f), val1(v1), val2(v2) + : m_fcn(f), m_val1(v1), m_val2(v2) { } // Insertor applies underlying manipulator function to stream template inline gzofstream& operator<<(gzofstream& s, const gzomanip2& m) -{ return (*m.fcn)(s, m.val1, m.val2); } +{ return (*m.m_fcn)(s, m.m_val1, m.m_val2); } // Insert this onto stream to simplify setting of compression level inline gzomanip2 diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/help.cc --- a/libinterp/corefcn/help.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/help.cc Fri May 12 08:03:14 2023 +0200 @@ -320,7 +320,7 @@ return which (name, type); } -string_vector help_system::make_name_list (void) const +string_vector help_system::make_name_list () const { const static string_vector keywords = Fiskeyword ()(0).string_vector_value (); @@ -447,7 +447,7 @@ } } -std::string help_system::init_built_in_docstrings_file (void) +std::string help_system::init_built_in_docstrings_file () { std::string df = sys::env::getenv ("OCTAVE_BUILT_IN_DOCSTRINGS_FILE"); @@ -459,7 +459,7 @@ return df; } -std::string help_system::init_doc_cache_file (void) +std::string help_system::init_doc_cache_file () { std::string def_file = config::prepend_octave_home (OCTAVE_DOC_CACHE_FILE); @@ -468,7 +468,7 @@ return (env_file.empty () ? def_file : env_file); } -std::string help_system::init_info_file (void) +std::string help_system::init_info_file () { std::string std_info_file = config::prepend_octave_home (OCTAVE_INFOFILE); @@ -477,7 +477,7 @@ return (oct_info_file.empty () ? std_info_file : oct_info_file); } -std::string help_system::init_info_program (void) +std::string help_system::init_info_program () { std::string info_prog = sys::env::getenv ("OCTAVE_INFO_PROGRAM"); @@ -487,7 +487,7 @@ return info_prog; } -std::string help_system::init_texi_macros_file (void) +std::string help_system::init_texi_macros_file () { std::string def_file = config::prepend_octave_home (OCTAVE_TEXI_MACROS_FILE); @@ -499,7 +499,7 @@ // Return a vector of all functions from this file, // for use in command line auto-completion. -string_vector help_system::local_functions (void) const +string_vector help_system::local_functions () const { string_vector retval; @@ -725,7 +725,7 @@ // FIXME: It's not likely that this does the right thing now. -string_vector make_name_list (void) +string_vector make_name_list () { help_system& help_sys = __get_help_system__ (); diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/help.h --- a/libinterp/corefcn/help.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/help.h Fri May 12 08:03:14 2023 +0200 @@ -59,7 +59,7 @@ built_in_docstrings_file (const octave_value_list& args, int nargout); std::string - built_in_docstrings_file (void) const { return m_built_in_docstrings_file; } + built_in_docstrings_file () const { return m_built_in_docstrings_file; } std::string built_in_docstrings_file (const std::string& file) { @@ -68,7 +68,7 @@ octave_value doc_cache_file (const octave_value_list& args, int nargout); - std::string doc_cache_file (void) const { return m_doc_cache_file; } + std::string doc_cache_file () const { return m_doc_cache_file; } std::string doc_cache_file (const std::string& file) { @@ -77,7 +77,7 @@ octave_value info_file (const octave_value_list& args, int nargout); - std::string info_file (void) const { return m_info_file; } + std::string info_file () const { return m_info_file; } std::string info_file (const std::string& file) { @@ -86,7 +86,7 @@ octave_value info_program (const octave_value_list& args, int nargout); - std::string info_program (void) const { return m_info_program; } + std::string info_program () const { return m_info_program; } std::string info_program (const std::string& file) { @@ -95,7 +95,7 @@ octave_value makeinfo_program (const octave_value_list& args, int nargout); - std::string makeinfo_program (void) const { return m_makeinfo_program; } + std::string makeinfo_program () const { return m_makeinfo_program; } std::string makeinfo_program (const std::string& file) { @@ -105,7 +105,7 @@ octave_value suppress_verbose_help_message (const octave_value_list& args, int nargout); - bool suppress_verbose_help_message (void) const + bool suppress_verbose_help_message () const { return m_suppress_verbose_help_message; } @@ -117,7 +117,7 @@ octave_value texi_macros_file (const octave_value_list& args, int nargout); - std::string texi_macros_file (void) const { return m_texi_macros_file; } + std::string texi_macros_file () const { return m_texi_macros_file; } std::string texi_macros_file (const std::string& file) { @@ -129,7 +129,7 @@ std::string which (const std::string& name) const; std::string which (const std::string& name, std::string& type) const; - string_vector make_name_list (void) const; + string_vector make_name_list () const; void get_help_text (const std::string& name, std::string& text, std::string& format) const; @@ -169,15 +169,15 @@ // (--texi-macros-file) std::string m_texi_macros_file; - static std::string init_built_in_docstrings_file (void); + static std::string init_built_in_docstrings_file (); - static std::string init_doc_cache_file (void); + static std::string init_doc_cache_file (); - static std::string init_info_file (void); + static std::string init_info_file (); - static std::string init_info_program (void); + static std::string init_info_program (); - static std::string init_texi_macros_file (void); + static std::string init_texi_macros_file (); template T set (T& var, const T& new_val) @@ -187,7 +187,7 @@ return old_val; } - string_vector local_functions (void) const; + string_vector local_functions () const; bool raw_help_from_symbol_table (const std::string& nm, std::string& h, std::string& w, @@ -201,7 +201,7 @@ bool& symbol_found) const; }; -extern string_vector make_name_list (void); +extern string_vector make_name_list (); OCTAVE_END_NAMESPACE(octave) diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/hook-fcn.cc --- a/libinterp/corefcn/hook-fcn.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/hook-fcn.cc Fri May 12 08:03:14 2023 +0200 @@ -28,7 +28,8 @@ #endif #include "hook-fcn.h" -#include "parse.h" +#include "interpreter-private.h" +#include "interpreter.h" OCTAVE_BEGIN_NAMESPACE(octave) @@ -55,7 +56,9 @@ if (m_data.is_defined ()) args.append (m_data); - feval (m_name, args, 0); + interpreter& interp = __get_interpreter__ (); + + interp.feval (m_name, args, 0); } void fcn_handle_hook_function::eval (const octave_value_list& initial_args) @@ -65,7 +68,9 @@ if (m_data.is_defined ()) args.append (m_data); - feval (m_fcn_handle, args, 0); + interpreter& interp = __get_interpreter__ (); + + interp.feval (m_fcn_handle, args, 0); } OCTAVE_END_NAMESPACE(octave) diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/hook-fcn.h --- a/libinterp/corefcn/hook-fcn.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/hook-fcn.h Fri May 12 08:03:14 2023 +0200 @@ -42,15 +42,13 @@ { public: - base_hook_function (void) = default; + OCTAVE_DEFAULT_CONSTRUCT_COPY (base_hook_function) - base_hook_function (const base_hook_function&) = default; + virtual ~base_hook_function () = default; - virtual ~base_hook_function (void) = default; + virtual std::string id () const { return ""; } - virtual std::string id (void) const { return ""; } - - virtual bool is_valid (void) const { return false; } + virtual bool is_valid () const { return false; } virtual void eval (const octave_value_list&) { } }; @@ -59,7 +57,7 @@ { public: - hook_function (void) + hook_function () { static std::shared_ptr nil_rep (new base_hook_function ()); @@ -70,15 +68,13 @@ hook_function (const octave_value& f, const octave_value& d = octave_value ()); - ~hook_function (void) = default; + OCTAVE_DEFAULT_COPY (hook_function) - hook_function (const hook_function& hf) = default; + ~hook_function () = default; - hook_function& operator = (const hook_function& hf) = default; + std::string id () const { return m_rep->id (); } - std::string id (void) const { return m_rep->id (); } - - bool is_valid (void) const { return m_rep->is_valid (); } + bool is_valid () const { return m_rep->is_valid (); } void eval (const octave_value_list& initial_args) { @@ -94,15 +90,19 @@ { public: + named_hook_function () = delete; + named_hook_function (const std::string& n, const octave_value& d) : m_name (n), m_data (d) { } + OCTAVE_DEFAULT_COPY_DELETE (named_hook_function) + void eval (const octave_value_list& initial_args); - std::string id (void) const { return m_name; } + std::string id () const { return m_name; } - bool is_valid (void) const { return is_valid_function (m_name); } + bool is_valid () const { return is_valid_function (m_name); } private: @@ -115,6 +115,8 @@ { public: + fcn_handle_hook_function () = delete; + fcn_handle_hook_function (const octave_value& fh_arg, const octave_value& d) : m_ident (), m_valid (false), m_fcn_handle (fh_arg), m_data (d) { @@ -130,11 +132,13 @@ } } + OCTAVE_DEFAULT_COPY_DELETE (fcn_handle_hook_function) + void eval (const octave_value_list& initial_args); - std::string id (void) const { return m_ident; } + std::string id () const { return m_ident; } - bool is_valid (void) const { return m_valid; } + bool is_valid () const { return m_valid; } private: @@ -156,17 +160,11 @@ typedef map_type::iterator iterator; typedef map_type::const_iterator const_iterator; - hook_function_list (void) = default; - - ~hook_function_list (void) = default; - - hook_function_list (const hook_function_list& lst) = default; + OCTAVE_DEFAULT_CONSTRUCT_COPY_DELETE (hook_function_list) - hook_function_list& operator = (const hook_function_list& lst) = default; + bool empty () const { return m_fcn_map.empty (); } - bool empty (void) const { return m_fcn_map.empty (); } - - void clear (void) { m_fcn_map.clear (); } + void clear () { m_fcn_map.clear (); } void insert (const std::string& id, const hook_function& f) { @@ -183,9 +181,9 @@ return m_fcn_map.find (id); } - iterator end (void) { return m_fcn_map.end (); } + iterator end () { return m_fcn_map.end (); } - const_iterator end (void) const { return m_fcn_map.end (); } + const_iterator end () const { return m_fcn_map.end (); } void erase (iterator p) { m_fcn_map.erase (p); } @@ -214,21 +212,4 @@ OCTAVE_END_NAMESPACE(octave) -#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS) -OCTAVE_DEPRECATED (7, "use 'octave::base_hook_function' instead") -typedef octave::base_hook_function base_hook_function; - -OCTAVE_DEPRECATED (7, "use 'octave::hook_function' instead") -typedef octave::hook_function hook_function; - -OCTAVE_DEPRECATED (7, "use 'octave::named_hook_function' instead") -typedef octave::named_hook_function named_hook_function; - -OCTAVE_DEPRECATED (7, "use 'octave::fcn_handle_hook_function' instead") -typedef octave::fcn_handle_hook_function fcn_handle_hook_function; - -OCTAVE_DEPRECATED (7, "use 'octave::hook_function_list' instead") -typedef octave::hook_function_list hook_function_list; #endif - -#endif diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/input.cc --- a/libinterp/corefcn/input.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/input.cc Fri May 12 08:03:14 2023 +0200 @@ -70,7 +70,6 @@ #include "ov-fcn-handle.h" #include "ov-usr-fcn.h" #include "pager.h" -#include "parse.h" #include "pt-eval.h" #include "pt-stmt.h" #include "sighandlers.h" @@ -259,7 +258,7 @@ } static bool -is_completing_dirfns (void) +is_completing_dirfns () { static std::string dirfns_commands[] = {"cd", "isfile", "isfolder", "ls"}; static const std::size_t dirfns_commands_length = 4; @@ -386,7 +385,7 @@ return retval; } -static int internal_input_event_hook_fcn (void) +static int internal_input_event_hook_fcn () { octave_quit (); @@ -489,7 +488,7 @@ octave_value retval = set_internal_variable (m_mfile_encoding, args, nargout, - "__mfile_encoding__"); + "mfile_encoding"); // Additional validation if the encoding has changed. @@ -516,10 +515,10 @@ { m_mfile_encoding = saved_encoding; if (errno == EINVAL) - error ("__mfile_encoding__: conversion from encoding '%s' " + error ("mfile_encoding: conversion from encoding '%s' " "not supported", encoding.c_str ()); else - error ("__mfile_encoding__: error %d opening encoding '%s'", + error ("mfile_encoding: error %d opening encoding '%s'", errno, encoding.c_str ()); } else @@ -529,8 +528,7 @@ } // Synchronize the related gui preference for editor encoding - feval ("__event_manager_gui_preference__", - ovl ("editor/default_encoding", m_mfile_encoding)); + F__event_manager_gui_preference__ (m_interpreter, ovl ("editor/default_encoding", m_mfile_encoding)); return retval; } @@ -747,7 +745,7 @@ return retval; } -bool input_system::have_input_event_hooks (void) const +bool input_system::have_input_event_hooks () const { return ! m_input_event_hook_functions.empty (); } @@ -769,12 +767,12 @@ return true; } -void input_system::clear_input_event_hooks (void) +void input_system::clear_input_event_hooks () { m_input_event_hook_functions.clear (); } -void input_system::run_input_event_hooks (void) +void input_system::run_input_event_hooks () { m_input_event_hook_functions.run (); } @@ -889,9 +887,9 @@ std::string get_input (const std::string& prompt, bool& eof); - std::string input_source (void) const { return s_in_src; } + std::string input_source () const { return s_in_src; } - bool input_from_terminal (void) const { return true; } + bool input_from_terminal () const { return true; } private: @@ -918,9 +916,9 @@ std::string get_input (const std::string& prompt, bool& eof); - std::string input_source (void) const { return s_in_src; } + std::string input_source () const { return s_in_src; } - bool input_from_file (void) const { return true; } + bool input_from_file () const { return true; } private: @@ -942,9 +940,9 @@ std::string get_input (const std::string& prompt, bool& eof); - std::string input_source (void) const { return s_in_src; } + std::string input_source () const { return s_in_src; } - bool input_from_eval_string (void) const { return true; } + bool input_from_eval_string () const { return true; } private: @@ -1444,8 +1442,7 @@ if (nargin < 1 || nargin > 2) print_usage (); - std::string hook_fcn_id = args( - 0).xstring_value ("remove_input_event_hook: argument not valid as a hook function name or id"); + std::string hook_fcn_id = args(0).xstring_value ("remove_input_event_hook: argument not valid as a hook function name or id"); bool warn = (nargin < 2); @@ -1497,9 +1494,7 @@ @seealso{PS2, PS4} @end deftypefn */) { - input_system& input_sys = interp.get_input_system (); - - return input_sys.PS1 (args, nargout); + return interp.PS1 (args, nargout); } DEFMETHOD (PS2, interp, args, nargout, @@ -1521,9 +1516,7 @@ @seealso{PS1, PS4} @end deftypefn */) { - input_system& input_sys = interp.get_input_system (); - - return input_sys.PS2 (args, nargout); + return interp.PS2 (args, nargout); } DEFMETHOD (completion_append_char, interp, args, nargout, @@ -1577,14 +1570,31 @@ return input_sys.gud_mode (args, nargout); } -DEFMETHOD (__mfile_encoding__, interp, args, nargout, +DEFMETHOD (mfile_encoding, interp, args, nargout, doc: /* -*- texinfo -*- -@deftypefn {} {@var{current_encoding} =} __mfile_encoding__ () -@deftypefnx {} {} __mfile_encoding__ (@var{new_encoding}) -@deftypefnx {} {@var{old_encoding} =} __mfile_encoding__ (@var{new_encoding}) -Query or set the codepage that is used for reading m-files. +@deftypefn {} {@var{current_encoding} =} mfile_encoding () +@deftypefnx {} {} mfile_encoding (@var{new_encoding}) +@deftypefnx {} {@var{old_encoding} =} mfile_encoding (@var{new_encoding}) +Query or set the encoding that is used for reading m-files. + +The input and output are strings naming an encoding, e.g., "utf-8". + +This encoding is used by Octave's parser when reading m-files unless a +different encoding was set for a specific directory containing m-files using +the function @code{dir_encoding} or in a file @file{.oct-config} in that +directory. -The input and output are strings naming a particular codepage, e.g., "utf-8". +The special value @qcode{"system"} selects the encoding that matches the system +locale. + +If the m-file encoding is changed after the m-files have already been parsed, +the files have to be parsed again for that change to take effect. That can be +triggered with the command @code{clear all}. + +Additionally, this encoding is used to load and save files with the built-in +editor in Octave's GUI. + +@seealso{dir_encoding} @end deftypefn */) { input_system& input_sys = interp.get_input_system (); @@ -1592,6 +1602,8 @@ return input_sys.mfile_encoding (args, nargout); } +DEFALIAS (__mfile_encoding__, mfile_encoding); + DEFMETHOD (dir_encoding, interp, args, nargout, doc: /* -*- texinfo -*- @deftypefn {} {@var{current_encoding} =} dir_encoding (@var{dir}) @@ -1600,7 +1612,8 @@ @deftypefnx {} {@var{old_encoding} =} dir_encoding (@var{dir}, @var{new_encoding}) Query or set the @var{encoding} that is used for reading m-files in @var{dir}. -The per-directory encoding overrides the (globally set) m-file encoding. +The per-directory encoding overrides the (globally set) m-file encoding, +@pxref{XREFmfile_encoding,,@code{mfile_encoding}}. The string @var{DIR} must match how the directory would appear in the load path. @@ -1629,7 +1642,7 @@ files have to be parsed again for that change to take effect. That can be done with the command @code{clear all}. -@seealso{addpath, path} +@seealso{addpath, path, mfile_encoding} @end deftypefn */) { int nargin = args.length (); diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/input.h --- a/libinterp/corefcn/input.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/input.h Fri May 12 08:03:14 2023 +0200 @@ -66,7 +66,7 @@ octave_value PS1 (const octave_value_list& args, int nargout); - std::string PS1 (void) const { return m_PS1; } + std::string PS1 () const { return m_PS1; } std::string PS1 (const std::string& s) { @@ -79,7 +79,7 @@ octave_value PS2 (const octave_value_list& args, int nargout); - std::string PS2 (void) const { return m_PS2; } + std::string PS2 () const { return m_PS2; } std::string PS2 (const std::string& s) { @@ -90,7 +90,7 @@ void set_PS2 (const std::string& s) { m_PS2 = s; } - std::string last_debugging_command (void) const + std::string last_debugging_command () const { return m_last_debugging_command; } @@ -105,7 +105,7 @@ octave_value completion_append_char (const octave_value_list& args, int nargout); - char completion_append_char (void) const + char completion_append_char () const { return m_completion_append_char; } @@ -121,7 +121,7 @@ octave_value gud_mode (const octave_value_list& args, int nargout); - bool gud_mode (void) const { return m_gud_mode; } + bool gud_mode () const { return m_gud_mode; } bool gud_mode (bool flag) { @@ -134,7 +134,7 @@ octave_value mfile_encoding (const octave_value_list& args, int nargout); - std::string mfile_encoding (void) const { return m_mfile_encoding; } + std::string mfile_encoding () const { return m_mfile_encoding; } std::string mfile_encoding (const std::string& s) { @@ -152,7 +152,7 @@ octave_value auto_repeat_debug_command (const octave_value_list& args, int nargout); - bool auto_repeat_debug_command (void) const + bool auto_repeat_debug_command () const { return m_auto_repeat_debug_command; } @@ -171,15 +171,15 @@ octave_value_list get_user_input (const octave_value_list& args, int nargout); - bool have_input_event_hooks (void) const; + bool have_input_event_hooks () const; void add_input_event_hook (const hook_function& hook_fcn); bool remove_input_event_hook (const std::string& hook_fcn_id); - void clear_input_event_hooks (void); + void clear_input_event_hooks (); - void run_input_event_hooks (void); + void run_input_event_hooks (); private: @@ -229,23 +229,21 @@ : m_interpreter (interp) { } - base_reader (const base_reader& x) - : m_interpreter (x.m_interpreter) - { } + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (base_reader) - virtual ~base_reader (void) = default; + virtual ~base_reader () = default; virtual std::string get_input (const std::string& prompt, bool& eof) = 0; - virtual std::string input_source (void) const { return s_in_src; } + virtual std::string input_source () const { return s_in_src; } std::string octave_gets (const std::string& prompt, bool& eof); - virtual bool input_from_terminal (void) const { return false; } + virtual bool input_from_terminal () const { return false; } - virtual bool input_from_file (void) const { return false; } + virtual bool input_from_file () const { return false; } - virtual bool input_from_eval_string (void) const { return false; } + virtual bool input_from_eval_string () const { return false; } protected: @@ -260,6 +258,8 @@ { public: + input_reader () = delete; + input_reader (interpreter& interp); input_reader (interpreter& interp, FILE *file); @@ -268,33 +268,29 @@ input_reader (interpreter& interp, const std::string& str); - input_reader (const input_reader& ir) = default; - - input_reader& operator = (const input_reader& ir) = default; - - ~input_reader (void) = default; + OCTAVE_DEFAULT_COPY_DELETE (input_reader) std::string get_input (const std::string& prompt, bool& eof) { return m_rep->get_input (prompt, eof); } - std::string input_source (void) const + std::string input_source () const { return m_rep->input_source (); } - bool input_from_terminal (void) const + bool input_from_terminal () const { return m_rep->input_from_terminal (); } - bool input_from_file (void) const + bool input_from_file () const { return m_rep->input_from_file (); } - bool input_from_eval_string (void) const + bool input_from_eval_string () const { return m_rep->input_from_eval_string (); } diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/interpreter-private.cc --- a/libinterp/corefcn/interpreter-private.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/interpreter-private.cc Fri May 12 08:03:14 2023 +0200 @@ -51,7 +51,7 @@ OCTAVE_BEGIN_NAMESPACE(octave) -interpreter& __get_interpreter__ (void) +interpreter& __get_interpreter__ () { interpreter *interp = interpreter::the_interpreter (); @@ -64,91 +64,91 @@ return *interp; } -dynamic_loader& __get_dynamic_loader__ (void) +dynamic_loader& __get_dynamic_loader__ () { interpreter& interp = __get_interpreter__ (); return interp.get_dynamic_loader (); } -error_system& __get_error_system__ (void) +error_system& __get_error_system__ () { interpreter& interp = __get_interpreter__ (); return interp.get_error_system (); } -gh_manager& __get_gh_manager__ (void) +gh_manager& __get_gh_manager__ () { interpreter& interp = __get_interpreter__ (); return interp.get_gh_manager (); } -help_system& __get_help_system__ (void) +help_system& __get_help_system__ () { interpreter& interp = __get_interpreter__ (); return interp.get_help_system (); } -input_system& __get_input_system__ (void) +input_system& __get_input_system__ () { interpreter& interp = __get_interpreter__ (); return interp.get_input_system (); } -output_system& __get_output_system__ (void) +output_system& __get_output_system__ () { interpreter& interp = __get_interpreter__ (); return interp.get_output_system (); } -load_path& __get_load_path__ (void) +load_path& __get_load_path__ () { interpreter& interp = __get_interpreter__ (); return interp.get_load_path (); } -load_save_system& __get_load_save_system__ (void) +load_save_system& __get_load_save_system__ () { interpreter& interp = __get_interpreter__ (); return interp.get_load_save_system (); } -event_manager& __get_event_manager__ (void) +event_manager& __get_event_manager__ () { interpreter& interp = __get_interpreter__ (); return interp.get_event_manager (); } -type_info& __get_type_info__ (void) +type_info& __get_type_info__ () { interpreter& interp = __get_interpreter__ (); return interp.get_type_info (); } -symbol_table& __get_symbol_table__ (void) +symbol_table& __get_symbol_table__ () { interpreter& interp = __get_interpreter__ (); return interp.get_symbol_table (); } -symbol_scope __get_current_scope__ (void) +symbol_scope __get_current_scope__ () { interpreter& interp = __get_interpreter__ (); return interp.get_current_scope (); } -symbol_scope __require_current_scope__ (void) +symbol_scope __require_current_scope__ () { symbol_scope scope = __get_current_scope__ (); @@ -158,42 +158,42 @@ return scope; } -tree_evaluator& __get_evaluator__ (void) +tree_evaluator& __get_evaluator__ () { interpreter& interp = __get_interpreter__ (); return interp.get_evaluator (); } -bp_table& __get_bp_table__ (void) +bp_table& __get_bp_table__ () { tree_evaluator& tw = __get_evaluator__ (); return tw.get_bp_table (); } -child_list& __get_child_list__ (void) +child_list& __get_child_list__ () { interpreter& interp = __get_interpreter__ (); return interp.get_child_list (); } -cdef_manager& __get_cdef_manager__ (void) +cdef_manager& __get_cdef_manager__ () { interpreter& interp = __get_interpreter__ (); return interp.get_cdef_manager (); } -display_info& __get_display_info__ (void) +display_info& __get_display_info__ () { interpreter& interp = __get_interpreter__ (); return interp.get_display_info (); } -gtk_manager& __get_gtk_manager__ (void) +gtk_manager& __get_gtk_manager__ () { interpreter& interp = __get_interpreter__ (); diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/interpreter-private.h --- a/libinterp/corefcn/interpreter-private.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/interpreter-private.h Fri May 12 08:03:14 2023 +0200 @@ -53,45 +53,45 @@ class tree_evaluator; class type_info; -extern OCTINTERP_API interpreter& __get_interpreter__ (void); +extern OCTINTERP_API interpreter& __get_interpreter__ (); -extern OCTINTERP_API dynamic_loader& __get_dynamic_loader__ (void); +extern OCTINTERP_API dynamic_loader& __get_dynamic_loader__ (); -extern OCTINTERP_API error_system& __get_error_system__ (void); +extern OCTINTERP_API error_system& __get_error_system__ (); -extern OCTINTERP_API gh_manager& __get_gh_manager__ (void); +extern OCTINTERP_API gh_manager& __get_gh_manager__ (); -extern OCTINTERP_API help_system& __get_help_system__ (void); +extern OCTINTERP_API help_system& __get_help_system__ (); -extern OCTINTERP_API input_system& __get_input_system__ (void); +extern OCTINTERP_API input_system& __get_input_system__ (); -extern OCTINTERP_API load_path& __get_load_path__ (void); +extern OCTINTERP_API load_path& __get_load_path__ (); -extern OCTINTERP_API load_save_system& __get_load_save_system__ (void); +extern OCTINTERP_API load_save_system& __get_load_save_system__ (); -extern OCTINTERP_API event_manager& __get_event_manager__ (void); +extern OCTINTERP_API event_manager& __get_event_manager__ (); -extern OCTINTERP_API output_system& __get_output_system__ (void); +extern OCTINTERP_API output_system& __get_output_system__ (); -extern OCTINTERP_API type_info& __get_type_info__ (void); +extern OCTINTERP_API type_info& __get_type_info__ (); -extern OCTINTERP_API symbol_table& __get_symbol_table__ (void); +extern OCTINTERP_API symbol_table& __get_symbol_table__ (); -extern OCTINTERP_API symbol_scope __get_current_scope__ (void); +extern OCTINTERP_API symbol_scope __get_current_scope__ (); -extern OCTINTERP_API symbol_scope __require_current_scope__ (void); +extern OCTINTERP_API symbol_scope __require_current_scope__ (); -extern OCTINTERP_API tree_evaluator& __get_evaluator__ (void); +extern OCTINTERP_API tree_evaluator& __get_evaluator__ (); -extern OCTINTERP_API bp_table& __get_bp_table__ (void); +extern OCTINTERP_API bp_table& __get_bp_table__ (); -extern OCTINTERP_API child_list& __get_child_list__ (void); +extern OCTINTERP_API child_list& __get_child_list__ (); -extern OCTINTERP_API cdef_manager& __get_cdef_manager__ (void); +extern OCTINTERP_API cdef_manager& __get_cdef_manager__ (); -extern OCTINTERP_API display_info& __get_display_info__ (void); +extern OCTINTERP_API display_info& __get_display_info__ (); -extern OCTINTERP_API gtk_manager& __get_gtk_manager__ (void); +extern OCTINTERP_API gtk_manager& __get_gtk_manager__ (); // Functions that could be methods in the interpreter class but maybe // shouldn't be exposed as part of the public interface. diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/interpreter.cc --- a/libinterp/corefcn/interpreter.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/interpreter.cc Fri May 12 08:03:14 2023 +0200 @@ -43,6 +43,7 @@ #include "fpucw-wrappers.h" #include "lo-blas-proto.h" #include "lo-error.h" +#include "lo-sysdep.h" #include "oct-env.h" #include "quit.h" #include "str-vec.h" @@ -91,7 +92,7 @@ bool octave_interpreter_ready = false; // TRUE means we've processed all the init code and we are good to go. -bool octave_initialized = false; +std::atomic octave_initialized{false}; OCTAVE_BEGIN_NAMESPACE(octave) @@ -314,7 +315,7 @@ return ovl (interp.traditional ()); } -temporary_file_list::~temporary_file_list (void) +temporary_file_list::~temporary_file_list () { cleanup (); } @@ -324,7 +325,7 @@ m_files.insert (file); } -void temporary_file_list::cleanup (void) +void temporary_file_list::cleanup () { while (! m_files.empty ()) { @@ -339,56 +340,24 @@ // The time we last time we changed directories. sys::time Vlast_chdir_time = 0.0; -// Execute commands from a file and catch potential exceptions in a consistent -// way. This function should be called anywhere we might parse and execute -// commands from a file before we have entered the main loop in -// toplev.cc. - -static int safe_source_file (const std::string& file_name, - const std::string& context = "", - bool verbose = false, - bool require_file = true) +static void initialize_version_info () { - interpreter& interp = __get_interpreter__ (); - - try - { - source_file (file_name, context, verbose, require_file); - } - catch (const interrupt_exception&) - { - interp.recover_from_exception (); - - return 1; - } - catch (const execution_exception& ee) - { - interp.handle_exception (ee); - - return 1; - } - - return 0; + octave_value_list args (4); + + args(0) = "GNU Octave"; + args(1) = OCTAVE_VERSION; + args(2) = config::release (); + args(3) = OCTAVE_RELEASE_DATE; + + F__version_info__ (args); } -static void initialize_version_info (void) -{ - octave_value_list args; - - args(3) = OCTAVE_RELEASE_DATE; - args(2) = config::release (); - args(1) = OCTAVE_VERSION; - args(0) = "GNU Octave"; - - F__version_info__ (args, 0); -} - -static void xerbla_abort (void) +static void xerbla_abort () { error ("Fortran procedure terminated by call to XERBLA"); } -static void initialize_xerbla_error_handler (void) +static void initialize_xerbla_error_handler () { // The idea here is to force xerbla to be referenced so that we will // link to our own version instead of the one provided by the BLAS @@ -400,7 +369,7 @@ if (numeric_limits::NaN () == -1) F77_FUNC (xerbla, XERBLA) ("octave", 13 F77_CHAR_ARG_LEN (6)); - typedef void (*xerbla_handler_ptr) (void); + typedef void (*xerbla_handler_ptr) (); typedef void (*octave_set_xerbla_handler_ptr) (xerbla_handler_ptr); @@ -439,7 +408,7 @@ throw execution_exception (); } -static void initialize_error_handlers (void) +static void initialize_error_handlers () { set_liboctave_error_handler (lo_error_handler); set_liboctave_error_with_id_handler (lo_error_with_id_handler); @@ -473,7 +442,7 @@ m_child_list (), m_url_handle_manager (), m_cdef_manager (*this), - m_gtk_manager (), + m_gtk_manager (*this), m_event_manager (*this), m_gh_manager (nullptr), m_interactive (false), @@ -495,11 +464,11 @@ // // only one Octave interpreter may be active in any given thread - if (m_instance) + if (s_instance) throw std::runtime_error ("only one Octave interpreter may be active"); - m_instance = this; + s_instance = this; #if defined (OCTAVE_HAVE_WINDOWS_UTF8_LOCALE) // Force a UTF-8 locale on Windows if possible @@ -607,23 +576,23 @@ std::string docstrings_file = options.docstrings_file (); if (! docstrings_file.empty ()) - Fbuilt_in_docstrings_file (*this, octave_value (docstrings_file)); + Fbuilt_in_docstrings_file (*this, ovl (docstrings_file)); std::string doc_cache_file = options.doc_cache_file (); if (! doc_cache_file.empty ()) - Fdoc_cache_file (*this, octave_value (doc_cache_file)); + Fdoc_cache_file (*this, ovl (doc_cache_file)); std::string info_file = options.info_file (); if (! info_file.empty ()) - Finfo_file (*this, octave_value (info_file)); + Finfo_file (*this, ovl (info_file)); std::string info_program = options.info_program (); if (! info_program.empty ()) - Finfo_program (*this, octave_value (info_program)); + Finfo_program (*this, ovl (info_program)); std::string texi_macros_file = options.texi_macros_file (); if (! texi_macros_file.empty ()) - Ftexi_macros_file (*this, octave_value (texi_macros_file)); + Ftexi_macros_file (*this, ovl (texi_macros_file)); } // FIXME: we defer creation of the gh_manager object because it @@ -655,9 +624,9 @@ octave_interpreter_ready = true; } -OCTAVE_THREAD_LOCAL interpreter *interpreter::m_instance = nullptr; - -interpreter::~interpreter (void) +OCTAVE_THREAD_LOCAL interpreter *interpreter::s_instance = nullptr; + +interpreter::~interpreter () { if (! m_app_context) shutdown (); @@ -736,7 +705,7 @@ // This may be called separately from execute -void interpreter::initialize (void) +void interpreter::initialize () { if (m_initialized) return; @@ -789,7 +758,7 @@ // Note: this function is currently only used with the new // experimental terminal widget. -void interpreter::get_line_and_eval (void) +void interpreter::get_line_and_eval () { m_evaluator.get_line_and_eval (); } @@ -804,11 +773,9 @@ cli_input_reader (interpreter& interp) : m_interpreter (interp), m_thread () { } - cli_input_reader (const cli_input_reader&) = delete; - - cli_input_reader& operator = (const cli_input_reader&) = delete; - - ~cli_input_reader (void) + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (cli_input_reader) + + ~cli_input_reader () { // FIXME: Would it be better to ensure that // interpreter::get_line_and_eval exits and then call @@ -817,7 +784,7 @@ m_thread.detach (); } - void start (void) + void start () { m_thread = std::thread (&interpreter::get_line_and_eval, &m_interpreter); } @@ -838,7 +805,7 @@ // FIXME: this function is intended to be executed only once. Should // we enforce that restriction? -int interpreter::execute (void) +int interpreter::execute () { int exit_status = 0; @@ -965,7 +932,7 @@ } \ while (0) -void interpreter::shutdown (void) +void interpreter::shutdown () { // Attempt to prevent more than one call to shutdown. @@ -1075,7 +1042,7 @@ // OCTAVE_SAFE_CALL (singleton_cleanup_list::cleanup, ()); } -void interpreter::execute_atexit_fcns (void) +void interpreter::execute_atexit_fcns () { // Prevent atexit functions from adding new functions to the list. m_executing_atexit = true; @@ -1092,7 +1059,7 @@ } } -void interpreter::display_startup_message (void) const +void interpreter::display_startup_message () const { bool inhibit_startup_message = false; @@ -1107,11 +1074,11 @@ std::cout << octave_startup_message () << "\n" << std::endl; } -// Initialize by reading startup files. Return non-zero if an exception +// Initialize by reading startup files. Return nonzero if an exception // occurs when reading any of them, but don't exit early because of an // exception. -int interpreter::execute_startup_files (void) +int interpreter::execute_startup_files () { bool read_site_files = m_read_site_files; bool read_init_files = m_read_init_files; @@ -1227,16 +1194,14 @@ // Names alone are not enough. - sys::file_stat fs_home_rc (home_rc); - - if (fs_home_rc) + if (sys::file_exists (home_rc)) { // We want to check for curr_dir after executing home_rc // because doing that may change the working directory. local_rc = sys::env::make_absolute (initfile); - home_rc_already_executed = same_file (home_rc, local_rc); + home_rc_already_executed = sys::same_file (home_rc, local_rc); } } @@ -1261,7 +1226,7 @@ // Execute any code specified with --eval 'CODE' -int interpreter::execute_eval_option_code (void) +int interpreter::execute_eval_option_code () { if (! m_app_context) return 0; @@ -1294,7 +1259,7 @@ return parse_status; } -int interpreter::execute_command_line_file (void) +int interpreter::execute_command_line_file () { if (! m_app_context) return 0; @@ -1343,41 +1308,41 @@ return safe_source_file (fname, context, verbose, require_file); } -int interpreter::main_loop (void) +int interpreter::main_loop () { command_editor::add_event_hook (release_unreferenced_dynamic_libraries); return m_evaluator.repl (); } -int interpreter::server_loop (void) +int interpreter::server_loop () { return m_evaluator.server_loop (); } -tree_evaluator& interpreter::get_evaluator (void) +tree_evaluator& interpreter::get_evaluator () { return m_evaluator; } -stream_list& interpreter::get_stream_list (void) +stream_list& interpreter::get_stream_list () { return m_stream_list; } -url_handle_manager& interpreter::get_url_handle_manager (void) +url_handle_manager& interpreter::get_url_handle_manager () { return m_url_handle_manager; } symbol_scope -interpreter::get_top_scope (void) const +interpreter::get_top_scope () const { return m_evaluator.get_top_scope (); } symbol_scope -interpreter::get_current_scope (void) const +interpreter::get_current_scope () const { return m_evaluator.get_current_scope (); } @@ -1393,7 +1358,7 @@ return scope; } -profiler& interpreter::get_profiler (void) +profiler& interpreter::get_profiler () { return m_evaluator.get_profiler (); } @@ -1710,7 +1675,7 @@ m_evaluator.source_file (file_name, context, verbose, require_file); } -bool interpreter::at_top_level (void) const +bool interpreter::at_top_level () const { return m_evaluator.at_top_level (); } @@ -1730,7 +1695,7 @@ m_evaluator.clear_all (force); } -void interpreter::clear_objects (void) +void interpreter::clear_objects () { m_evaluator.clear_objects (); } @@ -1750,7 +1715,7 @@ m_evaluator.clear_variable_regexp (pattern); } -void interpreter::clear_variables (void) +void interpreter::clear_variables () { m_evaluator.clear_variables (); } @@ -1770,7 +1735,7 @@ m_evaluator.clear_global_variable_regexp (pattern); } -void interpreter::clear_global_variables (void) +void interpreter::clear_global_variables () { m_evaluator.clear_global_variables (); } @@ -1810,27 +1775,27 @@ return m_evaluator.clear_symbol_regexp (pat); } -std::list interpreter::global_variable_names (void) +std::list interpreter::global_variable_names () { return m_evaluator.global_variable_names (); } -std::list interpreter::top_level_variable_names (void) +std::list interpreter::top_level_variable_names () { return m_evaluator.top_level_variable_names (); } -std::list interpreter::variable_names (void) +std::list interpreter::variable_names () { return m_evaluator.variable_names (); } -std::list interpreter::user_function_names (void) +std::list interpreter::user_function_names () { return m_symbol_table.user_function_names (); } -std::list interpreter::autoloaded_functions (void) const +std::list interpreter::autoloaded_functions () const { return m_evaluator.autoloaded_functions (); } @@ -1838,7 +1803,7 @@ // May be used to send an interrupt signal to the the interpreter from // another thread (for example, the GUI). -void interpreter::interrupt (void) +void interpreter::interrupt () { static int sigint = 0; static bool first = true; @@ -1866,7 +1831,7 @@ octave_kill_wrapper (pid, sigint); } -void interpreter::pause (void) +void interpreter::pause () { // FIXME: To be reliable, these tree_evaluator functions must be // made thread safe. @@ -1875,7 +1840,7 @@ m_evaluator.reset_debug_state (); } -void interpreter::stop (void) +void interpreter::stop () { // FIXME: To be reliable, these tree_evaluator functions must be // made thread safe. @@ -1886,7 +1851,7 @@ interrupt (); } -void interpreter::resume (void) +void interpreter::resume () { // FIXME: To be reliable, these tree_evaluator functions must be // made thread safe. @@ -1898,9 +1863,69 @@ m_evaluator.dbcont (); } +octave_value interpreter::PS1 (const octave_value_list& args, int nargout) +{ + return m_input_system.PS1 (args, nargout); +} + +std::string interpreter::PS1 () const +{ + return m_input_system.PS1 (); +} + +std::string interpreter::PS1 (const std::string& s) +{ + return m_input_system.PS1 (s); +} + +void interpreter::set_PS1 (const std::string& s) +{ + m_input_system.set_PS1 (s); +} + +octave_value interpreter::PS2 (const octave_value_list& args, int nargout) +{ + return m_input_system.PS2 (args, nargout); +} + +std::string interpreter::PS2 () const +{ + return m_input_system.PS2 (); +} + +std::string interpreter::PS2 (const std::string& s) +{ + return m_input_system.PS2 (s); +} + +void interpreter::set_PS2 (const std::string& s) +{ + m_input_system.set_PS2 (s); +} + +octave_value interpreter::PS4 (const octave_value_list& args, int nargout) +{ + return m_evaluator.PS4 (args, nargout); +} + +std::string interpreter::PS4 () const +{ + return m_evaluator.PS4 (); +} + +std::string interpreter::PS4 (const std::string& s) +{ + return m_evaluator.PS4 (s); +} + +void interpreter::set_PS4 (const std::string& s) +{ + m_evaluator.set_PS4 (s); +} + // Provided for convenience. Will be removed once we eliminate the // old terminal widget. -bool interpreter::experimental_terminal_widget (void) const +bool interpreter::experimental_terminal_widget () const { if (! m_app_context) return false; @@ -1921,12 +1946,12 @@ m_evaluator.remove_debug_watch_expression (expr); } -void interpreter::clear_debug_watch_expressions (void) +void interpreter::clear_debug_watch_expressions () { m_evaluator.clear_debug_watch_expressions (); } -std::set interpreter::debug_watch_expressions (void) const +std::set interpreter::debug_watch_expressions () const { return m_evaluator.debug_watch_expressions (); } @@ -1943,14 +1968,14 @@ recover_from_exception (); } -void interpreter::recover_from_exception (void) +void interpreter::recover_from_exception () { if (octave_interrupt_state) m_event_manager.interpreter_interrupted (); can_interrupt = true; octave_interrupt_state = 0; - octave_signal_caught = 0; + octave_signal_caught = false; octave_restore_signal_mask (); catch_interrupts (); } @@ -1960,7 +1985,7 @@ m_tmp_files.insert (file); } -void interpreter::cleanup_tmp_files (void) +void interpreter::cleanup_tmp_files () { m_tmp_files.cleanup (); } @@ -2035,12 +2060,11 @@ // What internal options get configured by --traditional. -void interpreter::maximum_braindamage (void) +void interpreter::maximum_braindamage () { - m_input_system.PS1 (">> "); - m_input_system.PS2 (""); - - m_evaluator.PS4 (""); + PS1 (">> "); + PS2 (""); + PS4 (""); m_load_save_system.crash_dumps_octave_core (false); m_load_save_system.save_default_options ("-mat-binary"); @@ -2049,14 +2073,14 @@ m_error_system.beep_on_error (true); - Fconfirm_recursive_rmdir (octave_value (false)); - Foptimize_diagonal_matrix (octave_value (false)); - Foptimize_permutation_matrix (octave_value (false)); - Foptimize_range (octave_value (false)); - Ffixed_point_format (octave_value (true)); - Fprint_empty_dimensions (octave_value (false)); - Fprint_struct_array_contents (octave_value (true)); - Fstruct_levels_to_print (octave_value (0)); + Fconfirm_recursive_rmdir (ovl (false)); + Foptimize_diagonal_matrix (ovl (false)); + Foptimize_permutation_matrix (ovl (false)); + Foptimize_range (ovl (false)); + Ffixed_point_format (ovl (true)); + Fprint_empty_dimensions (ovl (false)); + Fprint_struct_array_contents (ovl (true)); + Fstruct_levels_to_print (ovl (0)); m_error_system.disable_warning ("Octave:abbreviated-property-match"); m_error_system.disable_warning ("Octave:colon-nonscalar-argument"); @@ -2082,4 +2106,33 @@ } } +// Execute commands from a file and catch potential exceptions in a consistent +// way. This function should be called anywhere we might parse and execute +// commands from a file before we have entered the main loop in +// toplev.cc. + +int interpreter::safe_source_file (const std::string& file_name, + const std::string& context, + bool verbose, bool require_file) +{ + try + { + source_file (file_name, context, verbose, require_file); + } + catch (const interrupt_exception&) + { + recover_from_exception (); + + return 1; + } + catch (const execution_exception& ee) + { + handle_exception (ee); + + return 1; + } + + return 0; +} + OCTAVE_END_NAMESPACE(octave) diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/interpreter.h --- a/libinterp/corefcn/interpreter.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/interpreter.h Fri May 12 08:03:14 2023 +0200 @@ -28,6 +28,7 @@ #include "octave-config.h" +#include #include #include #include @@ -44,6 +45,7 @@ #include "environment.h" #include "error.h" #include "event-manager.h" +#include "gh-manager.h" #include "graphics.h" #include "gtk-manager.h" #include "help.h" @@ -66,7 +68,7 @@ extern OCTINTERP_API bool octave_interpreter_ready; // TRUE means we've processed all the init code and we are good to go. -extern OCTINTERP_API bool octave_initialized; +extern OCTINTERP_API std::atomic octave_initialized; #include "oct-time.h" @@ -90,19 +92,15 @@ { public: - temporary_file_list (void) : m_files () { } - - // No copying! + temporary_file_list () : m_files () { } - temporary_file_list (const temporary_file_list&) = delete; + OCTAVE_DISABLE_COPY_MOVE (temporary_file_list) - temporary_file_list& operator = (const temporary_file_list&) = delete; - - ~temporary_file_list (void); + ~temporary_file_list (); void insert (const std::string& file); - void cleanup (void); + void cleanup (); private: @@ -119,15 +117,11 @@ interpreter (application *app_context = nullptr); - // No copying, at least not yet... - - interpreter (const interpreter&) = delete; - - interpreter& operator = (const interpreter&) = delete; + OCTAVE_DISABLE_COPY_MOVE (interpreter) // Clean up the interpreter object. - ~interpreter (void); + ~interpreter (); void intern_nargin (octave_idx_type nargs); @@ -147,12 +141,12 @@ // Load command line history, set the load path. - void initialize (void); + void initialize (); // Note: GET_LINE_AND_EVAL is only used by new experimental terminal // widget. - void get_line_and_eval (void); + void get_line_and_eval (); // Parse a line of input. If input ends at a complete statement // boundary, execute the resulting parse tree. Useful to handle @@ -164,11 +158,11 @@ // call to initialize), execute startup files, --eval option code, // script files, and/or interactive commands. - int execute (void); + int execute (); - bool server_mode (void) const { return m_evaluator.server_mode (); } + bool server_mode () const { return m_evaluator.server_mode (); } - bool interactive (void) const + bool interactive () const { return m_interactive; } @@ -198,7 +192,7 @@ m_traditional = flag; } - bool traditional (void) const + bool traditional () const { return m_traditional; } @@ -208,12 +202,12 @@ m_inhibit_startup_message = flag; } - bool in_top_level_repl (void) const + bool in_top_level_repl () const { return m_evaluator.in_top_level_repl (); } - bool initialized (void) const + bool initialized () const { return m_initialized; } @@ -223,114 +217,114 @@ m_interrupt_all_in_process_group = b; } - bool interrupt_all_in_process_group (void) const + bool interrupt_all_in_process_group () const { return m_interrupt_all_in_process_group; } - application * get_app_context (void) + application * get_app_context () { return m_app_context; } - display_info& get_display_info (void) + display_info& get_display_info () { return m_display_info; } - environment& get_environment (void) + environment& get_environment () { return m_environment; } - settings& get_settings (void) + settings& get_settings () { return m_settings; } - error_system& get_error_system (void) + error_system& get_error_system () { return m_error_system; } - tree_evaluator& get_evaluator (void); + tree_evaluator& get_evaluator (); - help_system& get_help_system (void) + help_system& get_help_system () { return m_help_system; } - input_system& get_input_system (void) + input_system& get_input_system () { return m_input_system; } - output_system& get_output_system (void) + output_system& get_output_system () { return m_output_system; } - history_system& get_history_system (void) + history_system& get_history_system () { return m_history_system; } - dynamic_loader& get_dynamic_loader (void) + dynamic_loader& get_dynamic_loader () { return m_dynamic_loader; } - load_path& get_load_path (void) + load_path& get_load_path () { return m_load_path; } - load_save_system& get_load_save_system (void) + load_save_system& get_load_save_system () { return m_load_save_system; } - type_info& get_type_info (void) + type_info& get_type_info () { return m_type_info; } - symbol_table& get_symbol_table (void) + symbol_table& get_symbol_table () { return m_symbol_table; } - symbol_scope get_top_scope (void) const; - symbol_scope get_current_scope (void) const; + symbol_scope get_top_scope () const; + symbol_scope get_current_scope () const; symbol_scope require_current_scope (const std::string& who) const; - profiler& get_profiler (void); + profiler& get_profiler (); - stream_list& get_stream_list (void); + stream_list& get_stream_list (); - child_list& get_child_list (void) + child_list& get_child_list () { return m_child_list; } - url_handle_manager& get_url_handle_manager (void); + url_handle_manager& get_url_handle_manager (); - cdef_manager& get_cdef_manager (void) + cdef_manager& get_cdef_manager () { return m_cdef_manager; } - gtk_manager& get_gtk_manager (void) + gtk_manager& get_gtk_manager () { return m_gtk_manager; } - event_manager& get_event_manager (void) + event_manager& get_event_manager () { return m_event_manager; } - gh_manager& get_gh_manager (void) + gh_manager& get_gh_manager () { return *m_gh_manager; } @@ -432,7 +426,7 @@ const std::string& context = "", bool verbose = false, bool require_file = true); - bool at_top_level (void) const; + bool at_top_level () const; bool isglobal (const std::string& name) const; @@ -440,7 +434,7 @@ void clear_all (bool force = false); - void clear_objects (void); + void clear_objects (); void clear_variable (const std::string& name); @@ -448,7 +442,7 @@ void clear_variable_regexp (const std::string& pattern); - void clear_variables (void); + void clear_variables (); void clear_global_variable (const std::string& name); @@ -456,7 +450,7 @@ void clear_global_variable_regexp (const std::string& pattern); - void clear_global_variables (void); + void clear_global_variables (); void clear_functions (bool force = false); @@ -472,25 +466,25 @@ void clear_symbol_regexp (const std::string& pat); - std::list variable_names (void); + std::list variable_names (); - std::list top_level_variable_names (void); + std::list top_level_variable_names (); - std::list global_variable_names (void); + std::list global_variable_names (); - std::list user_function_names (void); + std::list user_function_names (); - std::list autoloaded_functions (void) const; + std::list autoloaded_functions () const; - void interrupt (void); + void interrupt (); // Pause interpreter execution at the next available statement and // enter the debugger. - void pause (void); + void pause (); // Exit debugger or stop execution and return to the top-level REPL // or server loop. - void stop (void); + void stop (); // Add EXPR to the set of expressions that may be evaluated when the // debugger stops at a breakpoint. @@ -502,32 +496,47 @@ // Clear the set of expressions that may be evaluated when the // debugger stops at a breakpoint. - void clear_debug_watch_expressions (void); + void clear_debug_watch_expressions (); // Return the set of expressions that may be evaluated when the // debugger stops at a breakpoint. - std::set debug_watch_expressions (void) const; + std::set debug_watch_expressions () const; // Resume interpreter execution if paused. - void resume (void); + void resume (); + + octave_value PS1 (const octave_value_list& args, int nargout); + std::string PS1 () const; + std::string PS1 (const std::string& s); + void set_PS1 (const std::string& s); + + octave_value PS2 (const octave_value_list& args, int nargout); + std::string PS2 () const; + std::string PS2 (const std::string& s); + void set_PS2 (const std::string& s); + + octave_value PS4 (const octave_value_list& args, int nargout); + std::string PS4 () const; + std::string PS4 (const std::string& s); + void set_PS4 (const std::string& s); // Provided for convenience. Will be removed once we eliminate the // old terminal widget. - bool experimental_terminal_widget (void) const; + bool experimental_terminal_widget () const; void handle_exception (const execution_exception& ee); - void recover_from_exception (void); + void recover_from_exception (); void mark_for_deletion (const std::string& file); - void cleanup_tmp_files (void); + void cleanup_tmp_files (); void quit (int exit_status, bool force = false, bool confirm = true); void cancel_quit (bool flag) { m_cancel_quit = flag; } - bool executing_finish_script (void) const + bool executing_finish_script () const { return m_executing_finish_script; } @@ -536,30 +545,34 @@ bool remove_atexit_fcn (const std::string& fname); - static interpreter * the_interpreter (void) { return m_instance; } + static interpreter * the_interpreter () { return s_instance; } private: - void display_startup_message (void) const; + void display_startup_message () const; - int execute_startup_files (void); + int execute_startup_files (); - int execute_eval_option_code (void); + int execute_eval_option_code (); - int execute_command_line_file (void); + int execute_command_line_file (); - int main_loop (void); + int main_loop (); - int server_loop (void); + int server_loop (); - void shutdown (void); + void shutdown (); - void execute_atexit_fcns (void); + void execute_atexit_fcns (); - void maximum_braindamage (void); + void maximum_braindamage (); void execute_pkg_add (const std::string& dir); + int safe_source_file (const std::string& file_name, + const std::string& context = "", + bool verbose = false, bool require_file = true); + //-------- // The interpreter instance; Currently it is only possible to @@ -570,7 +583,7 @@ // replaced by the C++ thread_local keyword. For now, use a macro // to allow experimenting with thread_local storage. - OCTAVE_THREAD_LOCAL static interpreter *m_instance; + OCTAVE_THREAD_LOCAL static interpreter *s_instance; application *m_app_context; diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/jsondecode.cc --- a/libinterp/corefcn/jsondecode.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/jsondecode.cc Fri May 12 08:03:14 2023 +0200 @@ -612,7 +612,7 @@ = use_makeValidName ? new make_valid_name_options (make_valid_name_params) : nullptr; - unwind_action del_opts ([options] (void) { if (options) delete options; }); + unwind_action del_opts ([options] () { if (options) delete options; }); if (! args(0).is_string ()) error ("jsondecode: JSON_TXT must be a character string"); diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/kron.cc --- a/libinterp/corefcn/kron.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/kron.cc Fri May 12 08:03:14 2023 +0200 @@ -275,6 +275,7 @@ @noindent Since the Kronecker product is associative, this is well-defined. +@seealso{tensorprod} @end deftypefn */) { int nargin = args.length (); diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/latex-text-renderer.cc --- a/libinterp/corefcn/latex-text-renderer.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/latex-text-renderer.cc Fri May 12 08:03:14 2023 +0200 @@ -53,10 +53,9 @@ OCTINTERP_API latex_renderer : public base_text_renderer { - public: - latex_renderer (void) + latex_renderer () : m_fontsize (10.0), m_fontname ("cmr"), m_tmp_dir (), m_color (dim_vector (1, 3), 0), m_latex_binary ("latex"), m_dvipng_binary ("dvipng"), m_dvisvg_binary ("dvisvgm"), @@ -77,7 +76,9 @@ m_debug = ! sys::env::getenv ("OCTAVE_LATEX_DEBUG_FLAG").empty (); } - ~latex_renderer (void) + OCTAVE_DISABLE_COPY_MOVE (latex_renderer) + + ~latex_renderer () { if (! m_tmp_dir.empty () && ! m_debug) sys::recursive_rmdir (m_tmp_dir); @@ -144,9 +145,9 @@ void set_anti_aliasing (bool /*val*/) { } - octave_map get_system_fonts (void) { return octave_map (); } + octave_map get_system_fonts () { return octave_map (); } - bool ok (void); + bool ok (); private: @@ -183,7 +184,7 @@ }; bool -latex_renderer::ok (void) +latex_renderer::ok () { // Only run the test once in a session static bool tested = false; @@ -522,7 +523,7 @@ } base_text_renderer * -make_latex_text_renderer (void) +make_latex_text_renderer () { latex_renderer *renderer = new latex_renderer (); diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/latex-text-renderer.h --- a/libinterp/corefcn/latex-text-renderer.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/latex-text-renderer.h Fri May 12 08:03:14 2023 +0200 @@ -32,7 +32,7 @@ class base_text_renderer; -extern base_text_renderer * make_latex_text_renderer (void); +extern base_text_renderer * make_latex_text_renderer (); OCTAVE_END_NAMESPACE(octave) diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/load-path.cc --- a/libinterp/corefcn/load-path.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/load-path.cc Fri May 12 08:03:14 2023 +0200 @@ -33,6 +33,7 @@ #include "dir-ops.h" #include "file-ops.h" #include "file-stat.h" +#include "lo-sysdep.h" #include "oct-env.h" #include "pathsearch.h" @@ -147,45 +148,6 @@ return dir; } -// Should we cache all files in private directories, or is it OK to just -// look them up each time as needed? - -static std::string -find_private_file (const std::string& fname) -{ - std::string retval; - - // Look in private directory corresponding to current function (if - // any). - - symbol_scope scope = __get_current_scope__ (); - - octave_user_code *curr_code = scope ? scope.user_code () : nullptr; - - if (curr_code) - { - // Even for private functions, dir_name doesn't contain the - // "private" directory component so we append it here in all - // cases. - - std::string dir_name = curr_code->dir_name (); - - if (! dir_name.empty ()) - { - std::string pfname = dir_name + sys::file_ops::dir_sep_str () - + "private" + sys::file_ops::dir_sep_str () - + fname; - - sys::file_stat fs (pfname); - - if (fs.exists () && fs.is_reg ()) - retval = pfname; - } - } - - return retval; -} - // True if a path is contained in a path list separated by path_sep_char static bool @@ -207,24 +169,6 @@ return false; } -static void -rehash_internal (void) -{ - load_path& lp = __get_load_path__ (); - - lp.update (); - - // Signal the GUI allowing updating the load path dialog - event_manager& evmgr = __get_event_manager__ (); - evmgr.update_path_dialog (); - - // FIXME: maybe we should rename this variable since it is being - // used for more than keeping track of the prompt time. - - // This will force updated functions to be found. - Vlast_prompt_time.stamp (); -} - //! Check if directory contains modified subdirectories. //! //! @param d directory to check @@ -290,8 +234,8 @@ load_path::abs_dir_cache_type load_path::s_abs_dir_cache; load_path::load_path (interpreter& interp) - : add_hook ([=] (const std::string& dir) { this->execute_pkg_add (dir); }), -remove_hook ([=] (const std::string& dir) { this->execute_pkg_del (dir); }), + : m_add_hook ([=] (const std::string& dir) { this->execute_pkg_add (dir); }), +m_remove_hook ([=] (const std::string& dir) { this->execute_pkg_del (dir); }), m_interpreter (interp), m_package_map (), m_top_level_package (), m_dir_info_list (), m_init_dirs (), m_command_line_path () { } @@ -335,7 +279,7 @@ } void -load_path::clear (void) +load_path::clear () { m_dir_info_list.clear (); @@ -374,9 +318,9 @@ // Temporarily disable add hook. unwind_protect frame; - frame.protect_var (add_hook); - - add_hook = nullptr; + frame.protect_var (m_add_hook); + + m_add_hook = nullptr; clear (); @@ -390,8 +334,8 @@ // Why not use const here? Does add_hook change dir_info_list? for (auto& di : m_dir_info_list) { - if (add_hook) - add_hook (di.dir_name); + if (m_add_hook) + m_add_hook (di.dir_name); } // Always prepend current directory. @@ -419,7 +363,7 @@ if (! dir_arg.empty ()) { - if (same_file (dir_arg, ".")) + if (sys::same_file (dir_arg, ".")) { warning (R"(rmpath: can't remove "." from path)"); @@ -438,8 +382,8 @@ { retval = true; - if (remove_hook) - remove_hook (dir); + if (m_remove_hook) + m_remove_hook (dir); dir_info& di = *i; @@ -454,7 +398,7 @@ } void -load_path::update (void) +load_path::update () { // I don't see a better way to do this because we need to // preserve the correct directory ordering for new files that @@ -485,7 +429,7 @@ for (const auto& d : m_dir_info_list) { - if (same_file (dir, d.dir_name)) + if (sys::same_file (dir, d.dir_name)) { retval = true; break; @@ -504,7 +448,7 @@ std::string curr_dir = sys::env::get_current_directory (); - if (same_file (curr_dir, dir)) + if (sys::same_file (curr_dir, dir)) ok = true; else { @@ -519,7 +463,7 @@ if (dir_in_load_path) { - if (same_file (lp_file, file)) + if (sys::same_file (lp_file, file)) ok = true; } else @@ -530,9 +474,9 @@ // not enough because the file in the current directory would // still be found. - if (same_file (lp_file, base_file)) + if (sys::same_file (lp_file, base_file)) { - if (same_file (curr_dir, dir)) + if (sys::same_file (curr_dir, dir)) ok = true; else addpath_option = false; @@ -605,11 +549,7 @@ if (sys::env::absolute_pathname (file) || sys::env::rooted_relative_pathname (file)) - { - sys::file_stat fs (file); - - return fs.exists () ? file : retval; - } + return sys::file_exists (file) ? file : retval; else { std::string tfile = find_private_file (file); @@ -627,9 +567,7 @@ { std::string tfile = sys::file_ops::concat (di.abs_dir_name, file); - sys::file_stat fs (tfile); - - if (fs.exists ()) + if (sys::file_exists (tfile)) return tfile; } } @@ -662,9 +600,7 @@ && (sys::env::absolute_pathname (dir) || sys::env::rooted_relative_pathname (dir))) { - sys::file_stat fs (dir); - - if (fs.exists () && fs.is_dir ()) + if (sys::dir_exists (dir)) return dir; } else @@ -687,13 +623,9 @@ if (dname_len > dir_len && sys::file_ops::is_dir_sep (dname[dname_len - dir_len - 1]) - && canon_dir == dname.substr (dname_len - dir_len)) - { - sys::file_stat fs (di.dir_name); - - if (fs.exists () && fs.is_dir ()) - return di.abs_dir_name; - } + && canon_dir == dname.substr (dname_len - dir_len) + && sys::dir_exists (di.dir_name)) + return di.abs_dir_name; } } @@ -709,9 +641,7 @@ && (sys::env::absolute_pathname (dir) || sys::env::rooted_relative_pathname (dir))) { - sys::file_stat fs (dir); - - if (fs.exists () && fs.is_dir ()) + if (sys::dir_exists (dir)) retlist.push_back (dir); } else @@ -734,13 +664,9 @@ if (dname_len > dir_len && sys::file_ops::is_dir_sep (dname[dname_len - dir_len - 1]) - && canon_dir == dname.substr (dname_len - dir_len)) - { - sys::file_stat fs (di.dir_name); - - if (fs.exists () && fs.is_dir ()) - retlist.push_back (di.abs_dir_name); - } + && canon_dir == dname.substr (dname_len - dir_len) + && sys::dir_exists (di.dir_name)) + retlist.push_back (di.abs_dir_name); } } @@ -770,9 +696,7 @@ if (sys::env::absolute_pathname (file) || sys::env::rooted_relative_pathname (file)) { - sys::file_stat fs (file); - - if (fs.exists ()) + if (sys::file_exists (file)) return file; } else @@ -782,9 +706,7 @@ std::string tfile; tfile = sys::file_ops::concat (di.abs_dir_name, file); - sys::file_stat fs (tfile); - - if (fs.exists ()) + if (sys::file_exists (tfile)) return tfile; } } @@ -847,9 +769,7 @@ if (sys::env::absolute_pathname (file) || sys::env::rooted_relative_pathname (file)) { - sys::file_stat fs (file); - - if (fs.exists ()) + if (sys::file_exists (file)) retlist.push_back (file); } else @@ -859,9 +779,7 @@ std::string tfile; tfile = sys::file_ops::concat (di.abs_dir_name, file); - sys::file_stat fs (tfile); - - if (fs.exists ()) + if (sys::file_exists (tfile)) retlist.push_back (tfile); } } @@ -893,7 +811,7 @@ } string_vector -load_path::dirs (void) const +load_path::dirs () const { std::size_t len = m_dir_info_list.size (); @@ -908,7 +826,7 @@ } std::list -load_path::dir_list (void) const +load_path::dir_list () const { std::list retval; @@ -947,13 +865,13 @@ } string_vector -load_path::fcn_names (void) const +load_path::fcn_names () const { return m_top_level_package.fcn_names (); } std::string -load_path::path (void) const +load_path::path () const { std::string xpath; @@ -1021,6 +939,23 @@ execute_pkg_add_or_del (dir, "PKG_DEL"); } +void load_path::rehash () +{ + update (); + + // Signal the GUI allowing updating the load path dialog + + event_manager& evmgr = m_interpreter.get_event_manager (); + + evmgr.update_path_dialog (); + + // FIXME: maybe we should rename this variable since it is being + // used for more than keeping track of the prompt time. + + // This will force updated functions to be found. + Vlast_prompt_time.stamp (); +} + void load_path::execute_pkg_add_or_del (const std::string& dir, const std::string& script_file) { @@ -1029,9 +964,7 @@ std::string file = sys::file_ops::concat (dir, script_file); - sys::file_stat fs (file); - - if (fs.exists ()) + if (sys::file_exists (file)) source_file (file, "base"); } @@ -1143,34 +1076,27 @@ move (i, at_end); else { - sys::file_stat fs (dir); - - if (fs) + std::string msg; + + if (sys::dir_exists (dir, msg)) { - if (fs.is_dir ()) - { - read_dir_config (dir); - - dir_info di (dir); - - if (at_end) - m_dir_info_list.push_back (di); - else - m_dir_info_list.push_front (di); - - add (di, at_end); - - if (add_hook) - add_hook (dir); - } - else if (warn) - warning ("addpath: %s: not a directory", dir_arg.c_str ()); + read_dir_config (dir); + + dir_info di (dir); + + if (at_end) + m_dir_info_list.push_back (di); + else + m_dir_info_list.push_front (di); + + add (di, at_end); + + if (m_add_hook) + m_add_hook (dir); } - else if (warn) - { - std::string msg = fs.error (); - warning ("addpath: %s: %s", dir_arg.c_str (), msg.c_str ()); - } + + if (warn && ! msg.empty ()) + warning ("addpath: %s: %s", dir_arg.c_str (), msg.c_str ()); } // FIXME: is there a better way to do this? @@ -1223,7 +1149,7 @@ return; } - unwind_action close_file ([cfile] (void) { fclose (cfile); }); + unwind_action close_file ([cfile] () { fclose (cfile); }); // find line with character encoding and read it bool eof = false; @@ -1334,6 +1260,43 @@ return retval; } +// Should we cache all files in private directories, or is it OK to just +// look them up each time as needed? + +std::string +load_path::find_private_file (const std::string& fname) const +{ + std::string retval; + + // Look in private directory corresponding to current function (if + // any). + + symbol_scope scope = m_interpreter.get_current_scope (); + + octave_user_code *curr_code = scope ? scope.user_code () : nullptr; + + if (curr_code) + { + // Even for private functions, dir_name doesn't contain the + // "private" directory component so we append it here in all + // cases. + + std::string dir_name = curr_code->dir_name (); + + if (! dir_name.empty ()) + { + std::string pfname = dir_name + sys::file_ops::dir_sep_str () + + "private" + sys::file_ops::dir_sep_str () + + fname; + + if (sys::file_exists (pfname, false)) + retval = pfname; + } + } + + return retval; +} + load_path::dir_info::fcn_file_map_type get_fcn_files (const std::string& d) { @@ -1389,7 +1352,7 @@ } bool -load_path::dir_info::update (void) +load_path::dir_info::update () { sys::file_stat fs (dir_name); @@ -1483,7 +1446,7 @@ } void -load_path::dir_info::initialize (void) +load_path::dir_info::initialize () { is_relative = ! sys::env::absolute_pathname (dir_name); @@ -1554,36 +1517,31 @@ std::string full_name = sys::file_ops::concat (d, fname); - sys::file_stat fs (full_name); - - if (fs) + if (sys::dir_exists (full_name)) { - if (fs.is_dir ()) - { - if (fname == "private") - get_private_file_map (full_name); - else if (fname[0] == '@') - get_method_file_map (full_name, fname.substr (1)); - else if (fname[0] == '+') - get_package_dir (full_name, fname.substr (1)); - } - else + if (fname == "private") + get_private_file_map (full_name); + else if (fname[0] == '@') + get_method_file_map (full_name, fname.substr (1)); + else if (fname[0] == '+') + get_package_dir (full_name, fname.substr (1)); + } + else if (sys::file_exists (full_name)) + { + all_files[all_files_count++] = fname; + + std::size_t pos = fname.rfind ('.'); + + if (pos != std::string::npos) { - all_files[all_files_count++] = fname; - - std::size_t pos = fname.rfind ('.'); - - if (pos != std::string::npos) + std::string ext = fname.substr (pos); + + if (ext == ".m" || ext == ".oct" || ext == ".mex") { - std::string ext = fname.substr (pos); - - if (ext == ".m" || ext == ".oct" || ext == ".mex") - { - std::string base = fname.substr (0, pos); - - if (valid_identifier (base)) - fcn_files[fcn_files_count++] = fname; - } + std::string base = fname.substr (0, pos); + + if (valid_identifier (base)) + fcn_files[fcn_files_count++] = fname; } } } @@ -1607,9 +1565,7 @@ std::string pd = sys::file_ops::concat (d, "private"); - sys::file_stat fs (pd); - - if (fs && fs.is_dir ()) + if (sys::dir_exists (pd)) method_file_map[class_name].private_file_map = get_fcn_files (pd); } @@ -1746,11 +1702,10 @@ retval = find_method (class_name, meth, dir_name); } - else - retval = ""; } else { + // Ensure that dir_name is empty if function is not found. dir_name = ""; const_fcn_map_iterator p = m_fcn_map.find (fcn); @@ -1820,6 +1775,7 @@ // update (); + // Ensure that dir_name is empty if method is not found. dir_name = ""; const_method_map_iterator q = m_method_map.find (class_name); @@ -1897,7 +1853,7 @@ } string_vector -load_path::package_info::fcn_names (void) const +load_path::package_info::fcn_names () const { std::size_t len = m_fcn_map.size (); @@ -2445,9 +2401,7 @@ { std::string nm = sys::file_ops::concat (dirname, elt); - sys::file_stat fs (nm); - - if (fs && fs.is_dir ()) + if (sys::dir_exists (nm)) retval += (directory_path::path_sep_str () + genpath (nm, skip)); } @@ -2500,13 +2454,15 @@ return retval; } -DEFUN (rehash, , , - doc: /* -*- texinfo -*- +DEFMETHOD (rehash, interp, , , + doc: /* -*- texinfo -*- @deftypefn {} {} rehash () Reinitialize Octave's load path directory cache. @end deftypefn */) { - rehash_internal (); + load_path& lp = interp.get_load_path (); + + lp.rehash (); return ovl (); } @@ -2599,7 +2555,7 @@ lp.set (path, true); - rehash_internal (); + lp.rehash (); } if (nargout > 0) @@ -2754,7 +2710,7 @@ } if (need_to_update) - rehash_internal (); + lp.rehash (); return retval; } @@ -2814,7 +2770,7 @@ } if (need_to_update) - rehash_internal (); + lp.rehash (); return retval; } diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/load-path.h --- a/libinterp/corefcn/load-path.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/load-path.h Fri May 12 08:03:14 2023 +0200 @@ -51,15 +51,13 @@ typedef void (*hook_fcn_ptr) (const std::string& dir); - load_path (const load_path&) = delete; + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (load_path) - load_path& operator = (const load_path&) = delete; - - ~load_path (void) = default; + ~load_path () = default; void initialize (bool set_initial_path = false); - void clear (void); + void clear (); void set (const std::string& p, bool warn = false, bool is_init = false); @@ -69,7 +67,7 @@ bool remove (const std::string& dir); - void update (void); + void update (); bool contains_canonical (const std::string& dir_name) const; @@ -159,36 +157,36 @@ string_vector find_all_first_of (const string_vector& files) const; - string_vector dirs (void) const; + string_vector dirs () const; - std::list dir_list (void) const; + std::list dir_list () const; string_vector files (const std::string& dir, bool omit_exts = false) const; - string_vector fcn_names (void) const; + string_vector fcn_names () const; - std::string path (void) const; + std::string path () const; void display (std::ostream& os) const; - std::function get_add_hook (void) + std::function get_add_hook () { - return add_hook; + return m_add_hook; } - std::function get_remove_hook (void) + std::function get_remove_hook () { - return remove_hook; + return m_remove_hook; } void set_add_hook (const std::function& f) { - add_hook = f; + m_add_hook = f; } void set_remove_hook (const std::function& f) { - remove_hook = f; + m_remove_hook = f; } void read_dir_config (const std::string& dir) const; @@ -204,12 +202,14 @@ m_command_line_path += directory_path::path_sep_str () + p; } - std::string get_command_line_path (void) const + std::string get_command_line_path () const { return m_command_line_path; } - std::string system_path (void) const { return s_sys_path; } + std::string system_path () const { return s_sys_path; } + + void rehash (); static const int M_FILE = 1; static const int OCT_FILE = 2; @@ -230,7 +230,7 @@ struct class_info { public: - class_info (void) : method_file_map (), private_file_map () { } + class_info () : method_file_map (), private_file_map () { } class_info (const class_info& ci) : method_file_map (ci.method_file_map), @@ -247,7 +247,7 @@ return *this; } - ~class_info (void) = default; + ~class_info () = default; fcn_file_map_type method_file_map; fcn_file_map_type private_file_map; @@ -268,7 +268,7 @@ // This default constructor is only provided so we can create a // std::map of dir_info objects. You should not use this // constructor for any other purpose. - dir_info (void) = default; + dir_info () = default; dir_info (const std::string& d) : dir_name (d), abs_dir_name (), is_relative (false), @@ -280,11 +280,11 @@ dir_info (const dir_info&) = default; - ~dir_info (void) = default; + ~dir_info () = default; dir_info& operator = (const dir_info&) = default; - bool update (void); + bool update (); std::string dir_name; std::string abs_dir_name; @@ -301,7 +301,7 @@ private: - void initialize (void); + void initialize (); void get_file_list (const std::string& d); @@ -320,12 +320,14 @@ { public: + file_info () = delete; + file_info (const std::string& d, int t) : dir_name (d), types (t) { } file_info (const file_info& fi) : dir_name (fi.dir_name), types (fi.types) { } - ~file_info (void) = default; + ~file_info () = default; file_info& operator = (const file_info& fi) { @@ -404,7 +406,7 @@ m_private_fcn_map (l.m_private_fcn_map), m_method_map (l.m_method_map) { } - ~package_info (void) = default; + ~package_info () = default; package_info& operator = (const package_info& l) { @@ -438,7 +440,7 @@ void remove (const dir_info& di); - void clear (void) + void clear () { m_dir_list.clear (); @@ -468,7 +470,7 @@ void overloads (const std::string& meth, std::list& l) const; - string_vector fcn_names (void) const; + string_vector fcn_names () const; private: @@ -515,9 +517,9 @@ typedef package_map_type::const_iterator const_package_map_iterator; typedef package_map_type::iterator package_map_iterator; - std::function add_hook; + std::function m_add_hook; - std::function remove_hook; + std::function m_remove_hook; void execute_pkg_add_or_del (const std::string& dir, const std::string& script_file); @@ -558,6 +560,8 @@ string_vector get_file_list (const dir_info::fcn_file_map_type& lst) const; + std::string find_private_file (const std::string& fname) const; + friend dir_info::fcn_file_map_type get_fcn_files (const std::string& d); //-------- diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/load-save.cc --- a/libinterp/corefcn/load-save.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/load-save.cc Fri May 12 08:03:14 2023 +0200 @@ -43,6 +43,7 @@ #include "file-stat.h" #include "glob-match.h" #include "lo-mappers.h" +#include "lo-sysdep.h" #include "mach-info.h" #include "oct-env.h" #include "oct-locbuf.h" @@ -193,16 +194,12 @@ // Either no '.' in name or no '.' appears after last directory // separator. - sys::file_stat fs (fname); - - if (! (fs.exists () && fs.is_reg ())) + if (! (sys::file_exists (fname, false))) fname = find_file_to_load (fname + ".mat", orig_name); } else { - sys::file_stat fs (fname); - - if (! (fs.exists () && fs.is_reg ())) + if (! (sys::file_exists (fname, false))) { fname = ""; @@ -268,7 +265,7 @@ #endif } -load_save_system::~load_save_system (void) +load_save_system::~load_save_system () { #if defined (HAVE_HDF5) H5close (); @@ -732,7 +729,7 @@ } } -void load_save_system::dump_octave_core (void) +void load_save_system::dump_octave_core () { if (m_crash_dumps_octave_core) { @@ -1074,7 +1071,7 @@ m_interpreter.install_variable (name, val, global); } -std::string load_save_system::init_save_header_format (void) +std::string load_save_system::init_save_header_format () { return (std::string ("# Created by Octave " OCTAVE_VERSION @@ -1465,7 +1462,16 @@ print_usage (); else { - std::string fname = sys::file_ops::tilde_expand (argv[i]); + // For non-append mode, we make a new temporary filename, write to that + // instead of the file specified, then rename it at the end. + // That way, if something goes wrong during the save like OOM, + // we won't overwrite already-saved data in a file. + // See bug #63803 for context. + // In append mode, this kind of guard is counterproductive so we write + // directly to the specified file. + + std::string desiredname = sys::file_ops::tilde_expand (argv[i]); + std::string fname = desiredname + (append ? "" : ".saving_in_progress"); i++; @@ -1542,6 +1548,20 @@ file.close (); } } + + // If we are all the way here without Octave crashing or running + // out of memory etc, then we can say that writing to the + // temporary file was successful. So now we try to rename it to + // the actual file that was specified, unless we were in append mode + // in which case we take no action. + + if (! append) + { + std::string msg; + if (octave::sys::rename (fname, desiredname, msg) < 0) + error ("save: unable to save to %s %s", + desiredname.c_str (), msg.c_str ()); + } } return retval; @@ -2060,13 +2080,3 @@ } OCTAVE_END_NAMESPACE(octave) - -// DEPRECATED in Octave 7 - -void -dump_octave_core (void) -{ - octave::load_save_system& load_save_sys = octave::__get_load_save_system__ (); - - load_save_sys.dump_octave_core (); -} diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/load-save.h --- a/libinterp/corefcn/load-save.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/load-save.h Fri May 12 08:03:14 2023 +0200 @@ -75,16 +75,14 @@ OCTINTERP_API load_save_system (interpreter& interp); - OCTINTERP_API ~load_save_system (void); + OCTINTERP_API ~load_save_system (); - load_save_system (const load_save_system&) = delete; - - load_save_system& operator = (const load_save_system&) = delete; + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (load_save_system) OCTINTERP_API octave_value crash_dumps_octave_core (const octave_value_list& args, int nargout); - bool crash_dumps_octave_core (void) const + bool crash_dumps_octave_core () const { return m_crash_dumps_octave_core; } @@ -97,7 +95,7 @@ octave_value octave_core_file_limit (const octave_value_list& args, int nargout); - double octave_core_file_limit (void) const + double octave_core_file_limit () const { return m_octave_core_file_limit; } @@ -110,7 +108,7 @@ OCTINTERP_API octave_value octave_core_file_name (const octave_value_list& args, int nargout); - std::string octave_core_file_name (void) const + std::string octave_core_file_name () const { return m_octave_core_file_name; } @@ -123,7 +121,7 @@ OCTINTERP_API octave_value save_default_options (const octave_value_list& args, int nargout); - std::string save_default_options (void) const + std::string save_default_options () const { return m_save_default_options; } @@ -136,7 +134,7 @@ OCTINTERP_API octave_value octave_core_file_options (const octave_value_list& args, int nargout); - std::string octave_core_file_options (void) const + std::string octave_core_file_options () const { return m_octave_core_file_options; } @@ -149,7 +147,7 @@ OCTINTERP_API octave_value save_header_format_string (const octave_value_list& args, int nargout); - std::string save_header_format_string (void) const + std::string save_header_format_string () const { return m_save_header_format_string; } @@ -186,7 +184,7 @@ std::ostream& os, const load_save_format& fmt, bool save_as_floats, bool write_header_info); - OCTINTERP_API void dump_octave_core (void); + OCTINTERP_API void dump_octave_core (); OCTINTERP_API octave_value_list load (const octave_value_list& args = octave_value_list (), @@ -252,7 +250,7 @@ install_loaded_variable (const std::string& name, const octave_value& val, bool global, const std::string& /*doc*/); - static OCTINTERP_API std::string init_save_header_format (void); + static OCTINTERP_API std::string init_save_header_format (); static OCTINTERP_API load_save_format get_file_format (std::istream& file, const std::string& filename); @@ -277,14 +275,14 @@ void set_type (load_save_system::format_type type) { m_type = type; } - load_save_system::format_type type (void) const { return m_type; } + load_save_system::format_type type () const { return m_type; } void set_option (load_save_system::format_options option) { m_options |= option; } - int options (void) const { return m_options; } + int options () const { return m_options; } private: @@ -294,7 +292,4 @@ OCTAVE_END_NAMESPACE(octave) -OCTAVE_DEPRECATED (7, "use 'load_save_system::dump_octave_core' instead") -extern OCTINTERP_API void dump_octave_core (void); - #endif diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/ls-ascii-helper.h --- a/libinterp/corefcn/ls-ascii-helper.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/ls-ascii-helper.h Fri May 12 08:03:14 2023 +0200 @@ -44,29 +44,4 @@ OCTAVE_END_NAMESPACE(octave) -#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS) - -OCTAVE_DEPRECATED (7, "use 'octave::skip_until_newline' instead") -inline void -skip_until_newline (std::istream& is, bool keep_newline = false) -{ - return octave::skip_until_newline (is, keep_newline); -} - -OCTAVE_DEPRECATED (7, "use 'octave::skip_preceding_newline' instead") -inline void -skip_preceeding_newline (std::istream& is) -{ - return octave::skip_preceeding_newline (is); -} - -OCTAVE_DEPRECATED (7, "use 'octave::read_until_newline' instead") -inline std::string -read_until_newline (std::istream& is, bool keep_newline = false) -{ - return octave::read_until_newline (is, keep_newline); -} - #endif - -#endif diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/ls-hdf5.cc --- a/libinterp/corefcn/ls-hdf5.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/ls-hdf5.cc Fri May 12 08:03:14 2023 +0200 @@ -100,7 +100,7 @@ } void -hdf5_fstreambase::close (void) +hdf5_fstreambase::close () { #if defined (HAVE_HDF5) diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/ls-hdf5.h --- a/libinterp/corefcn/ls-hdf5.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/ls-hdf5.h Fri May 12 08:03:14 2023 +0200 @@ -51,12 +51,14 @@ hdf5_fstreambase () : file_id (-1), current_item () { } + OCTAVE_DISABLE_COPY_MOVE (hdf5_fstreambase) + ~hdf5_fstreambase () { close (); } OCTINTERP_API hdf5_fstreambase (const char *name, int mode, int /* prot */ = 0); - OCTINTERP_API void close (void); + OCTINTERP_API void close (); OCTINTERP_API void open (const char *name, int mode, int); @@ -101,9 +103,12 @@ struct hdf5_callback_data { public: - hdf5_callback_data (void) + + hdf5_callback_data () : name (), global (false), tc (), doc () { } + OCTAVE_DEFAULT_COPY_MOVE_DELETE (hdf5_callback_data) + // the following fields are set by hdf5_read_data on successful return: // the name of the variable diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/ls-mat5.cc --- a/libinterp/corefcn/ls-mat5.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/ls-mat5.cc Fri May 12 08:03:14 2023 +0200 @@ -44,6 +44,7 @@ #include "file-stat.h" #include "glob-match.h" #include "lo-mappers.h" +#include "lo-sysdep.h" #include "mach-info.h" #include "oct-env.h" #include "oct-locbuf.h" @@ -897,9 +898,8 @@ std::string str = (octave::config::octave_exec_home () + fpath.substr (mroot.length ())); - octave::sys::file_stat fs (str); - - if (fs.exists ()) + + if (octave::sys::file_exists (str)) { std::size_t xpos = str.find_last_of (octave::sys::file_ops::dir_sep_chars ()); @@ -1239,7 +1239,7 @@ { try { - octave_value_list tmp = octave::feval ("loadobj", tc, 1); + octave_value_list tmp = interp.feval ("loadobj", tc, 1); tc = tmp(0); } @@ -2724,14 +2724,16 @@ octave_map m; - octave::load_path& lp = octave::__get_load_path__ (); + octave::interpreter& interp = octave::__get_interpreter__ (); + + octave::load_path& lp = interp.get_load_path (); if (tc.isobject () && lp.find_method (tc.class_name (), "saveobj") != "") { try { - octave_value_list tmp = octave::feval ("saveobj", tc, 1); + octave_value_list tmp = interp.feval ("saveobj", tc, 1); m = tmp(0).map_value (); } diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/ls-utils.h --- a/libinterp/corefcn/ls-utils.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/ls-utils.h Fri May 12 08:03:14 2023 +0200 @@ -40,22 +40,4 @@ OCTAVE_END_NAMESPACE(octave) -#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS) - -OCTAVE_DEPRECATED (7, "use 'octave::get_save_type' instead") -inline save_type -get_save_type (double max_val, double min_val) -{ - return octave::get_save_type (max_val, min_val); -} - -OCTAVE_DEPRECATED (7, "use 'octave::get_save_type' instead") -inline save_type -get_save_type (float max_val, float min_val) -{ - return octave::get_save_type (max_val, min_val); -} - #endif - -#endif diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/lsode.cc --- a/libinterp/corefcn/lsode.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/lsode.cc Fri May 12 08:03:14 2023 +0200 @@ -37,11 +37,11 @@ #include "error.h" #include "errwarn.h" #include "interpreter-private.h" +#include "interpreter.h" #include "ovl.h" #include "ov-fcn.h" #include "ov-cell.h" #include "pager.h" -#include "parse.h" #include "pr-output.h" #include "unwind-prot.h" #include "utils.h" @@ -79,7 +79,9 @@ try { - tmp = octave::feval (lsode_fcn, args, 1); + interpreter& interp = __get_interpreter__ (); + + tmp = interp.feval (lsode_fcn, args, 1); } catch (octave::execution_exception& ee) { @@ -119,7 +121,9 @@ try { - tmp = octave::feval (lsode_jac, args, 1); + interpreter& interp = __get_interpreter__ (); + + tmp = interp.feval (lsode_jac, args, 1); } catch (octave::execution_exception& ee) { @@ -135,8 +139,7 @@ warned_jac_imaginary = true; } - retval = tmp( - 0).xmatrix_value ("lsode: expecting user supplied jacobian function to return numeric array"); + retval = tmp(0).xmatrix_value ("lsode: expecting user supplied jacobian function to return numeric array"); if (retval.isempty ()) err_user_supplied_eval ("lsode"); diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/mappers.cc --- a/libinterp/corefcn/mappers.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/mappers.cc Fri May 12 08:03:14 2023 +0200 @@ -2163,10 +2163,10 @@ %!error tanh (1, 2) */ -DEFUNX ("tolower", Ftolower, args, , - doc: /* -*- texinfo -*- -@deftypefn {} {@var{y} =} tolower (@var{s}) -@deftypefnx {} {@var{y} =} lower (@var{s}) +DEFUN (lower, args, , + doc: /* -*- texinfo -*- +@deftypefn {} {@var{y} =} lower (@var{s}) +@deftypefnx {} {@var{y} =} tolower (@var{s}) Return a copy of the string or cell string @var{s}, with each uppercase character replaced by the corresponding lowercase one; non-alphabetic characters are left unchanged. @@ -2175,15 +2175,15 @@ @example @group -tolower ("MiXeD cAsE 123") - @result{} "mixed case 123" +lower ("MiXeD cAsE 123") + @result{} "mixed case 123" @end group @end example -Programming Note: @code{lower} is an alias for @code{tolower} and either name +Programming Note: @code{tolower} is an alias for @code{lower} and either name can be used in Octave. -@seealso{toupper} +@seealso{upper} @end deftypefn */) { if (args.length () != 1) @@ -2192,24 +2192,24 @@ return ovl (args(0).xtolower ()); } -DEFALIAS (lower, tolower); +DEFALIAS (tolower, lower); /* -%!assert (tolower ("OCTAVE"), "octave") -%!assert (tolower ("123OCTave! _&"), "123octave! _&") -%!assert (tolower ({"ABC", "DEF", {"GHI", {"JKL"}}}), +%!assert (lower ("OCTAVE"), "octave") +%!assert (lower ("123OCTave! _&"), "123octave! _&") +%!assert (lower ({"ABC", "DEF", {"GHI", {"JKL"}}}), %! {"abc", "def", {"ghi", {"jkl"}}}) -%!assert (tolower (["ABC"; "DEF"]), ["abc"; "def"]) -%!assert (tolower ({["ABC"; "DEF"]}), {["abc";"def"]}) -%!assert (tolower (["ABCÄÖÜSS"; "abcäöüß"]), +%!assert (lower (["ABC"; "DEF"]), ["abc"; "def"]) +%!assert (lower ({["ABC"; "DEF"]}), {["abc";"def"]}) +%!assert (lower (["ABCÄÖÜSS"; "abcäöüß"]), %! ["abcäöüss"; "abcäöüß"]) -%!assert (tolower (repmat ("ÄÖÜ", 2, 1, 3)), repmat ("äöü", 2, 1, 3)) -%!assert (tolower (68), 68) -%!assert (tolower ({[68, 68; 68, 68]}), {[68, 68; 68, 68]}) -%!assert (tolower (68i), 68i) -%!assert (tolower ({[68i, 68; 68, 68i]}), {[68i, 68; 68, 68i]}) -%!assert (tolower (single (68i)), single (68i)) -%!assert (tolower ({single([68i, 68; 68, 68i])}), {single([68i, 68; 68, 68i])}) +%!assert (lower (repmat ("ÄÖÜ", 2, 1, 3)), repmat ("äöü", 2, 1, 3)) +%!assert (lower (68), 68) +%!assert (lower ({[68, 68; 68, 68]}), {[68, 68; 68, 68]}) +%!assert (lower (68i), 68i) +%!assert (lower ({[68i, 68; 68, 68i]}), {[68i, 68; 68, 68i]}) +%!assert (lower (single (68i)), single (68i)) +%!assert (lower ({single([68i, 68; 68, 68i])}), {single([68i, 68; 68, 68i])}) %!test %! classes = {@char, @double, @single, ... @@ -2217,28 +2217,28 @@ %! @uint8, @uint16, @uint32, @uint64}; %! for i = 1:numel (classes) %! cls = classes{i}; -%! assert (class (tolower (cls (97))), class (cls (97))); -%! assert (class (tolower (cls ([98, 99]))), class (cls ([98, 99]))); +%! assert (class (lower (cls (97))), class (cls (97))); +%! assert (class (lower (cls ([98, 99]))), class (cls ([98, 99]))); %! endfor %!test %! a(3,3,3,3) = "D"; -%! assert (tolower (a)(3,3,3,3), "d"); +%! assert (lower (a)(3,3,3,3), "d"); %!test %! charset = char (0:127); %! result = charset; %! result (double ("A":"Z") + 1) = result (double ("a":"z") + 1); -%! assert (tolower (charset), result); +%! assert (lower (charset), result); -%!error lower () -%!error tolower () -%!error tolower (1, 2) +%!error lower () +%!error tolower () +%!error lower (1, 2) */ -DEFUNX ("toupper", Ftoupper, args, , - doc: /* -*- texinfo -*- -@deftypefn {} {@var{y} =} toupper (@var{s}) -@deftypefnx {} {@var{y} =} upper (@var{s}) +DEFUN (upper, args, , + doc: /* -*- texinfo -*- +@deftypefn {} {@var{y} =} upper (@var{s}) +@deftypefnx {} {@var{y} =} toupper (@var{s}) Return a copy of the string or cell string @var{s}, with each lowercase character replaced by the corresponding uppercase one; non-alphabetic characters are left unchanged. @@ -2247,15 +2247,15 @@ @example @group -toupper ("MiXeD cAsE 123") - @result{} "MIXED CASE 123" +upper ("MiXeD cAsE 123") + @result{} "MIXED CASE 123" @end group @end example -Programming Note: @code{upper} is an alias for @code{toupper} and either name +Programming Note: @code{toupper} is an alias for @code{upper} and either name can be used in Octave. -@seealso{tolower} +@seealso{lower} @end deftypefn */) { if (args.length () != 1) @@ -2264,25 +2264,25 @@ return ovl (args(0).xtoupper ()); } -DEFALIAS (upper, toupper); +DEFALIAS (toupper, upper); /* -%!assert (toupper ("octave"), "OCTAVE") -%!assert (toupper ("123OCTave! _&"), "123OCTAVE! _&") -%!assert (toupper ({"abc", "def", {"ghi", {"jkl"}}}), +%!assert (upper ("octave"), "OCTAVE") +%!assert (upper ("123OCTave! _&"), "123OCTAVE! _&") +%!assert (upper ({"abc", "def", {"ghi", {"jkl"}}}), %! {"ABC", "DEF", {"GHI", {"JKL"}}}) -%!assert (toupper (["abc"; "def"]), ["ABC"; "DEF"]) -%!assert (toupper ({["abc"; "def"]}), {["ABC";"DEF"]}) -%!assert (toupper (["ABCÄÖÜSS"; "abcäöüß"]), +%!assert (upper (["abc"; "def"]), ["ABC"; "DEF"]) +%!assert (upper ({["abc"; "def"]}), {["ABC";"DEF"]}) +%!assert (upper (["ABCÄÖÜSS"; "abcäöüß"]), %! ["ABCÄÖÜSS"; "ABCÄÖÜSS"]) -%!assert (toupper (repmat ("äöü", 2, 1, 3)), repmat ("ÄÖÜ", 2, 1, 3)) -%!assert (toupper (100), 100) -%!assert (toupper ({[100, 100; 100, 100]}), {[100, 100; 100, 100]}) -%!assert (toupper (100i), 100i) -%!assert (toupper ({[100i, 100; 100, 100i]}), {[100i, 100; 100, 100i]}) -%!assert (toupper (single (100i)), single (100i)) -%!assert (toupper ({single([100i, 100; 100, 100i])}), -%! {single([100i, 100; 100, 100i])}) +%!assert (upper (repmat ("äöü", 2, 1, 3)), repmat ("ÄÖÜ", 2, 1, 3)) +%!assert (upper (100), 100) +%!assert (upper ({[100, 100; 100, 100]}), {[100, 100; 100, 100]}) +%!assert (upper (100i), 100i) +%!assert (upper ({[100i, 100; 100, 100i]}), {[100i, 100; 100, 100i]}) +%!assert (upper (single (100i)), single (100i)) +%!assert (upper ({single([100i, 100; 100, 100i])}), +%! {single([100i, 100; 100, 100i])}) %!test %! classes = {@char, @double, @single, ... @@ -2290,21 +2290,21 @@ %! @uint8, @uint16, @uint32, @uint64}; %! for i = 1:numel (classes) %! cls = classes{i}; -%! assert (class (toupper (cls (97))), class (cls (97))); -%! assert (class (toupper (cls ([98, 99]))), class (cls ([98, 99]))); +%! assert (class (upper (cls (97))), class (cls (97))); +%! assert (class (upper (cls ([98, 99]))), class (cls ([98, 99]))); %! endfor %!test %! a(3,3,3,3) = "d"; -%! assert (toupper (a)(3,3,3,3), "D"); +%! assert (upper (a)(3,3,3,3), "D"); %!test %! charset = char (0:127); %! result = charset; %! result (double ("a":"z") + 1) = result (double ("A":"Z") + 1); -%! assert (toupper (charset), result); +%! assert (upper (charset), result); -%!error toupper () -%!error upper () -%!error toupper (1, 2) +%!error upper () +%!error toupper () +%!error upper (1, 2) */ DEFALIAS (gammaln, lgamma); diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/mex.cc --- a/libinterp/corefcn/mex.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/mex.cc Fri May 12 08:03:14 2023 +0200 @@ -65,7 +65,6 @@ #include "ov-mex-fcn.h" #include "ov-usr-fcn.h" #include "pager.h" -#include "parse.h" #include "unwind-prot.h" #include "utils.h" #include "variables.h" @@ -218,17 +217,6 @@ extern OCTINTERP_API mxComplexDouble * mxGetComplexDoubles (const mxArray *p); extern OCTINTERP_API mxComplexSingle * mxGetComplexSingles (const mxArray *p); -#if 0 - /* We don't have these yet. */ - extern OCTINTERP_API mxComplexInt8 * mxGetComplexInt8s (const mxArray *p); - extern OCTINTERP_API mxComplexInt16 * mxGetComplexInt16s (const mxArray *p); - extern OCTINTERP_API mxComplexInt32 * mxGetComplexInt32s (const mxArray *p); - extern OCTINTERP_API mxComplexInt64 * mxGetComplexInt64s (const mxArray *p); - extern OCTINTERP_API mxComplexUint8 * mxGetComplexUint8s (const mxArray *p); - extern OCTINTERP_API mxComplexUint16 * mxGetComplexUint16s (const mxArray *p); - extern OCTINTERP_API mxComplexUint32 * mxGetComplexUint32s (const mxArray *p); - extern OCTINTERP_API mxComplexUint64 * mxGetComplexUint64s (const mxArray *p); -#endif extern OCTINTERP_API double * mxGetPi (const mxArray *ptr); extern OCTINTERP_API void * mxGetImagData (const mxArray *ptr); @@ -246,17 +234,6 @@ extern OCTINTERP_API int mxSetComplexDoubles (mxArray *p, mxComplexDouble *d); extern OCTINTERP_API int mxSetComplexSingles (mxArray *p, mxComplexSingle *d); -#if 0 - /* We don't have these yet. */ - extern OCTINTERP_API int mxSetComplexInt8s (mxArray *p, mxComplexInt8 *d); - extern OCTINTERP_API int mxSetComplexInt16s (mxArray *p, mxComplexInt16 *d); - extern OCTINTERP_API int mxSetComplexInt32s (mxArray *p, mxComplexInt32 *d); - extern OCTINTERP_API int mxSetComplexInt64s (mxArray *p, mxComplexInt64 *d); - extern OCTINTERP_API int mxSetComplexUint8s (mxArray *p, mxComplexUint8 *d); - extern OCTINTERP_API int mxSetComplexUint16s (mxArray *p, mxComplexUint16 *d); - extern OCTINTERP_API int mxSetComplexUint32s (mxArray *p, mxComplexUint32 *d); - extern OCTINTERP_API int mxSetComplexUint64s (mxArray *p, mxComplexUint64 *d); -#endif extern OCTINTERP_API void mxSetPi (mxArray *ptr, double *pi); extern OCTINTERP_API void mxSetImagData (mxArray *ptr, void *pi); @@ -471,6 +448,8 @@ { public: + mxArray_octave_value () = delete; + mxArray_octave_value (bool interleaved, const octave_value& ov) : mxArray_base (interleaved), m_val (ov), m_mutate_flag (false), m_id (mxUNKNOWN_CLASS), m_class_name (nullptr), m_ndims (-1), @@ -728,7 +707,7 @@ { if (m_val.issparse ()) { - // For sparse arrays, return the first non-zero value. + // For sparse arrays, return the first nonzero value. const void *m_data = m_val.mex_get_data (); if (m_data == nullptr) return 0.0; @@ -805,25 +784,6 @@ GET_DATA_METHOD (mxComplexSingle, get_complex_singles, mxDOUBLE_CLASS, mxCOMPLEX); -#if 0 - /* We don't have these yet. */ - GET_DATA_METHOD (mxComplexInt8 *, get_complex_int8s, (void), nullptr); - - GET_DATA_METHOD (mxComplexInt16 *, get_complex_int16s, (void), nullptr); - - GET_DATA_METHOD (mxComplexInt32 *, get_complex_int32s, (void), nullptr); - - GET_DATA_METHOD (mxComplexInt64 *, get_complex_int64s, (void), nullptr); - - GET_DATA_METHOD (mxComplexUint8 *, get_complex_uint8s, (void), nullptr); - - GET_DATA_METHOD (mxComplexUint16 *, get_complex_uint16s, (void), nullptr); - - GET_DATA_METHOD (mxComplexUint32 *, get_complex_uint32s, (void), nullptr); - - GET_DATA_METHOD (mxComplexUint64 *, get_complex_uint64s, (void), nullptr); -#endif - void * get_imag_data (void) const { void *retval = nullptr; @@ -852,17 +812,6 @@ MUTATION_METHOD (int, set_complex_doubles, (mxComplexDouble *), 0) MUTATION_METHOD (int, set_complex_singles, (mxComplexSingle *), 0) -#if 0 - /* We don't have these yet. */ - MUTATION_METHOD (int, set_complex_int8s, (mxComplexInt8 *), 0) - MUTATION_METHOD (int, set_complex_int16s, (mxComplexInt16 *), 0) - MUTATION_METHOD (int, set_complex_int32s, (mxComplexInt32 *), 0) - MUTATION_METHOD (int, set_complex_int64s, (mxComplexInt64 *), 0) - MUTATION_METHOD (int, set_complex_uint8s, (mxComplexUint8 *), 0) - MUTATION_METHOD (int, set_complex_uint16s, (mxComplexUint16 *), 0) - MUTATION_METHOD (int, set_complex_uint32s, (mxComplexUint32 *), 0) - MUTATION_METHOD (int, set_complex_uint64s, (mxComplexUint64 *), 0) -#endif // Not allowed. VOID_MUTATION_METHOD (set_imag_data, (void *)) @@ -1052,11 +1001,13 @@ { public: + mxArray_matlab () = delete; + // No assignment! // FIXME: should this be implemented? // Note that we *do* have a copy constructor. - mxArray_matlab& operator = (const mxArray_matlab&); + mxArray_matlab& operator = (const mxArray_matlab&) = delete; ~mxArray_matlab (void) { @@ -1290,49 +1241,6 @@ err_invalid_type ("get_complex_singles"); } -#if 0 - /* We don't have these yet. */ - mxComplexInt8 * get_complex_int8s (void) const - { - err_invalid_type ("get_complex_int8s"); - } - - mxComplexInt16 * get_complex_int16s (void) const - { - err_invalid_type ("get_complex_int16s"); - } - - mxComplexInt32 * get_complex_int32s (void) const - { - err_invalid_type ("get_complex_int32s"); - } - - mxComplexInt64 * get_complex_int64s (void) const - { - err_invalid_type ("get_complex_int64s"); - } - - mxComplexUint8 * get_complex_uint8s (void) const - { - err_invalid_type ("get_complex_uint8s"); - } - - mxComplexUint16 * get_complex_uint16s (void) const - { - err_invalid_type ("get_complex_uint16s"); - } - - mxComplexUint32 * get_complex_uint32s (void) const - { - err_invalid_type ("get_complex_uint32s"); - } - - mxComplexUint64 * get_complex_uint64s (void) const - { - err_invalid_type ("get_complex_uint64s"); - } -#endif - void * get_imag_data (void) const { err_invalid_type ("get_imag_data"); @@ -1403,49 +1311,6 @@ err_invalid_type ("set_complex_singles"); } -#if 0 - /* We don't have these yet. */ - int set_complex_int8s (mxComplexInt8 *) - { - err_invalid_type ("set_complex_int8s"); - } - - int set_complex_int16s (mxComplexInt16 *) - { - err_invalid_type ("set_complex_int16s"); - } - - int set_complex_int32s (mxComplexInt32 *) - { - err_invalid_type ("set_complex_int32s"); - } - - int set_complex_int64s (mxComplexInt64 *) - { - err_invalid_type ("set_complex_int64s"); - } - - int set_complex_uint8s (mxComplexUint8 *) - { - err_invalid_type ("set_complex_uint8s"); - } - - int set_complex_uint16s (mxComplexUint16 *) - { - err_invalid_type ("set_complex_uint16s"); - } - - int set_complex_uint32s (mxComplexUint32 *) - { - err_invalid_type ("set_complex_uint32s"); - } - - int set_complex_uint64s (mxComplexUint64 *) - { - err_invalid_type ("set_complex_uint64s"); - } -#endif - void set_imag_data (void * /*pi*/) { err_invalid_type ("set_imag_data"); @@ -1661,6 +1526,8 @@ { public: + mxArray_base_full () = delete; + mxArray_base_full (bool interleaved, mxClassID id, mwSize ndims, const mwSize *dims, bool init = true) : mxArray_matlab (interleaved, id, ndims, dims), @@ -1734,7 +1601,7 @@ // No assignment! FIXME: should this be implemented? Note that we // do have a copy constructor. - mxArray_base_full& operator = (const mxArray_base_full&); + mxArray_base_full& operator = (const mxArray_base_full&) = delete; mxArray_base * dup (void) const { @@ -1878,58 +1745,6 @@ return static_cast (m_pr); } -#if 0 - // We don't have these data types. - - int get_complex_int8s (mxComplexInt8 *d) - { - m_pr = d; - return 0; - } - - int get_complex_int16s (mxComplexInt16 *d) - { - m_pr = d; - return 0; - } - - int get_complex_int32s (mxComplexInt32 *d) - { - m_pr = d; - return 0; - } - - int get_complex_int64s (mxComplexInt64 *d) - { - m_pr = d; - return 0; - } - - int get_complex_uint8s (mxComplexUint8 *d) - { - m_pr = d; - return 0; - } - - int get_complex_uint16s (mxComplexUint16 *d) - { - m_pr = d; - return 0; - } - - int get_complex_uint32s (mxComplexUint32 *d) - { - m_pr = d; - return 0; - } - - int get_complex_uint64s (mxComplexUint64 *d) - { - m_pr = d; - return 0; - } -#endif - int set_doubles (mxDouble *d) { m_pr = d; @@ -2002,58 +1817,6 @@ return 0; } -#if 0 - // We don't have these data types. - - int set_complex_int8s (mxComplexInt8 *d) - { - m_pr = d; - return 0; - } - - int set_complex_int16s (mxComplexInt16 *d) - { - m_pr = d; - return 0; - } - - int set_complex_int32s (mxComplexInt32 *d) - { - m_pr = d; - return 0; - } - - int set_complex_int64s (mxComplexInt64 *d) - { - m_pr = d; - return 0; - } - - int set_complex_uint8s (mxComplexUint8 *d) - { - m_pr = d; - return 0; - } - - int set_complex_uint16s (mxComplexUint16 *d) - { - m_pr = d; - return 0; - } - - int set_complex_uint32s (mxComplexUint32 *d) - { - m_pr = d; - return 0; - } - - int set_complex_uint64s (mxComplexUint64 *d) - { - m_pr = d; - return 0; - } -#endif - int get_string (char *buf, mwSize buflen) const { int retval = 0; @@ -2211,17 +1974,6 @@ ELT_T *ppr = static_cast (m_pr); -#if 0 && defined (OCTAVE_HAVE_STD_PMR_POLYMORPHIC_ALLOCATOR) - - // FIXME: Currently not allowed because we don't have the necessary - // constructors for integer arrays. - - octave::unwind_action act ([=] () { maybe_disown_ptr (m_pr); }); - - return ARRAY_T (ppr, dv, current_mx_memory_resource); - -#else - // Copy data instead of allowing the octave_value object to borrow // the mxArray object data. @@ -2236,7 +1988,6 @@ return octave_value (val); -#endif } protected: @@ -2251,6 +2002,8 @@ { public: + mxArray_interleaved_full () = delete; + mxArray_interleaved_full (mxClassID id, mwSize ndims, const mwSize *dims, mxComplexity flag = mxREAL, bool init = true) : mxArray_base_full (true, id, ndims, dims, init), @@ -2289,7 +2042,7 @@ // No assignment! FIXME: should this be implemented? Note that we // do have a copy constructor. - mxArray_interleaved_full& operator = (const mxArray_interleaved_full&); + mxArray_interleaved_full& operator = (const mxArray_interleaved_full&) = delete; mxArray_base * dup (void) const { @@ -2318,6 +2071,8 @@ { public: + mxArray_separate_full () = delete; + mxArray_separate_full (mxClassID id, mwSize ndims, const mwSize *dims, mxComplexity flag = mxREAL, bool init = true) : mxArray_base_full (false, id, ndims, dims, init), @@ -2362,7 +2117,7 @@ // No assignment! FIXME: should this be implemented? Note that we // do have a copy constructor. - mxArray_separate_full& operator = (const mxArray_separate_full&); + mxArray_separate_full& operator = (const mxArray_separate_full&) = delete; mxArray_base * dup (void) const { @@ -2512,6 +2267,8 @@ { public: + mxArray_base_sparse () = delete; + mxArray_base_sparse (bool interleaved, mxClassID id, mwSize m, mwSize n, mwSize nzmax) : mxArray_matlab (interleaved, id, m, n), @@ -2545,7 +2302,7 @@ // No assignment! FIXME: should this be implemented? Note that we // do have a copy constructor. - mxArray_base_sparse& operator = (const mxArray_base_sparse&); + mxArray_base_sparse& operator = (const mxArray_base_sparse&) = delete; mxArray_base * dup (void) const { @@ -2695,6 +2452,8 @@ { public: + mxArray_interleaved_sparse () = delete; + mxArray_interleaved_sparse (mxClassID id, mwSize m, mwSize n, mwSize nzmax, mxComplexity flag = mxREAL) : mxArray_base_sparse (true, id, m, n, nzmax), @@ -2712,7 +2471,7 @@ // No assignment! FIXME: should this be implemented? Note that we // do have a copy constructor. - mxArray_interleaved_sparse& operator = (const mxArray_interleaved_sparse&); + mxArray_interleaved_sparse& operator = (const mxArray_interleaved_sparse&) = delete; mxArray_base * dup (void) const { @@ -2738,6 +2497,8 @@ { public: + mxArray_separate_sparse () = delete; + mxArray_separate_sparse (mxClassID id, mwSize m, mwSize n, mwSize nzmax, mxComplexity flag = mxREAL) : mxArray_base_sparse (false, id, m, n, nzmax), @@ -2763,7 +2524,7 @@ // No assignment! FIXME: should this be implemented? Note that we // do have a copy constructor. - mxArray_separate_sparse& operator = (const mxArray_separate_sparse&); + mxArray_separate_sparse& operator = (const mxArray_separate_sparse&) = delete; mxArray_base * dup (void) const { @@ -2844,6 +2605,8 @@ { public: + mxArray_struct () = delete; + mxArray_struct (bool interleaved, mwSize ndims, const mwSize *dims, int num_keys, const char **keys) : mxArray_matlab (interleaved, mxSTRUCT_CLASS, ndims, dims), @@ -2910,7 +2673,7 @@ // No assignment! FIXME: should this be implemented? Note that we // do have a copy constructor. - mxArray_struct& operator = (const mxArray_struct& val); + mxArray_struct& operator = (const mxArray_struct& val) = delete; void init (const char **keys) { @@ -3111,30 +2874,28 @@ { public: + mxArray_cell () = delete; + mxArray_cell (bool interleaved, mwSize ndims, const mwSize *dims) : mxArray_matlab (interleaved, mxCELL_CLASS, ndims, dims), - m_data (static_cast ( - mxArray::calloc (get_number_of_elements (), sizeof (mxArray *)))) + m_data (static_cast (mxArray::calloc (get_number_of_elements (), sizeof (mxArray *)))) { } mxArray_cell (bool interleaved, const dim_vector& dv) : mxArray_matlab (interleaved, mxCELL_CLASS, dv), - m_data (static_cast ( - mxArray::calloc (get_number_of_elements (), sizeof (mxArray *)))) + m_data (static_cast (mxArray::calloc (get_number_of_elements (), sizeof (mxArray *)))) { } mxArray_cell (bool interleaved, mwSize m, mwSize n) : mxArray_matlab (interleaved, mxCELL_CLASS, m, n), - m_data (static_cast ( - mxArray::calloc (get_number_of_elements (), sizeof (mxArray *)))) + m_data (static_cast (mxArray::calloc (get_number_of_elements (), sizeof (mxArray *)))) { } private: mxArray_cell (const mxArray_cell& val) : mxArray_matlab (val), - m_data (static_cast ( - mxArray::malloc (get_number_of_elements () * sizeof (mxArray *)))) + m_data (static_cast (mxArray::malloc (get_number_of_elements () * sizeof (mxArray *)))) { mwSize nel = get_number_of_elements (); @@ -3150,7 +2911,7 @@ // No assignment! FIXME: should this be implemented? Note that we // do have a copy constructor. - mxArray_cell& operator = (const mxArray_cell&); + mxArray_cell& operator = (const mxArray_cell&) = delete; mxArray_base * dup (void) const { return new mxArray_cell (*this); } @@ -3415,11 +3176,7 @@ mex (octave_mex_function& f) : m_curr_mex_fcn (f), m_memlist (), m_arraylist (), m_fname (nullptr) { } - // No copying! - - mex (const mex&) = delete; - - mex& operator = (const mex&) = delete; + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (mex) ~mex (void) { @@ -4441,49 +4198,6 @@ return ptr->get_complex_singles (); } -#if 0 -/* We don't have these yet. */ -mxComplexInt8 * mxGetComplexInt8s (const mxArray *ptr) -{ - return ptr->get_complex_int8s (); -} - -mxComplexInt16 * mxGetComplexInt16s (const mxArray *ptr) -{ - return ptr->get_complex_int16s (); -} - -mxComplexInt32 * mxGetComplexInt32s (const mxArray *ptr) -{ - return ptr->get_complex_int32s (); -} - -mxComplexInt64 * mxGetComplexInt64s (const mxArray *ptr) -{ - return ptr->get_complex_int64s (); -} - -mxComplexUint8 * mxGetComplexUint8s (const mxArray *ptr) -{ - return ptr->get_complex_uint8s (); -} - -mxComplexUint16 * mxGetComplexUint16s (const mxArray *ptr) -{ - return ptr->get_complex_uint16s (); -} - -mxComplexUint32 * mxGetComplexUint32s (const mxArray *ptr) -{ - return ptr->get_complex_uint32s (); -} - -mxComplexUint64 * mxGetComplexUint64s (const mxArray *ptr) -{ - return ptr->get_complex_uint64s (); -} -#endif - // Data setters. void mxSetPr (mxArray *ptr, double *pr) @@ -4557,49 +4271,6 @@ return ptr->set_complex_singles (maybe_unmark (data)); } -#if 0 -/* We don't have these yet. */ -int mxSetComplexInt8s (mxArray *ptr, mxComplexInt8 *data) -{ - return ptr->set_complex_int8s (maybe_unmark (data)); -} - -int mxSetComplexInt16s (mxArray *ptr, mxComplexInt16 *data) -{ - return ptr->set_complex_int16s (maybe_unmark (data)); -} - -int mxSetComplexInt32s (mxArray *ptr, mxComplexInt32 *data) -{ - return ptr->set_complex_int32s (maybe_unmark (data)); -} - -int mxSetComplexInt64s (mxArray *ptr, mxComplexInt64 *data) -{ - return ptr->set_complex_int64s (maybe_unmark (data)); -} - -int mxSetComplexUint8s (mxArray *ptr, mxComplexUint8 *data) -{ - return ptr->set_complex_uint8s (maybe_unmark (data)); -} - -int mxSetComplexUint16s (mxArray *ptr, mxComplexUint16 *data) -{ - return ptr->set_complex_uint16s (maybe_unmark (data)); -} - -int mxSetComplexUint32s (mxArray *ptr, mxComplexUint32 *data) -{ - return ptr->set_complex_uint32s (maybe_unmark (data)); -} - -int mxSetComplexUint64s (mxArray *ptr, mxComplexUint64 *data) -{ - return ptr->set_complex_uint64s (maybe_unmark (data)); -} -#endif - void mxSetPi (mxArray *ptr, double *pi) { @@ -4917,7 +4588,7 @@ tw.set_lvalue_list (nullptr); - retval = octave::feval (fname, args, nargout); + retval = interp.feval (fname, args, nargout); } catch (const octave::execution_exception&) { diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/mexproto.h --- a/libinterp/corefcn/mexproto.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/mexproto.h Fri May 12 08:03:14 2023 +0200 @@ -287,17 +287,6 @@ extern OCTINTERP_API mxComplexDouble * mxGetComplexDoubles (const mxArray *p); extern OCTINTERP_API mxComplexSingle * mxGetComplexSingles (const mxArray *p); -#if 0 -/* We don't have these yet. */ -extern OCTINTERP_API mxComplexInt8 * mxGetComplexInt8s (const mxArray *p); -extern OCTINTERP_API mxComplexInt16 * mxGetComplexInt16s (const mxArray *p); -extern OCTINTERP_API mxComplexInt32 * mxGetComplexInt32s (const mxArray *p); -extern OCTINTERP_API mxComplexInt64 * mxGetComplexInt64s (const mxArray *p); -extern OCTINTERP_API mxComplexUint8 * mxGetComplexUint8s (const mxArray *p); -extern OCTINTERP_API mxComplexUint16 * mxGetComplexUint16s (const mxArray *p); -extern OCTINTERP_API mxComplexUint32 * mxGetComplexUint32s (const mxArray *p); -extern OCTINTERP_API mxComplexUint64 * mxGetComplexUint64s (const mxArray *p); -#endif #else extern OCTINTERP_API double * mxGetPi (const mxArray *ptr); extern OCTINTERP_API void * mxGetImagData (const mxArray *ptr); @@ -320,17 +309,6 @@ extern OCTINTERP_API int mxSetComplexDoubles (mxArray *p, mxComplexDouble *d); extern OCTINTERP_API int mxSetComplexSingles (mxArray *p, mxComplexSingle *d); -#if 0 -/* We don't have these yet. */ -extern OCTINTERP_API int mxSetComplexInt8s (mxArray *p, mxComplexInt8 *d); -extern OCTINTERP_API int mxSetComplexInt16s (mxArray *p, mxComplexInt16 *d); -extern OCTINTERP_API int mxSetComplexInt32s (mxArray *p, mxComplexInt32 *d); -extern OCTINTERP_API int mxSetComplexInt64s (mxArray *p, mxComplexInt64 *d); -extern OCTINTERP_API int mxSetComplexUint8s (mxArray *p, mxComplexUint8 *d); -extern OCTINTERP_API int mxSetComplexUint16s (mxArray *p, mxComplexUint16 *d); -extern OCTINTERP_API int mxSetComplexUint32s (mxArray *p, mxComplexUint32 *d); -extern OCTINTERP_API int mxSetComplexUint64s (mxArray *p, mxComplexUint64 *d); -#endif #else extern OCTINTERP_API void mxSetPi (mxArray *ptr, double *pi); extern OCTINTERP_API void mxSetImagData (mxArray *ptr, void *pi); diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/module.mk --- a/libinterp/corefcn/module.mk Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/module.mk Fri May 12 08:03:14 2023 +0200 @@ -38,6 +38,7 @@ %reldir%/fcn-info.h \ %reldir%/file-io.h \ %reldir%/ft-text-renderer.h \ + %reldir%/gh-manager.h \ %reldir%/gl-render.h \ %reldir%/gl2ps-print.h \ %reldir%/graphics-handle.h \ @@ -102,6 +103,7 @@ %reldir%/gzfstream.h NOINSTALL_COREFCN_INC = \ + %reldir%/graphics-utils.h \ %reldir%/interpreter-private.h \ %reldir%/mex-private.h \ %reldir%/oct-hdf5.h \ @@ -176,10 +178,12 @@ %reldir%/getgrent.cc \ %reldir%/getpwent.cc \ %reldir%/getrusage.cc \ + %reldir%/gh-manager.cc \ %reldir%/givens.cc \ %reldir%/gl-render.cc \ %reldir%/gl2ps-print.cc \ %reldir%/graphics-toolkit.cc \ + %reldir%/graphics-utils.cc \ %reldir%/graphics.cc \ %reldir%/gsvd.cc \ %reldir%/gtk-manager.cc \ @@ -231,6 +235,7 @@ %reldir%/ordqz.cc \ %reldir%/ordschur.cc \ %reldir%/pager.cc \ + %reldir%/perms.cc \ %reldir%/pinv.cc \ %reldir%/pow2.cc \ %reldir%/pr-flt-fmt.cc \ diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/mxarray.h --- a/libinterp/corefcn/mxarray.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/mxarray.h Fri May 12 08:03:14 2023 +0200 @@ -94,17 +94,21 @@ public: - virtual mxArray_base * dup (void) const = 0; + mxArray_base () = delete; + + OCTAVE_DEFAULT_COPY_MOVE (mxArray_base) - virtual mxArray * as_mxArray (void) const { return nullptr; } + virtual mxArray_base * dup () const = 0; - virtual ~mxArray_base (void) = default; + virtual mxArray * as_mxArray () const { return nullptr; } - virtual bool is_octave_value (void) const { return false; } + virtual ~mxArray_base () = default; + + virtual bool is_octave_value () const { return false; } - virtual int iscell (void) const = 0; + virtual int iscell () const = 0; - virtual int is_char (void) const = 0; + virtual int is_char () const = 0; virtual int is_class (const char *name_arg) const { @@ -118,52 +122,52 @@ return retval; } - virtual int is_complex (void) const = 0; + virtual int is_complex () const = 0; - virtual int is_double (void) const = 0; + virtual int is_double () const = 0; - virtual int is_function_handle (void) const = 0; + virtual int is_function_handle () const = 0; - virtual int is_int16 (void) const = 0; + virtual int is_int16 () const = 0; - virtual int is_int32 (void) const = 0; + virtual int is_int32 () const = 0; - virtual int is_int64 (void) const = 0; + virtual int is_int64 () const = 0; - virtual int is_int8 (void) const = 0; + virtual int is_int8 () const = 0; - virtual int is_logical (void) const = 0; + virtual int is_logical () const = 0; - virtual int is_numeric (void) const = 0; + virtual int is_numeric () const = 0; - virtual int is_single (void) const = 0; + virtual int is_single () const = 0; - virtual int is_sparse (void) const = 0; + virtual int is_sparse () const = 0; - virtual int is_struct (void) const = 0; + virtual int is_struct () const = 0; - virtual int is_uint16 (void) const = 0; + virtual int is_uint16 () const = 0; - virtual int is_uint32 (void) const = 0; + virtual int is_uint32 () const = 0; - virtual int is_uint64 (void) const = 0; + virtual int is_uint64 () const = 0; - virtual int is_uint8 (void) const = 0; + virtual int is_uint8 () const = 0; - virtual int is_logical_scalar (void) const + virtual int is_logical_scalar () const { return is_logical () && get_number_of_elements () == 1; } - virtual int is_logical_scalar_true (void) const = 0; + virtual int is_logical_scalar_true () const = 0; - virtual mwSize get_m (void) const = 0; + virtual mwSize get_m () const = 0; - virtual mwSize get_n (void) const = 0; + virtual mwSize get_n () const = 0; - virtual mwSize * get_dimensions (void) const = 0; + virtual mwSize * get_dimensions () const = 0; - virtual mwSize get_number_of_dimensions (void) const = 0; + virtual mwSize get_number_of_dimensions () const = 0; virtual void set_m (mwSize m) = 0; @@ -171,15 +175,15 @@ virtual int set_dimensions (mwSize *dims_arg, mwSize ndims_arg) = 0; - virtual mwSize get_number_of_elements (void) const = 0; + virtual mwSize get_number_of_elements () const = 0; - virtual int isempty (void) const = 0; + virtual int isempty () const = 0; - virtual bool is_scalar (void) const = 0; + virtual bool is_scalar () const = 0; - virtual mxClassID get_class_id (void) const = 0; + virtual mxClassID get_class_id () const = 0; - virtual const char * get_class_name (void) const = 0; + virtual const char * get_class_name () const = 0; virtual void set_class_name (const char *name_arg) = 0; @@ -207,36 +211,25 @@ virtual void set_cell (mwIndex idx, mxArray *val) = 0; - virtual double get_scalar (void) const = 0; - - virtual void * get_data (void) const = 0; + virtual double get_scalar () const = 0; - virtual mxDouble * get_doubles (void) const = 0; - virtual mxSingle * get_singles (void) const = 0; - virtual mxInt8 * get_int8s (void) const = 0; - virtual mxInt16 * get_int16s (void) const = 0; - virtual mxInt32 * get_int32s (void) const = 0; - virtual mxInt64 * get_int64s (void) const = 0; - virtual mxUint8 * get_uint8s (void) const = 0; - virtual mxUint16 * get_uint16s (void) const = 0; - virtual mxUint32 * get_uint32s (void) const = 0; - virtual mxUint64 * get_uint64s (void) const = 0; + virtual void * get_data () const = 0; - virtual mxComplexDouble * get_complex_doubles (void) const = 0; - virtual mxComplexSingle * get_complex_singles (void) const = 0; -#if 0 - /* We don't have these yet. */ - virtual mxComplexInt8 * get_complex_int8s (void) const = 0; - virtual mxComplexInt16 * get_complex_int16s (void) const = 0; - virtual mxComplexInt32 * get_complex_int32s (void) const = 0; - virtual mxComplexInt64 * get_complex_int64s (void) const = 0; - virtual mxComplexUint8 * get_complex_uint8s (void) const = 0; - virtual mxComplexUint16 * get_complex_uint16s (void) const = 0; - virtual mxComplexUint32 * get_complex_uint32s (void) const = 0; - virtual mxComplexUint64 * get_complex_uint64s (void) const = 0; -#endif + virtual mxDouble * get_doubles () const = 0; + virtual mxSingle * get_singles () const = 0; + virtual mxInt8 * get_int8s () const = 0; + virtual mxInt16 * get_int16s () const = 0; + virtual mxInt32 * get_int32s () const = 0; + virtual mxInt64 * get_int64s () const = 0; + virtual mxUint8 * get_uint8s () const = 0; + virtual mxUint16 * get_uint16s () const = 0; + virtual mxUint32 * get_uint32s () const = 0; + virtual mxUint64 * get_uint64s () const = 0; - virtual void * get_imag_data (void) const = 0; + virtual mxComplexDouble * get_complex_doubles () const = 0; + virtual mxComplexSingle * get_complex_singles () const = 0; + + virtual void * get_imag_data () const = 0; virtual void set_data (void *pr) = 0; @@ -253,25 +246,14 @@ virtual int set_complex_doubles (mxComplexDouble *data) = 0; virtual int set_complex_singles (mxComplexSingle *data) = 0; -#if 0 - /* We don't have these yet. */ - virtual int set_complex_int8s (mxComplexInt8 *data) = 0; - virtual int set_complex_int16s (mxComplexInt16 *data) = 0; - virtual int set_complex_int32s (mxComplexInt32 *data) = 0; - virtual int set_complex_int64s (mxComplexInt64 *data) = 0; - virtual int set_complex_uint8s (mxComplexUint8 *data) = 0; - virtual int set_complex_uint16s (mxComplexUint16 *data) = 0; - virtual int set_complex_uint32s (mxComplexUint32 *data) = 0; - virtual int set_complex_uint64s (mxComplexUint64 *data) = 0; -#endif virtual void set_imag_data (void *pi) = 0; - virtual mwIndex * get_ir (void) const = 0; + virtual mwIndex * get_ir () const = 0; - virtual mwIndex * get_jc (void) const = 0; + virtual mwIndex * get_jc () const = 0; - virtual mwSize get_nzmax (void) const = 0; + virtual mwSize get_nzmax () const = 0; virtual void set_ir (mwIndex *ir) = 0; @@ -288,7 +270,7 @@ virtual void set_field_by_number (mwIndex index, int key_num, mxArray *val) = 0; - virtual int get_number_of_fields (void) const = 0; + virtual int get_number_of_fields () const = 0; virtual const char * get_field_name_by_number (int key_num) const = 0; @@ -296,22 +278,20 @@ virtual int get_string (char *buf, mwSize buflen) const = 0; - virtual char * array_to_string (void) const = 0; + virtual char * array_to_string () const = 0; virtual mwIndex calc_single_subscript (mwSize nsubs, mwIndex *subs) const = 0; - virtual std::size_t get_element_size (void) const = 0; + virtual std::size_t get_element_size () const = 0; - virtual bool mutation_needed (void) const { return false; } + virtual bool mutation_needed () const { return false; } - virtual mxArray * mutate (void) const { return nullptr; } + virtual mxArray * mutate () const { return nullptr; } - virtual octave_value as_octave_value (void) const = 0; + virtual octave_value as_octave_value () const = 0; protected: - mxArray_base (const mxArray_base&) = default; - std::size_t get_numeric_element_size (std::size_t size) const { return (m_interleaved @@ -377,7 +357,7 @@ OCTINTERP_API mxArray (bool interleaved, mwSize m, mwSize n); - mxArray * dup (void) const + mxArray * dup () const { mxArray *retval = m_rep->as_mxArray (); @@ -393,66 +373,62 @@ return retval; } - // No copying! + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (mxArray) - mxArray (const mxArray&) = delete; - - mxArray& operator = (const mxArray&) = delete; + OCTINTERP_API ~mxArray (); - OCTINTERP_API ~mxArray (void); - - bool is_octave_value (void) const { return m_rep->is_octave_value (); } + bool is_octave_value () const { return m_rep->is_octave_value (); } - int iscell (void) const { return m_rep->iscell (); } + int iscell () const { return m_rep->iscell (); } - int is_char (void) const { return m_rep->is_char (); } + int is_char () const { return m_rep->is_char (); } int is_class (const char *name_arg) const { return m_rep->is_class (name_arg); } - int is_complex (void) const { return m_rep->is_complex (); } + int is_complex () const { return m_rep->is_complex (); } - int is_double (void) const { return m_rep->is_double (); } + int is_double () const { return m_rep->is_double (); } - int is_function_handle (void) const { return m_rep->is_function_handle (); } + int is_function_handle () const { return m_rep->is_function_handle (); } - int is_int16 (void) const { return m_rep->is_int16 (); } + int is_int16 () const { return m_rep->is_int16 (); } - int is_int32 (void) const { return m_rep->is_int32 (); } + int is_int32 () const { return m_rep->is_int32 (); } - int is_int64 (void) const { return m_rep->is_int64 (); } + int is_int64 () const { return m_rep->is_int64 (); } - int is_int8 (void) const { return m_rep->is_int8 (); } + int is_int8 () const { return m_rep->is_int8 (); } - int is_logical (void) const { return m_rep->is_logical (); } + int is_logical () const { return m_rep->is_logical (); } - int is_numeric (void) const { return m_rep->is_numeric (); } + int is_numeric () const { return m_rep->is_numeric (); } - int is_single (void) const { return m_rep->is_single (); } + int is_single () const { return m_rep->is_single (); } - int is_sparse (void) const { return m_rep->is_sparse (); } + int is_sparse () const { return m_rep->is_sparse (); } - int is_struct (void) const { return m_rep->is_struct (); } + int is_struct () const { return m_rep->is_struct (); } - int is_uint16 (void) const { return m_rep->is_uint16 (); } + int is_uint16 () const { return m_rep->is_uint16 (); } - int is_uint32 (void) const { return m_rep->is_uint32 (); } + int is_uint32 () const { return m_rep->is_uint32 (); } - int is_uint64 (void) const { return m_rep->is_uint64 (); } + int is_uint64 () const { return m_rep->is_uint64 (); } - int is_uint8 (void) const { return m_rep->is_uint8 (); } + int is_uint8 () const { return m_rep->is_uint8 (); } - int is_logical_scalar (void) const { return m_rep->is_logical_scalar (); } + int is_logical_scalar () const { return m_rep->is_logical_scalar (); } - int is_logical_scalar_true (void) const + int is_logical_scalar_true () const { return m_rep->is_logical_scalar_true (); } - mwSize get_m (void) const { return m_rep->get_m (); } + mwSize get_m () const { return m_rep->get_m (); } - mwSize get_n (void) const { return m_rep->get_n (); } + mwSize get_n () const { return m_rep->get_n (); } - mwSize * get_dimensions (void) const { return m_rep->get_dimensions (); } + mwSize * get_dimensions () const { return m_rep->get_dimensions (); } - mwSize get_number_of_dimensions (void) const + mwSize get_number_of_dimensions () const { return m_rep->get_number_of_dimensions (); } void set_m (mwSize m) { DO_VOID_MUTABLE_METHOD (set_m (m)); } @@ -462,20 +438,20 @@ int set_dimensions (mwSize *dims_arg, mwSize ndims_arg) { DO_MUTABLE_METHOD (int, set_dimensions (dims_arg, ndims_arg)); } - mwSize get_number_of_elements (void) const + mwSize get_number_of_elements () const { return m_rep->get_number_of_elements (); } - int isempty (void) const { return get_number_of_elements () == 0; } + int isempty () const { return get_number_of_elements () == 0; } - bool is_scalar (void) const { return m_rep->is_scalar (); } + bool is_scalar () const { return m_rep->is_scalar (); } - const char * get_name (void) const { return m_name; } + const char * get_name () const { return m_name; } OCTINTERP_API void set_name (const char *name); - mxClassID get_class_id (void) const { return m_rep->get_class_id (); } + mxClassID get_class_id () const { return m_rep->get_class_id (); } - const char * get_class_name (void) const { return m_rep->get_class_name (); } + const char * get_class_name () const { return m_rep->get_class_name (); } mxArray * get_property (mwIndex idx, const char *pname) const { return m_rep->get_property (idx, pname); } @@ -492,74 +468,47 @@ void set_cell (mwIndex idx, mxArray *val) { DO_VOID_MUTABLE_METHOD (set_cell (idx, val)); } - double get_scalar (void) const { return m_rep->get_scalar (); } + double get_scalar () const { return m_rep->get_scalar (); } - void * get_data (void) const { DO_MUTABLE_METHOD (void *, get_data ()); } + void * get_data () const { DO_MUTABLE_METHOD (void *, get_data ()); } - mxDouble * get_doubles (void) const + mxDouble * get_doubles () const { DO_MUTABLE_METHOD (mxDouble *, get_doubles ()); } - mxSingle * get_singles (void) const + mxSingle * get_singles () const { DO_MUTABLE_METHOD (mxSingle *, get_singles ()); } - mxInt8 * get_int8s (void) const + mxInt8 * get_int8s () const { DO_MUTABLE_METHOD (mxInt8 *, get_int8s ()); } - mxInt16 * get_int16s (void) const + mxInt16 * get_int16s () const { DO_MUTABLE_METHOD (mxInt16 *, get_int16s ()); } - mxInt32 * get_int32s (void) const + mxInt32 * get_int32s () const { DO_MUTABLE_METHOD (mxInt32 *, get_int32s ()); } - mxInt64 * get_int64s (void) const + mxInt64 * get_int64s () const { DO_MUTABLE_METHOD (mxInt64 *, get_int64s ()); } - mxUint8 * get_uint8s (void) const + mxUint8 * get_uint8s () const { DO_MUTABLE_METHOD (mxUint8 *, get_uint8s ()); } - mxUint16 * get_uint16s (void) const + mxUint16 * get_uint16s () const { DO_MUTABLE_METHOD (mxUint16 *, get_uint16s ()); } - mxUint32 * get_uint32s (void) const + mxUint32 * get_uint32s () const { DO_MUTABLE_METHOD (mxUint32 *, get_uint32s ()); } - mxUint64 * get_uint64s (void) const + mxUint64 * get_uint64s () const { DO_MUTABLE_METHOD (mxUint64 *, get_uint64s ()); } - mxComplexDouble * get_complex_doubles (void) const + mxComplexDouble * get_complex_doubles () const { DO_MUTABLE_METHOD (mxComplexDouble *, get_complex_doubles ()); } - mxComplexSingle * get_complex_singles (void) const + mxComplexSingle * get_complex_singles () const { DO_MUTABLE_METHOD (mxComplexSingle *, get_complex_singles ()); } -#if 0 - /* We don't have these yet. */ - mxComplexInt8 * get_complex_int8s (void) const - { DO_MUTABLE_METHOD (mxComplexInt8 *, get_complex_int8s ()); } - - mxComplexInt16 * get_complex_int16s (void) const - { DO_MUTABLE_METHOD (mxComplexInt16 *, get_complex_int16s ()); } - - mxComplexInt32 * get_complex_int32s (void) const - { DO_MUTABLE_METHOD (mxComplexInt32 *, get_complex_int32s ()); } - - mxComplexInt64 * get_complex_int64s (void) const - { DO_MUTABLE_METHOD (mxComplexInt64 *, get_complex_int64s ()); } - - mxComplexUint8 * get_complex_uint8s (void) const - { DO_MUTABLE_METHOD (mxComplexUint8 *, get_complex_uint8s ()); } - - mxComplexUint16 * get_complex_uint16s (void) const - { DO_MUTABLE_METHOD (mxComplexUint16 *, get_complex_uint16s ()); } - - mxComplexUint32 * get_complex_uint32s (void) const - { DO_MUTABLE_METHOD (mxComplexUint32 *, get_complex_uint32s ()); } - - mxComplexUint64 * get_complex_uint64s (void) const - { DO_MUTABLE_METHOD (mxComplexUint64 *, get_complex_uint64s ()); } -#endif - - void * get_imag_data (void) const + void * get_imag_data () const { DO_MUTABLE_METHOD (void *, get_imag_data ()); } void set_data (void *pr) { DO_VOID_MUTABLE_METHOD (set_data (pr)); } @@ -600,40 +549,13 @@ int set_complex_singles (mxComplexSingle *data) { DO_MUTABLE_METHOD (int, set_complex_singles (data)); } -#if 0 - /* We don't have these yet. */ - int set_complex_int8s (mxComplexInt8 *data) - { DO_MUTABLE_METHOD (int, set_complex_int8s (data)); } - - int set_complex_int16s (mxComplexInt16 *data) - { DO_MUTABLE_METHOD (int, set_complex_int16s (data)); } - - int set_complex_int32s (mxComplexInt32 *data) - { DO_MUTABLE_METHOD (int, set_complex_int32s (data)); } - - int set_complex_int64s (mxComplexInt64 *data) - { DO_MUTABLE_METHOD (int, set_complex_int64s (data)); } - - int set_complex_uint8s (mxComplexUint8 *data) - { DO_MUTABLE_METHOD (int, set_complex_uint8s (data)); } - - int set_complex_uint16s (mxComplexUint16 *data) - { DO_MUTABLE_METHOD (int, set_complex_uint16s (data)); } - - int set_complex_uint32s (mxComplexUint32 *data) - { DO_MUTABLE_METHOD (int, set_complex_uint32s (data)); } - - int set_complex_uint64s (mxComplexUint64 *data) - { DO_MUTABLE_METHOD (int, set_complex_uint64s (data)); } -#endif - void set_imag_data (void *pi) { DO_VOID_MUTABLE_METHOD (set_imag_data (pi)); } - mwIndex * get_ir (void) const { DO_MUTABLE_METHOD (mwIndex *, get_ir ()); } + mwIndex * get_ir () const { DO_MUTABLE_METHOD (mwIndex *, get_ir ()); } - mwIndex * get_jc (void) const { DO_MUTABLE_METHOD (mwIndex *, get_jc ()); } + mwIndex * get_jc () const { DO_MUTABLE_METHOD (mwIndex *, get_jc ()); } - mwSize get_nzmax (void) const { return m_rep->get_nzmax (); } + mwSize get_nzmax () const { return m_rep->get_nzmax (); } void set_ir (mwIndex *ir) { DO_VOID_MUTABLE_METHOD (set_ir (ir)); } @@ -652,7 +574,7 @@ void set_field_by_number (mwIndex index, int key_num, mxArray *val) { DO_VOID_MUTABLE_METHOD (set_field_by_number (index, key_num, val)); } - int get_number_of_fields (void) const + int get_number_of_fields () const { return m_rep->get_number_of_fields (); } const char * get_field_name_by_number (int key_num) const @@ -664,17 +586,17 @@ int get_string (char *buf, mwSize buflen) const { return m_rep->get_string (buf, buflen); } - char * array_to_string (void) const { return m_rep->array_to_string (); } + char * array_to_string () const { return m_rep->array_to_string (); } mwIndex calc_single_subscript (mwSize nsubs, mwIndex *subs) const { return m_rep->calc_single_subscript (nsubs, subs); } - std::size_t get_element_size (void) const + std::size_t get_element_size () const { return m_rep->get_element_size (); } - bool mutation_needed (void) const { return m_rep->mutation_needed (); } + bool mutation_needed () const { return m_rep->mutation_needed (); } - mxArray * mutate (void) const { return m_rep->mutate (); } + mxArray * mutate () const { return m_rep->mutate (); } static OCTINTERP_API void * malloc (std::size_t n); @@ -702,7 +624,7 @@ static OCTINTERP_API octave_value as_octave_value (const mxArray *ptr, bool null_is_empty = true); - OCTINTERP_API octave_value as_octave_value (void) const; + OCTINTERP_API octave_value as_octave_value () const; private: @@ -740,7 +662,7 @@ create_rep (bool interleaved, mxClassID id, mwSize m, mwSize n, mwSize nzmax, mxComplexity flag); - OCTINTERP_API void maybe_mutate (void) const; + OCTINTERP_API void maybe_mutate () const; //-------- diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/oct-errno.h --- a/libinterp/corefcn/oct-errno.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/oct-errno.h Fri May 12 08:03:14 2023 +0200 @@ -39,22 +39,24 @@ { protected: - octave_errno (void); + octave_errno (); public: - ~octave_errno (void) = default; + OCTAVE_DISABLE_COPY_MOVE (octave_errno) + + ~octave_errno () = default; - static bool instance_ok (void); + static bool instance_ok (); - static void cleanup_instance (void) + static void cleanup_instance () { delete s_instance; s_instance = nullptr; } static int lookup (const std::string& name); - static octave_scalar_map list (void); + static octave_scalar_map list (); - static int get (void) { return errno; } + static int get () { return errno; } static int set (int val) { @@ -67,14 +69,13 @@ int do_lookup (const std::string& name); - octave_scalar_map do_list (void); + octave_scalar_map do_list (); //-------- std::map m_errno_tbl; static octave_errno *s_instance; - }; #endif diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/oct-errno.in.cc --- a/libinterp/corefcn/oct-errno.in.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/oct-errno.in.cc Fri May 12 08:03:14 2023 +0200 @@ -39,7 +39,7 @@ octave_errno *octave_errno::s_instance = nullptr; -octave_errno::octave_errno (void) +octave_errno::octave_errno () { struct errno_struct { @@ -293,7 +293,7 @@ } bool -octave_errno::instance_ok (void) +octave_errno::instance_ok () { bool retval = true; @@ -313,7 +313,7 @@ } octave_scalar_map -octave_errno::list (void) +octave_errno::list () { return (instance_ok ()) ? s_instance->do_list () : octave_scalar_map (); } @@ -326,7 +326,7 @@ } octave_scalar_map -octave_errno::do_list (void) +octave_errno::do_list () { octave_scalar_map retval; diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/oct-fstrm.cc --- a/libinterp/corefcn/oct-fstrm.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/oct-fstrm.cc Fri May 12 08:03:14 2023 +0200 @@ -67,7 +67,7 @@ // Return current stream position. off_t -fstream::tell (void) +fstream::tell () { // Note: error is inherited from base_stream, not ::error. // This error function does not halt execution so "return ..." must exist. @@ -78,19 +78,19 @@ // Return nonzero if EOF has been reached on this stream. bool -fstream::eof (void) const +fstream::eof () const { return m_fstream.eof (); } void -fstream::do_close (void) +fstream::do_close () { m_fstream.close (); } std::istream * -fstream::input_stream (void) +fstream::input_stream () { std::istream *retval = nullptr; @@ -101,7 +101,7 @@ } std::ostream * -fstream::output_stream (void) +fstream::output_stream () { std::ostream *retval = nullptr; diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/oct-fstrm.h --- a/libinterp/corefcn/oct-fstrm.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/oct-fstrm.h Fri May 12 08:03:14 2023 +0200 @@ -44,11 +44,7 @@ std::ios::openmode arg_md = std::ios::in | std::ios::out, mach_info::float_format flt_fmt = mach_info::native_float_format ()); - // No copying! - - fstream (const fstream&) = delete; - - fstream& operator = (const fstream&) = delete; + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (fstream) static stream create (const std::string& nm_arg, @@ -61,25 +57,25 @@ // Return current stream position. - off_t tell (void); + off_t tell (); // Return nonzero if EOF has been reached on this stream. - bool eof (void) const; + bool eof () const; - void do_close (void); + void do_close (); // The name of the file. - std::string name (void) const { return m_name; } + std::string name () const { return m_name; } - std::istream * input_stream (void); + std::istream * input_stream (); - std::ostream * output_stream (void); + std::ostream * output_stream (); protected: - ~fstream (void) = default; + ~fstream () = default; private: @@ -90,11 +86,4 @@ OCTAVE_END_NAMESPACE(octave) -#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS) - -OCTAVE_DEPRECATED (7, "use 'octave::fstream' instead") -typedef octave::fstream octave_fstream; - #endif - -#endif diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/oct-handle.h --- a/libinterp/corefcn/oct-handle.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/oct-handle.h Fri May 12 08:03:14 2023 +0200 @@ -39,7 +39,7 @@ class octave_handle { public: - octave_handle (void) : m_dval (octave::numeric_limits::NaN ()) { } + octave_handle () : m_dval (octave::numeric_limits::NaN ()) { } octave_handle (const octave_value& a) : m_dval (octave::numeric_limits::NaN ()) @@ -73,23 +73,23 @@ return *this; } - ~octave_handle (void) = default; + ~octave_handle () = default; - double value (void) const { return m_dval; } + double value () const { return m_dval; } - octave_value as_octave_value (void) const + octave_value as_octave_value () const { return ok () ? octave_value (m_dval) : octave_value (Matrix ()); } // Prefix increment/decrement operators. - octave_handle& operator ++ (void) + octave_handle& operator ++ () { ++m_dval; return *this; } - octave_handle& operator -- (void) + octave_handle& operator -- () { --m_dval; return *this; @@ -110,7 +110,7 @@ return old_value; } - bool ok (void) const { return ! octave::math::isnan (m_dval); } + bool ok () const { return ! octave::math::isnan (m_dval); } private: double m_dval; diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/oct-hdf5-types.h --- a/libinterp/corefcn/oct-hdf5-types.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/oct-hdf5-types.h Fri May 12 08:03:14 2023 +0200 @@ -38,16 +38,6 @@ OCTAVE_END_NAMESPACE(octave) -#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS) - -OCTAVE_DEPRECATED (7, "use 'octave::check_hdf5_types' instead") -inline bool check_hdf5_types (bool warn = true) -{ - return octave::check_hdf5_types (warn); -} - -#endif - #endif // Available for C and C++. diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/oct-hist.cc --- a/libinterp/corefcn/oct-hist.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/oct-hist.cc Fri May 12 08:03:14 2023 +0200 @@ -276,7 +276,7 @@ evmgr.set_history (command_history::list ()); } -void history_system::write_timestamp (void) +void history_system::write_timestamp () { sys::localtime now; @@ -524,7 +524,7 @@ source_file (name); } -std::string history_system::default_file (void) +std::string history_system::default_file () { std::string file; @@ -550,7 +550,7 @@ return file; } -int history_system::default_size (void) +int history_system::default_size () { int size = 1000; @@ -567,7 +567,7 @@ return size; } -std::string history_system::default_timestamp_format (void) +std::string history_system::default_timestamp_format () { return "# Octave " OCTAVE_VERSION ", %a %b %d %H:%M:%S %Y %Z <" diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/oct-hist.h --- a/libinterp/corefcn/oct-hist.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/oct-hist.h Fri May 12 08:03:14 2023 +0200 @@ -44,20 +44,18 @@ history_system (interpreter& interp); - history_system (const history_system&) = delete; + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (history_system) - history_system& operator = (const history_system&) = delete; - - ~history_system (void) = default; + ~history_system () = default; void initialize (bool read_history_file = false); - void write_timestamp (void); + void write_timestamp (); octave_value input_from_tmp_file (const octave_value_list& args, int nargout); - bool input_from_tmp_file (void) const + bool input_from_tmp_file () const { return m_input_from_tmp_file; } @@ -70,7 +68,7 @@ octave_value timestamp_format_string (const octave_value_list& args, int nargout); - std::string timestamp_format_string (void) const + std::string timestamp_format_string () const { return m_timestamp_format_string; } @@ -99,11 +97,11 @@ // Octave exits. std::string m_timestamp_format_string; - static std::string default_file (void); + static std::string default_file (); - static int default_size (void); + static int default_size (); - static std::string default_timestamp_format (void); + static std::string default_timestamp_format (); template T set (T& var, const T& new_val) diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/oct-iostrm.cc --- a/libinterp/corefcn/oct-iostrm.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/oct-iostrm.cc Fri May 12 08:03:14 2023 +0200 @@ -47,7 +47,7 @@ // Return current stream position. off_t -base_iostream::tell (void) +base_iostream::tell () { invalid_operation (); return -1; @@ -56,14 +56,14 @@ // Return nonzero if EOF has been reached on this stream. bool -base_iostream::eof (void) const +base_iostream::eof () const { invalid_operation (); return false; } void -base_iostream::invalid_operation (void) const +base_iostream::invalid_operation () const { // Note: use ::error to get error from error.h which halts operation. ::error ("%s: invalid operation", stream_type ()); @@ -72,7 +72,7 @@ // Return nonzero if EOF has been reached on this stream. bool -istream::eof (void) const +istream::eof () const { return m_istream && m_istream->eof (); } @@ -86,7 +86,7 @@ // Return nonzero if EOF has been reached on this stream. bool -ostream::eof (void) const +ostream::eof () const { return m_ostream && m_ostream->eof (); } diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/oct-iostrm.h --- a/libinterp/corefcn/oct-iostrm.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/oct-iostrm.h Fri May 12 08:03:14 2023 +0200 @@ -44,15 +44,11 @@ mach_info::float_format ff = mach_info::native_float_format ()) : base_stream (m, ff), m_name (n) { } - // No copying! - - base_iostream (const base_iostream&) = delete; - - base_iostream& operator = (const base_iostream&) = delete; + OCTAVE_DISABLE_COPY_MOVE (base_iostream) protected: - ~base_iostream (void) = default; + ~base_iostream () = default; public: @@ -62,25 +58,25 @@ // Return current stream position. - off_t tell (void); + off_t tell (); // Return nonzero if EOF has been reached on this stream. - bool eof (void) const; + bool eof () const; // The name of the file. - std::string name (void) const { return m_name; } + std::string name () const { return m_name; } protected: - void invalid_operation (void) const; + void invalid_operation () const; private: std::string m_name; - virtual const char * stream_type (void) const = 0; + virtual const char * stream_type () const = 0; }; class @@ -93,32 +89,28 @@ m_istream (arg) { } + OCTAVE_DISABLE_COPY_MOVE (istream) + static stream create (std::istream *arg = nullptr, const std::string& n = ""); // Return nonzero if EOF has been reached on this stream. - bool eof (void) const; + bool eof () const; - std::istream * input_stream (void) { return m_istream; } + std::istream * input_stream () { return m_istream; } - std::ostream * output_stream (void) { return nullptr; } + std::ostream * output_stream () { return nullptr; } protected: - ~istream (void) = default; + ~istream () = default; private: std::istream *m_istream; - const char * stream_type (void) const { return "istream"; } - - // No copying! - - istream (const istream&) = delete; - - istream& operator = (const istream&) = delete; + const char * stream_type () const { return "istream"; } }; class @@ -131,47 +123,30 @@ m_ostream (arg) { } + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (ostream) + static stream create (std::ostream *arg, const std::string& n = ""); // Return nonzero if EOF has been reached on this stream. - bool eof (void) const; + bool eof () const; - std::istream * input_stream (void) { return nullptr; } + std::istream * input_stream () { return nullptr; } - std::ostream * output_stream (void) { return m_ostream; } + std::ostream * output_stream () { return m_ostream; } protected: - ~ostream (void) = default; + ~ostream () = default; private: std::ostream *m_ostream; - const char * stream_type (void) const { return "ostream"; } - - // No copying! - - ostream (const ostream&) = delete; - - ostream& operator = (const ostream&) = delete; + const char * stream_type () const { return "ostream"; } }; OCTAVE_END_NAMESPACE(octave) -#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS) - -OCTAVE_DEPRECATED (7, "use 'octave::base_iostream' instead") -typedef octave::base_iostream octave_base_iostream; - -OCTAVE_DEPRECATED (7, "use 'octave::istream' instead") -typedef octave::istream octave_istream; - -OCTAVE_DEPRECATED (7, "use 'octave::ostream' instead") -typedef octave::ostream octave_ostream; - #endif - -#endif diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/oct-map.cc --- a/libinterp/corefcn/oct-map.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/oct-map.cc Fri May 12 08:03:14 2023 +0200 @@ -36,7 +36,7 @@ #include "utils.h" octave_fields::fields_rep * -octave_fields::nil_rep (void) +octave_fields::nil_rep () { static fields_rep nr; return &nr; @@ -155,7 +155,7 @@ } string_vector -octave_fields::fieldnames (void) const +octave_fields::fieldnames () const { octave_idx_type n = nfields (); string_vector retval(n); @@ -205,7 +205,7 @@ } octave_scalar_map -octave_scalar_map::orderfields (void) const +octave_scalar_map::orderfields () const { Array perm; return orderfields (perm); @@ -303,7 +303,7 @@ } octave_map -octave_map::orderfields (void) const +octave_map::orderfields () const { Array perm; return orderfields (perm); @@ -439,7 +439,7 @@ } octave_map -octave_map::squeeze (void) const +octave_map::squeeze () const { octave_map retval (*this); octave_idx_type nf = nfields (); @@ -496,7 +496,7 @@ */ octave_map -octave_map::transpose (void) const +octave_map::transpose () const { octave_map retval (m_keys); @@ -1344,7 +1344,7 @@ } void -octave_map::optimize_dimensions (void) +octave_map::optimize_dimensions () { octave_idx_type nf = nfields (); diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/oct-map.h --- a/libinterp/corefcn/oct-map.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/oct-map.h Fri May 12 08:03:14 2023 +0200 @@ -40,38 +40,41 @@ // A class holding a map field->index. Supports reference-counting. class OCTINTERP_API - octave_fields +octave_fields { class fields_rep : public std::map { public: - fields_rep (void) : std::map (), m_count (1) { } + + fields_rep () : std::map (), m_count (1) { } + fields_rep (const fields_rep& other) : std::map (other), m_count (1) { } - octave::refcount m_count; + fields_rep& operator = (const fields_rep&) = delete; - private: - fields_rep& operator = (const fields_rep&); // no assignment! + ~fields_rep () = default; + + octave::refcount m_count; }; fields_rep *m_rep; - static fields_rep * nil_rep (void); + static fields_rep * nil_rep (); public: - octave_fields (void) : m_rep (nil_rep ()) { m_rep->m_count++; } + octave_fields () : m_rep (nil_rep ()) { m_rep->m_count++; } octave_fields (const string_vector&); octave_fields (const char *const *); - ~octave_fields (void) + ~octave_fields () { if (--m_rep->m_count == 0) delete m_rep; } - void make_unique (void) + void make_unique () { if (m_rep->m_count > 1) { @@ -105,11 +108,11 @@ typedef std::map::const_iterator const_iterator; typedef const_iterator iterator; - const_iterator begin (void) const { return m_rep->begin (); } - const_iterator end (void) const { return m_rep->end (); } + const_iterator begin () const { return m_rep->begin (); } + const_iterator end () const { return m_rep->end (); } - const_iterator cbegin (void) const { return m_rep->cbegin (); } - const_iterator cend (void) const { return m_rep->cend (); } + const_iterator cbegin () const { return m_rep->cbegin (); } + const_iterator cend () const { return m_rep->cend (); } std::string key (const_iterator p) const { return p->first; } octave_idx_type index (const_iterator p) const { return p->second; } @@ -120,7 +123,7 @@ // high-level methods. // number of fields. - octave_idx_type nfields (void) const { return m_rep->size (); } + octave_idx_type nfields () const { return m_rep->size (); } // check whether a field exists. bool isfield (const std::string& name) const; @@ -149,39 +152,28 @@ { return m_rep == other.m_rep; } // Returns the fields as a vector of strings. - string_vector fieldnames (void) const; + string_vector fieldnames () const; - void clear (void) + void clear () { *this = octave_fields (); } }; class OCTINTERP_API - octave_scalar_map +octave_scalar_map { public: octave_scalar_map (const octave_fields& k) : m_keys (k), m_vals (k.nfields ()) { } - octave_scalar_map (void) : m_keys (), m_vals () { } - octave_scalar_map (const string_vector& k) : m_keys (k), m_vals (k.numel ()) { } - octave_scalar_map (const octave_scalar_map& m) - : m_keys (m.m_keys), m_vals (m.m_vals) { } - octave_scalar_map (const std::map& m); - octave_scalar_map& operator = (const octave_scalar_map& m) - { - m_keys = m.m_keys; - m_vals = m.m_vals; - - return *this; - } + OCTAVE_DEFAULT_CONSTRUCT_COPY_MOVE_DELETE (octave_scalar_map) // iteration support. // note that both const and non-const iterators are the same. @@ -189,11 +181,11 @@ typedef octave_fields::const_iterator const_iterator; typedef const_iterator iterator; - const_iterator begin (void) const { return m_keys.begin (); } - const_iterator end (void) const { return m_keys.end (); } + const_iterator begin () const { return m_keys.begin (); } + const_iterator end () const { return m_keys.end (); } - const_iterator cbegin (void) const { return m_keys.cbegin (); } - const_iterator cend (void) const { return m_keys.cend (); } + const_iterator cbegin () const { return m_keys.cbegin (); } + const_iterator cend () const { return m_keys.cend (); } const_iterator seek (const std::string& k) const { return m_keys.seek (k); } @@ -215,7 +207,7 @@ { return m_vals[i]; } // number of fields. - octave_idx_type nfields (void) const { return m_keys.nfields (); } + octave_idx_type nfields () const { return m_keys.nfields (); } // check whether a field exists. bool isfield (const std::string& name) const @@ -224,10 +216,10 @@ bool contains (const std::string& name) const { return isfield (name); } - string_vector fieldnames (void) const + string_vector fieldnames () const { return m_keys.fieldnames (); } - string_vector keys (void) const + string_vector keys () const { return fieldnames (); } // get contents of a given field. empty value if not exist. @@ -243,7 +235,7 @@ void del (const std::string& k) { rmfield (k); } // return a copy with fields ordered, optionally along with permutation. - octave_scalar_map orderfields (void) const; + octave_scalar_map orderfields () const; octave_scalar_map orderfields (Array& perm) const; octave_scalar_map orderfields (const octave_scalar_map& other, Array& perm) const; @@ -252,7 +244,7 @@ octave_value contents (const std::string& k) const; octave_value& contents (const std::string& k); - void clear (void) + void clear () { m_keys.clear (); m_vals.clear (); @@ -264,7 +256,6 @@ octave_fields m_keys; std::vector m_vals; - }; template <> @@ -273,7 +264,7 @@ { return v.scalar_map_value (); } class OCTINTERP_API - octave_map +octave_map { public: @@ -285,8 +276,6 @@ typedef octave_scalar_map element_type; - octave_map (void) : m_keys (), m_vals (), m_dimensions () { } - octave_map (const dim_vector& dv) : m_keys (), m_vals (), m_dimensions (dv) { } octave_map (const string_vector& k) @@ -295,19 +284,9 @@ octave_map (const dim_vector& dv, const string_vector& k) : m_keys (k), m_vals (k.numel (), Cell (dv)), m_dimensions (dv) { } - octave_map (const octave_map& m) - : m_keys (m.m_keys), m_vals (m.m_vals), m_dimensions (m.m_dimensions) { } - octave_map (const octave_scalar_map& m); - octave_map& operator = (const octave_map& m) - { - m_keys = m.m_keys; - m_vals = m.m_vals; - m_dimensions = m.m_dimensions; - - return *this; - } + OCTAVE_DEFAULT_CONSTRUCT_COPY_MOVE_DELETE (octave_map) // iteration support. // note that both const and non-const iterators are the same. @@ -315,11 +294,11 @@ typedef octave_fields::const_iterator const_iterator; typedef const_iterator iterator; - const_iterator begin (void) const { return m_keys.begin (); } - const_iterator end (void) const { return m_keys.end (); } + const_iterator begin () const { return m_keys.begin (); } + const_iterator end () const { return m_keys.end (); } - const_iterator cbegin (void) const { return m_keys.cbegin (); } - const_iterator cend (void) const { return m_keys.cend (); } + const_iterator cbegin () const { return m_keys.cbegin (); } + const_iterator cend () const { return m_keys.cend (); } const_iterator seek (const std::string& k) const { return m_keys.seek (k); } @@ -341,7 +320,7 @@ { return m_vals[i]; } // number of fields. - octave_idx_type nfields (void) const { return m_keys.nfields (); } + octave_idx_type nfields () const { return m_keys.nfields (); } // check whether a field exists. bool isfield (const std::string& name) const @@ -350,10 +329,10 @@ bool contains (const std::string& name) const { return isfield (name); } - string_vector fieldnames (void) const + string_vector fieldnames () const { return m_keys.fieldnames (); } - string_vector keys (void) const + string_vector keys () const { return fieldnames (); } // get contents of a given field. empty value if not exist. @@ -370,7 +349,7 @@ void del (const std::string& k) { rmfield (k); } // return a copy with fields ordered, optionally along with permutation. - octave_map orderfields (void) const; + octave_map orderfields () const; octave_map orderfields (Array& perm) const; octave_map orderfields (const octave_map& other, Array& perm) const; @@ -379,20 +358,20 @@ Cell contents (const std::string& k) const; Cell& contents (const std::string& k); - void clear (void) + void clear () { m_keys.clear (); m_vals.clear (); } // The Array-like methods. - octave_idx_type numel (void) const { return m_dimensions.numel (); } - octave_idx_type length (void) const { return numel (); } - bool isempty (void) const { return m_dimensions.any_zero (); } + octave_idx_type numel () const { return m_dimensions.numel (); } + octave_idx_type length () const { return numel (); } + bool isempty () const { return m_dimensions.any_zero (); } - octave_idx_type rows (void) const { return m_dimensions(0); } - octave_idx_type cols (void) const { return m_dimensions(1); } - octave_idx_type columns (void) const { return m_dimensions(1); } + octave_idx_type rows () const { return m_dimensions(0); } + octave_idx_type cols () const { return m_dimensions(1); } + octave_idx_type columns () const { return m_dimensions(1); } // Extract a scalar substructure. // FIXME: actually check something. @@ -423,15 +402,15 @@ operator () (const Array& ra_idx) const { return elem (ra_idx); } - octave_map squeeze (void) const; + octave_map squeeze () const; octave_map permute (const Array& vec, bool inv = false) const; - dim_vector dims (void) const { return m_dimensions; } + dim_vector dims () const { return m_dimensions; } - int ndims (void) const { return m_dimensions.ndims (); } + int ndims () const { return m_dimensions.ndims (); } - octave_map transpose (void) const; + octave_map transpose () const; octave_map reshape (const dim_vector& dv) const; @@ -491,7 +470,7 @@ std::vector m_vals; dim_vector m_dimensions; - void optimize_dimensions (void); + void optimize_dimensions (); void extract_scalar (octave_scalar_map& dest, octave_idx_type index) const; static void do_cat (int dim, octave_idx_type n, diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/oct-opengl.h --- a/libinterp/corefcn/oct-opengl.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/oct-opengl.h Fri May 12 08:03:14 2023 +0200 @@ -56,13 +56,13 @@ { public: - opengl_functions (void) { } + opengl_functions () { } opengl_functions (const opengl_functions&) = default; opengl_functions& operator = (const opengl_functions&) = default; - virtual ~opengl_functions (void) = default; + virtual ~opengl_functions () = default; #if defined (HAVE_OPENGL) @@ -186,17 +186,17 @@ ::glEnable (cap); } - virtual void glEndList (void) + virtual void glEndList () { ::glEndList (); } - virtual void glEnd (void) + virtual void glEnd () { ::glEnd (); } - virtual void glFinish (void) + virtual void glFinish () { ::glFinish (); } @@ -221,7 +221,7 @@ ::glGetDoublev (pname, data); } - virtual GLenum glGetError (void) + virtual GLenum glGetError () { return ::glGetError (); } @@ -246,7 +246,7 @@ ::glHint (target, mode); } - virtual void glInitNames (void) + virtual void glInitNames () { ::glInitNames (); } @@ -271,7 +271,7 @@ ::glLineWidth (width); } - virtual void glLoadIdentity (void) + virtual void glLoadIdentity () { ::glLoadIdentity (); } @@ -337,17 +337,17 @@ ::glPolygonOffset (factor, units); } - virtual void glPopAttrib (void) + virtual void glPopAttrib () { ::glPopAttrib (); } - virtual void glPopMatrix (void) + virtual void glPopMatrix () { ::glPopMatrix (); } - virtual void glPopName (void) + virtual void glPopName () { ::glPopName (); } @@ -357,7 +357,7 @@ ::glPushAttrib (mask); } - virtual void glPushMatrix (void) + virtual void glPushMatrix () { ::glPushMatrix (); } diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/oct-prcstrm.cc --- a/libinterp/corefcn/oct-prcstrm.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/oct-prcstrm.cc Fri May 12 08:03:14 2023 +0200 @@ -50,7 +50,7 @@ arg_md, ff, encoding, octave::pclose) { } -octave_iprocstream::~octave_iprocstream (void) +octave_iprocstream::~octave_iprocstream () { do_close (); } @@ -71,7 +71,7 @@ arg_md, ff, encoding, octave::pclose) { } -octave_oprocstream::~octave_oprocstream (void) +octave_oprocstream::~octave_oprocstream () { do_close (); } diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/oct-prcstrm.h --- a/libinterp/corefcn/oct-prcstrm.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/oct-prcstrm.h Fri May 12 08:03:14 2023 +0200 @@ -51,11 +51,7 @@ = octave::mach_info::native_float_format (), const std::string& encoding = "utf-8"); - // No copying! - - octave_iprocstream (const octave_iprocstream&) = delete; - - octave_iprocstream& operator = (const octave_iprocstream&) = delete; + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (octave_iprocstream) static octave::stream create (const std::string& n, std::ios::openmode arg_md = std::ios::in, @@ -65,7 +61,7 @@ protected: - ~octave_iprocstream (void); + ~octave_iprocstream (); }; class @@ -79,11 +75,7 @@ = octave::mach_info::native_float_format (), const std::string& encoding = "utf-8"); - // No copying! - - octave_oprocstream (const octave_oprocstream&) = delete; - - octave_oprocstream& operator = (const octave_oprocstream&) = delete; + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (octave_oprocstream) static octave::stream create (const std::string& n, std::ios::openmode arg_md = std::ios::out, @@ -93,19 +85,9 @@ protected: - ~octave_oprocstream (void); + ~octave_oprocstream (); }; OCTAVE_END_NAMESPACE(octave) -#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS) - -OCTAVE_DEPRECATED (7, "use 'octave::octave_iprocstream' instead") -typedef octave::octave_iprocstream octave_iprocstream; - -OCTAVE_DEPRECATED (7, "use 'octave::octave_oprocstream' instead") -typedef octave::octave_oprocstream octave_oprocstream; - #endif - -#endif diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/oct-procbuf.cc --- a/libinterp/corefcn/oct-procbuf.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/oct-procbuf.cc Fri May 12 08:03:14 2023 +0200 @@ -182,7 +182,7 @@ } procbuf * -procbuf::close (void) +procbuf::close () { #if defined (__CYGWIN__) || defined (__MINGW32__) || defined (_MSC_VER) diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/oct-procbuf.h --- a/libinterp/corefcn/oct-procbuf.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/oct-procbuf.h Fri May 12 08:03:14 2023 +0200 @@ -42,7 +42,7 @@ { public: - procbuf (void) + procbuf () : c_file_ptr_buf (nullptr), m_wstatus (-1), m_open_p (false), m_proc_pid (-1), m_next (nullptr) { } @@ -52,23 +52,19 @@ m_proc_pid (-1), m_next (nullptr) { open (command, mode); } - // No copying! - - procbuf (const procbuf&) = delete; + OCTAVE_DISABLE_COPY_MOVE (procbuf) - procbuf& operator = (const procbuf&) = delete; - - ~procbuf (void) { close (); } + ~procbuf () { close (); } procbuf * open (const char *command, int mode); - procbuf * close (void); + procbuf * close (); - int wait_status (void) const { return m_wstatus; } + int wait_status () const { return m_wstatus; } - bool is_open (void) const { return m_open_p; } + bool is_open () const { return m_open_p; } - pid_t pid (void) const { return m_proc_pid; } + pid_t pid () const { return m_proc_pid; } protected: @@ -83,11 +79,4 @@ OCTAVE_END_NAMESPACE(octave) -#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS) - -OCTAVE_DEPRECATED (7, "use octave::procbuf' instead") -typedef octave::procbuf procbuf; - #endif - -#endif diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/oct-process.h --- a/libinterp/corefcn/oct-process.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/oct-process.h Fri May 12 08:03:14 2023 +0200 @@ -37,7 +37,7 @@ { public: - process_execution_result (void) + process_execution_result () : m_status (-1), m_err_msg (), m_exit_status (-1), m_stdout_output () { } @@ -48,19 +48,21 @@ m_stdout_output (stdout_output) { } + OCTAVE_DEFAULT_COPY_MOVE_DELETE (process_execution_result) + static OCTINTERP_API process_execution_result of_success (int exit_status, const std::string& stdout_output); static OCTINTERP_API process_execution_result of_error (int status, const std::string& err_msg); - int status (void) const { return m_status; } + int status () const { return m_status; } - int exit_status (void) const { return m_exit_status; } + int exit_status () const { return m_exit_status; } - std::string err_msg (void) const { return m_err_msg; } + std::string err_msg () const { return m_err_msg; } - std::string stdout_output (void) const { return m_stdout_output; } + std::string stdout_output () const { return m_stdout_output; } private: diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/oct-stdstrm.h --- a/libinterp/corefcn/oct-stdstrm.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/oct-stdstrm.h Fri May 12 08:03:14 2023 +0200 @@ -50,11 +50,7 @@ m_stream (f ? new STREAM_T (f, cf) : nullptr), m_fnum (fid) { } - // No copying! - - tstdiostream (const tstdiostream&) = delete; - - tstdiostream& operator = (const tstdiostream&) = delete; + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (tstdiostream) // Position a stream at OFFSET relative to ORIGIN. @@ -65,43 +61,43 @@ // Return current stream position. - off_t tell (void) { return m_stream ? m_stream->tell () : -1; } + off_t tell () { return m_stream ? m_stream->tell () : -1; } // Return nonzero if EOF has been reached on this stream. - bool eof (void) const { return m_stream ? m_stream->eof () : true; } + bool eof () const { return m_stream ? m_stream->eof () : true; } // The name of the file. - std::string name (void) const { return m_name; } + std::string name () const { return m_name; } - std::istream * input_stream (void) + std::istream * input_stream () { return (m_mode & std::ios::in) ? m_stream : nullptr; } - std::ostream * output_stream (void) + std::ostream * output_stream () { return (m_mode & std::ios::out) ? m_stream : nullptr; } // FIXME: should not have to cast away const here. - BUF_T * rdbuf (void) const + BUF_T * rdbuf () const { return m_stream ? (const_cast (m_stream))->rdbuf () : nullptr; } - int file_number (void) const { return m_fnum; } + int file_number () const { return m_fnum; } - bool bad (void) const { return m_stream ? m_stream->bad () : true; } + bool bad () const { return m_stream ? m_stream->bad () : true; } - void clear (void) + void clear () { if (m_stream) m_stream->clear (); } - void do_close (void) + void do_close () { if (m_stream) m_stream->stream_close (); @@ -109,7 +105,7 @@ protected: - ~tstdiostream (void) { delete m_stream; } + ~tstdiostream () { delete m_stream; } //-------- @@ -147,15 +143,11 @@ return stream (new stdiostream (n, f, m, ff, encoding, cf)); } - // No copying! - - stdiostream (const stdiostream&) = delete; - - stdiostream& operator = (const stdiostream&) = delete; + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (stdiostream) protected: - ~stdiostream (void) = default; + ~stdiostream () = default; }; #if defined (HAVE_ZLIB) @@ -184,29 +176,15 @@ return stream (new zstdiostream (n, f, fid, m, ff, encoding, cf)); } - // No copying! - - zstdiostream (const zstdiostream&) = delete; - - zstdiostream& operator = (const zstdiostream&) = delete; + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (zstdiostream) protected: - ~zstdiostream (void) = default; + ~zstdiostream () = default; }; #endif OCTAVE_END_NAMESPACE(octave) -#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS) - -OCTAVE_DEPRECATED (7, "use 'octave::stdiostream' instead") -typedef octave::stdiostream octave_stdiostream; - -OCTAVE_DEPRECATED (7, "use 'octave::zstdiostream' instead") -typedef octave::zstdiostream octave_zstdiostream; - #endif - -#endif diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/oct-stream.cc --- a/libinterp/corefcn/oct-stream.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/oct-stream.cc Fri May 12 08:03:14 2023 +0200 @@ -39,6 +39,7 @@ #include #include #include +#include #include "Array.h" #include "Cell.h" @@ -262,7 +263,7 @@ scanf_format_elt& operator = (const scanf_format_elt&) = default; - ~scanf_format_elt (void) = default; + ~scanf_format_elt () = default; // The C-style format string. std::string text; @@ -291,30 +292,26 @@ scanf_format_list (const std::string& fmt = ""); - // No copying! - - scanf_format_list (const scanf_format_list&) = delete; - - scanf_format_list& operator = (const scanf_format_list&) = delete; - - ~scanf_format_list (void); - - octave_idx_type num_conversions (void) { return m_nconv; } + OCTAVE_DISABLE_COPY_MOVE (scanf_format_list) + + ~scanf_format_list (); + + octave_idx_type num_conversions () { return m_nconv; } // The length can be different than the number of conversions. // For example, "x %d y %d z" has 2 conversions but the length of // the list is 3 because of the characters that appear after the // last conversion. - std::size_t length (void) const { return m_fmt_elts.size (); } - - const scanf_format_elt * first (void) + std::size_t length () const { return m_fmt_elts.size (); } + + const scanf_format_elt * first () { m_curr_idx = 0; return current (); } - const scanf_format_elt * current (void) const + const scanf_format_elt * current () const { return length () > 0 ? m_fmt_elts[m_curr_idx] : nullptr; } @@ -337,15 +334,15 @@ return current (); } - void printme (void) const; - - bool ok (void) const { return (m_nconv >= 0); } + void printme () const; + + bool ok () const { return (m_nconv >= 0); } operator bool () const { return ok (); } - bool all_character_conversions (void); - - bool all_numeric_conversions (void); + bool all_character_conversions (); + + bool all_numeric_conversions (); private: @@ -449,7 +446,7 @@ m_buf.str (""); } -scanf_format_list::~scanf_format_list (void) +scanf_format_list::~scanf_format_list () { std::size_t n = m_fmt_elts.size (); @@ -665,7 +662,7 @@ } void -scanf_format_list::printme (void) const +scanf_format_list::printme () const { std::size_t n = m_fmt_elts.size (); @@ -693,7 +690,7 @@ } bool -scanf_format_list::all_character_conversions (void) +scanf_format_list::all_character_conversions () { std::size_t n = m_fmt_elts.size (); @@ -723,7 +720,7 @@ } bool -scanf_format_list::all_numeric_conversions (void) +scanf_format_list::all_numeric_conversions () { std::size_t n = m_fmt_elts.size (); @@ -767,7 +764,7 @@ printf_format_elt& operator = (const printf_format_elt&) = default; - ~printf_format_elt (void) = default; + ~printf_format_elt () = default; // The C-style format string. std::string text; @@ -799,28 +796,24 @@ printf_format_list (const std::string& fmt = ""); - // No copying! - - printf_format_list (const printf_format_list&) = delete; - - printf_format_list& operator = (const printf_format_list&) = delete; - - ~printf_format_list (void); - - octave_idx_type num_conversions (void) { return m_nconv; } - - const printf_format_elt * first (void) + OCTAVE_DISABLE_COPY_MOVE (printf_format_list) + + ~printf_format_list (); + + octave_idx_type num_conversions () { return m_nconv; } + + const printf_format_elt * first () { m_curr_idx = 0; return current (); } - const printf_format_elt * current (void) const + const printf_format_elt * current () const { return length () > 0 ? m_fmt_elts[m_curr_idx] : nullptr; } - std::size_t length (void) const { return m_fmt_elts.size (); } + std::size_t length () const { return m_fmt_elts.size (); } const printf_format_elt * next (bool cycle = true) { @@ -837,11 +830,11 @@ return current (); } - bool last_elt_p (void) { return (m_curr_idx + 1 == length ()); } - - void printme (void) const; - - bool ok (void) const { return (m_nconv >= 0); } + bool last_elt_p () { return (m_curr_idx + 1 == length ()); } + + void printme () const; + + bool ok () const { return (m_nconv >= 0); } operator bool () const { return ok (); } @@ -958,7 +951,7 @@ } } -printf_format_list::~printf_format_list (void) +printf_format_list::~printf_format_list () { std::size_t n = m_fmt_elts.size (); @@ -1160,7 +1153,7 @@ } void -printf_format_list::printme (void) const +printf_format_list::printme () const { std::size_t n = m_fmt_elts.size (); @@ -1198,7 +1191,7 @@ } static Cell -init_inf_nan (void) +init_inf_nan () { Cell retval (dim_vector (1, 2)); @@ -1231,17 +1224,13 @@ delimited_stream (std::istream& is, const delimited_stream& ds); - // No copying! - - delimited_stream (const delimited_stream&) = delete; - - delimited_stream& operator = (const delimited_stream&) = delete; - - ~delimited_stream (void); + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (delimited_stream) + + ~delimited_stream (); // Called when optimized sequence of get is finished. Ensures that // there is a remaining delimiter in buf, or loads more data in. - void field_done (void) + void field_done () { if (m_idx >= m_last) refresh_buf (); @@ -1253,7 +1242,7 @@ // Get a character, relying on caller to call field_done if // a delimiter has been reached. - int get (void) + int get () { if (m_delimited) return eof () ? std::istream::traits_type::eof () : *m_idx++; @@ -1262,17 +1251,17 @@ } // Get a character, checking for underrun of the buffer. - int get_undelim (void); + int get_undelim (); // Read character that will be got by the next get. // FIXME: This will not set EOF if delimited stream is at EOF and a peek // is attempted. This does *NOT* behave like C++ input stream. // For a compatible peek function, use peek_undelim. See bug #56917. - int peek (void) + int peek () { return eof () ? std::istream::traits_type::eof () : *m_idx; } // Read character that will be got by the next get. - int peek_undelim (void); + int peek_undelim (); // Undo a 'get' or 'get_undelim'. It is the caller's responsibility // to avoid overflow by calling putbacks only for a character got by @@ -1288,22 +1277,22 @@ // Return a position suitable to "seekg", valid only within this // block between calls to field_done. - char * tellg (void) { return m_idx; } + char * tellg () { return m_idx; } void seekg (char *old_idx) { m_idx = old_idx; } - bool eof (void) + bool eof () { return (m_eob == m_buf + m_overlap && m_i_stream.eof ()) || (m_flags & std::ios_base::eofbit); } - operator const void *(void) + operator const void *() { return (! eof () && ! m_flags) ? this : nullptr; } - bool fail (void) { return m_flags & std::ios_base::failbit; } - - std::ios_base::iostate rdstate (void) { return m_flags; } + bool fail () { return m_flags & std::ios_base::failbit; } + + std::ios_base::iostate rdstate () { return m_flags; } void setstate (std::ios_base::iostate m) { m_flags = m_flags | m; } @@ -1316,14 +1305,14 @@ // Report if any characters have been consumed. // (get, read, etc. not cancelled by putback or seekg) - void progress_benchmark (void) { m_progress_marker = m_idx; } - - bool no_progress (void) { return m_progress_marker == m_idx; } + void progress_benchmark () { m_progress_marker = m_idx; } + + bool no_progress () { return m_progress_marker == m_idx; } // Number of characters remaining until end of stream if it is already // buffered. int_max otherwise. - std::ptrdiff_t remaining (void) + std::ptrdiff_t remaining () { if (m_eob < m_buf + m_bufsize) return m_eob - m_idx; @@ -1398,7 +1387,7 @@ : delimited_stream (is, ds.m_delims, ds.m_longest, ds.m_bufsize) { } -delimited_stream::~delimited_stream (void) +delimited_stream::~delimited_stream () { // Seek to the correct position in i_stream. if (! eof ()) @@ -1415,7 +1404,7 @@ // if necessary. int -delimited_stream::get_undelim (void) +delimited_stream::get_undelim () { int retval; if (eof ()) @@ -1449,7 +1438,7 @@ // pointer, refilling the buffer from the file if necessary. int -delimited_stream::peek_undelim (void) +delimited_stream::peek_undelim () { int retval = get_undelim (); putback (); @@ -1659,6 +1648,8 @@ literal_conversion = 2 }; + textscan_format_elt () = delete; + textscan_format_elt (const std::string& txt, int w = 0, int p = -1, int bw = 0, bool dis = false, char typ = '\0', const std::string& ch_class = std::string ()) @@ -1667,28 +1658,7 @@ numeric (typ == 'd' || typ == 'u' || type == 'f' || type == 'n') { } - textscan_format_elt (const textscan_format_elt& e) - : text (e.text), width (e.width), prec (e.prec), - bitwidth (e.bitwidth), char_class (e.char_class), type (e.type), - discard (e.discard), numeric (e.numeric) - { } - - textscan_format_elt& operator = (const textscan_format_elt& e) - { - if (this != &e) - { - text = e.text; - width = e.width; - prec = e.prec; - bitwidth = e.bitwidth; - discard = e.discard; - type = e.type; - numeric = e.numeric; - char_class = e.char_class; - } - - return *this; - } + OCTAVE_DEFAULT_COPY_MOVE_DELETE (textscan_format_elt) // The C-style format string. std::string text; @@ -1729,30 +1699,26 @@ textscan_format_list (const std::string& fmt = std::string (), const std::string& who = "textscan"); - // No copying! - - textscan_format_list (const textscan_format_list&) = delete; - - textscan_format_list& operator = (const textscan_format_list&) = delete; - - ~textscan_format_list (void); - - octave_idx_type num_conversions (void) const { return m_nconv; } + OCTAVE_DISABLE_COPY_MOVE (textscan_format_list) + + ~textscan_format_list (); + + octave_idx_type num_conversions () const { return m_nconv; } // The length can be different than the number of conversions. // For example, "x %d y %d z" has 2 conversions but the length of // the list is 3 because of the characters that appear after the // last conversion. - std::size_t numel (void) const { return m_fmt_elts.size (); } - - const textscan_format_elt * first (void) + std::size_t numel () const { return m_fmt_elts.size (); } + + const textscan_format_elt * first () { m_curr_idx = 0; return current (); } - const textscan_format_elt * current (void) const + const textscan_format_elt * current () const { return numel () > 0 ? m_fmt_elts[m_curr_idx] : nullptr; } @@ -1772,11 +1738,11 @@ return current (); } - void printme (void) const; - - bool ok (void) const { return (m_nconv >= 0); } - - operator const void *(void) const { return ok () ? this : nullptr; } + void printme () const; + + bool ok () const { return (m_nconv >= 0); } + + operator const void *() const { return ok () ? this : nullptr; } // What function name should be shown when reporting errors. std::string who; @@ -1789,7 +1755,7 @@ int read_first_row (delimited_stream& is, textscan& ts); - std::list out_buf (void) const + std::list out_buf () const { return (m_output_container); } private: @@ -1846,13 +1812,9 @@ textscan (const std::string& who_arg = "textscan", const std::string& encoding = "utf-8"); - // No copying! - - textscan (const textscan&) = delete; - - textscan& operator = (const textscan&) = delete; - - ~textscan (void) = default; + OCTAVE_DISABLE_COPY_MOVE (textscan) + + ~textscan () = default; octave_value scan (std::istream& isp, const std::string& fmt, octave_idx_type ntimes, @@ -1922,7 +1884,7 @@ { return m_whitespace_table[ch & 0xff]; } // True if the only delimiter is whitespace. - bool whitespace_delim (void) const { return m_delim_table.empty (); } + bool whitespace_delim () const { return m_delim_table.empty (); } //-------- @@ -1982,7 +1944,7 @@ short m_return_on_error; bool m_collect_output; - bool multiple_delims_as_one; + bool m_multiple_delims_as_one; bool m_default_exp; octave_idx_type m_lines; @@ -2088,7 +2050,7 @@ m_buf.str (""); } -textscan_format_list::~textscan_format_list (void) +textscan_format_list::~textscan_format_list () { std::size_t n = numel (); @@ -2474,7 +2436,7 @@ } void -textscan_format_list::printme (void) const +textscan_format_list::printme () const { std::size_t n = numel (); @@ -2590,7 +2552,7 @@ m_exp_chars ("edED"), m_header_lines (0), m_treat_as_empty (), m_treat_as_empty_len (0), m_whitespace (" \b\t"), m_eol1 ('\r'), m_eol2 ('\n'), m_return_on_error (1), m_collect_output (false), - multiple_delims_as_one (false), m_default_exp (true), m_lines (0) + m_multiple_delims_as_one (false), m_default_exp (true), m_lines (0) { } octave_value @@ -2664,7 +2626,7 @@ int err = 0; octave_idx_type row = 0; - if (multiple_delims_as_one) // bug #44750? + if (m_multiple_delims_as_one) // bug #44750? skip_delim (is); int done_after; // Number of columns read when EOF seen. @@ -2690,7 +2652,7 @@ // after reading in data. // If the format was "", that conversion may already have happened, // so force all to be merged (as all are %f). - bool merge_with_prev[fmt_list.numel ()]; + std::vector merge_with_prev (fmt_list.numel ()); int conv = 0; if (m_collect_output) { @@ -3748,7 +3710,7 @@ } else if (param == "multipledelimsasone") { - multiple_delims_as_one = args(i + m_multiple_delims_as_one = args(i +1).xbool_value ("%s: MultipleDelimsAsOne must be logical or numeric", m_who.c_str ()); } else if (param == "returnonerror") @@ -3983,7 +3945,7 @@ if (c1 == m_eol1 && is.peek_undelim () == m_eol2) is.get (); // if \r\n, skip the \n too. - if (multiple_delims_as_one) + if (m_multiple_delims_as_one) { int prev = -1; // skip multiple delims. @@ -4021,7 +3983,7 @@ is.get_undelim (); } - if (multiple_delims_as_one) + if (m_multiple_delims_as_one) { int prev = -1; // skip multiple delims. @@ -4084,14 +4046,14 @@ } void -base_stream::clear (void) +base_stream::clear () { m_fail = false; m_errmsg = ""; } void -base_stream::clearerr (void) +base_stream::clearerr () { std::istream *is = input_stream (); std::ostream *os = preferred_output_stream (); @@ -4288,6 +4250,9 @@ { T value = T (); + is >> std::ws; // skip through whitespace and advance stream pointer + std::streampos pos = is.tellg (); + switch (fmt.type) { case 'o': @@ -4301,11 +4266,7 @@ case 'i': { - int c1 = std::istream::traits_type::eof (); - - while (is && (c1 = is.get ()) != std::istream::traits_type::eof () - && isspace (c1)) - ; // skip whitespace + int c1 = is.get (); if (c1 != std::istream::traits_type::eof ()) { @@ -4354,18 +4315,33 @@ break; } - // If conversion produces an integer that overflows, failbit is set but - // value is non-zero. We want to treat this case as success, so clear - // failbit from the stream state to keep going. - // FIXME: Maybe set error state on octave stream as above? Matlab does - // *not* indicate an error message on overflow. - if ((is.rdstate () & std::ios::failbit) && value != T ()) - is.clear (is.rdstate () & ~std::ios::failbit); - - // Only copy the converted value if the stream is in a state where we - // want to continue reading. - if (! (is.rdstate () & std::ios::failbit)) - *valptr = value; + std::ios::iostate status = is.rdstate (); + if (! (status & std::ios::failbit)) + { + // Copy the converted value if the stream is in a good state + *valptr = value; + } + else + { + if (value != T ()) + { + // If conversion produces an integer that overflows, failbit is set + // but value is nonzero. We want to treat this case as success, + // so clear failbit from the stream state to keep going. + // FIXME: Maybe set error state on octave stream? Matlab does + // *not* indicate an error message on overflow. + is.clear (status & ~std::ios::failbit); + *valptr = value; + } + else + { + // True error. + // Reset stream to original position, clear eof bit, pass status on. + is.clear (); + is.seekg (pos); + is.setstate (status & ~std::ios_base::eofbit); + } + } return is; } @@ -4433,17 +4409,20 @@ case 'E': case 'G': { - int c1 = std::istream::traits_type::eof (); - - while (is && (c1 = is.get ()) != std::istream::traits_type::eof () - && isspace (c1)) - ; // skip whitespace - - if (c1 != std::istream::traits_type::eof ()) + is >> std::ws; // skip through whitespace and advance stream pointer + if (is.good ()) { - is.putback (c1); + std::streampos pos = is.tellg (); ref = read_value (is); + + std::ios::iostate status = is.rdstate (); + if (status & std::ios::failbit) + { + is.clear (); + is.seekg (pos); + is.setstate (status & ~std::ios_base::eofbit); + } } } break; @@ -4497,11 +4476,16 @@ { \ int c = std::istream::traits_type::eof (); \ \ + /* get all whitespace characters */ \ while (is && (c = is.get ()) != std::istream::traits_type::eof () \ && isspace (c)) \ { /* skip whitespace */ } \ \ - if (c != std::istream::traits_type::eof ()) \ + if (c == std::istream::traits_type::eof ()) \ + /* reset failbit at eof */ \ + is.clear (is.rdstate () & (~std::ios::failbit)); \ + else \ + /* put back non-whitespace character */ \ is.putback (c); \ } \ while (0) @@ -4566,8 +4550,8 @@ && (c = is.get ()) != std::istream::traits_type::eof ()) \ tmp[n++] = static_cast (c); \ \ - if (n > 0 && c == std::istream::traits_type::eof ()) \ - is.clear (); \ + if (c == std::istream::traits_type::eof ()) \ + is.clear (is.rdstate () & (~std::ios::failbit)); \ \ tmp.resize (n) @@ -4609,8 +4593,8 @@ tmp[n++] = static_cast (c); \ } \ \ - if (n > 0 && c == std::istream::traits_type::eof ()) \ - is.clear (); \ + if (c == std::istream::traits_type::eof ()) \ + is.clear (is.rdstate () & (~std::ios::failbit)); \ \ tmp.resize (n); \ } \ @@ -4623,15 +4607,13 @@ // This format must match a nonempty sequence of characters. #define BEGIN_CHAR_CLASS_CONVERSION() \ - int width = elt->width; \ + int width = (elt->width ? elt->width \ + : std::numeric_limits::max ()); \ \ std::string tmp; \ \ do \ { \ - if (! width) \ - width = std::numeric_limits::max (); \ - \ std::ostringstream buf; \ \ std::string char_class = elt->char_class; \ @@ -4642,29 +4624,39 @@ { \ int chars_read = 0; \ while (is && chars_read++ < width \ - && (c = is.get ()) != std::istream::traits_type::eof () \ - && char_class.find (c) != std::string::npos) \ - buf << static_cast (c); \ + && (c = is.get ()) != std::istream::traits_type::eof ()) \ + { \ + if (char_class.find (c) != std::string::npos) \ + buf << static_cast (c); \ + else \ + { \ + is.putback (c); \ + break; \ + } \ + } \ } \ else \ { \ int chars_read = 0; \ while (is && chars_read++ < width \ - && (c = is.get ()) != std::istream::traits_type::eof () \ - && char_class.find (c) == std::string::npos) \ - buf << static_cast (c); \ + && (c = is.get ()) != std::istream::traits_type::eof ()) \ + { \ + if (char_class.find (c) == std::string::npos) \ + buf << static_cast (c); \ + else \ + { \ + is.putback (c); \ + break; \ + } \ + } \ } \ \ - if (width == std::numeric_limits::max () \ - && c != std::istream::traits_type::eof ()) \ - is.putback (c); \ - \ tmp = buf.str (); \ \ if (tmp.empty ()) \ is.setstate (std::ios::failbit); \ else if (c == std::istream::traits_type::eof ()) \ - is.clear (); \ + is.clear (is.rdstate () & (~std::ios::failbit)); \ \ } \ while (0) @@ -4676,7 +4668,7 @@ tmp = string::u8_from_encoding (who, tmp, encoding ()); \ width = tmp.length (); \ \ - if (is) \ + if (is && width > 0) \ { \ int i = 0; \ \ @@ -5048,10 +5040,10 @@ // If it looks like we have a matching failure, then // reset the failbit in the stream state. - if (! is.eof () && is.rdstate () & std::ios::failbit) + if (is.rdstate () & std::ios::failbit) { - error (who, "format failed to match"); is.clear (is.rdstate () & (~std::ios::failbit)); + error (who, "format failed to match"); } // FIXME: is this the right thing to do? @@ -5470,7 +5462,7 @@ // (output streams are those that define os). int -base_stream::flush (void) +base_stream::flush () { int retval = -1; @@ -5510,13 +5502,9 @@ } } - // No copying! - - printf_value_cache (const printf_value_cache&) = delete; - - printf_value_cache& operator = (const printf_value_cache&) = delete; - - ~printf_value_cache (void) = default; + OCTAVE_DISABLE_COPY_MOVE (printf_value_cache) + + ~printf_value_cache () = default; // Get the current value as a double and advance the internal pointer. octave_value get_next_value (char type = 0); @@ -5525,16 +5513,16 @@ // pointer. Value before conversion to int must be >= 0 and less // than std::numeric_limits::max (). - int int_value (void); + int int_value (); operator bool () const { return (m_curr_state == ok); } - bool exhausted (void) { return (m_val_idx >= m_n_vals); } + bool exhausted () { return (m_val_idx >= m_n_vals); } private: // Must create value cache with values! - printf_value_cache (void); + printf_value_cache (); //-------- @@ -5664,7 +5652,7 @@ } int -printf_value_cache::int_value (void) +printf_value_cache::int_value () { octave_value val = get_next_value (); @@ -6132,7 +6120,7 @@ } int -stream::flush (void) +stream::flush () { int retval = -1; @@ -6372,7 +6360,7 @@ } off_t -stream::tell (void) +stream::tell () { off_t retval = -1; @@ -6383,13 +6371,13 @@ } int -stream::rewind (void) +stream::rewind () { return seek (0, SEEK_SET); } bool -stream::is_open (void) const +stream::is_open () const { bool retval = false; @@ -6400,7 +6388,7 @@ } void -stream::close (void) +stream::close () { if (stream_ok ()) { @@ -7297,7 +7285,7 @@ } bool -stream::eof (void) const +stream::eof () const { int retval = -1; @@ -7319,7 +7307,7 @@ } std::string -stream::name (void) const +stream::name () const { std::string retval; @@ -7330,7 +7318,7 @@ } int -stream::mode (void) const +stream::mode () const { int retval = 0; @@ -7341,7 +7329,7 @@ } mach_info::float_format -stream::float_format (void) const +stream::float_format () const { mach_info::float_format retval = mach_info::flt_fmt_unknown; @@ -7412,7 +7400,7 @@ m_stderr_file = insert (stderr_stream); } -stream_list::~stream_list (void) +stream_list::~stream_list () { clear (); } @@ -7620,7 +7608,7 @@ return get_info (int_fid); } -std::string stream_list::list_open_files (void) const +std::string stream_list::list_open_files () const { std::ostringstream buf; @@ -7652,7 +7640,7 @@ return buf.str (); } -octave_value stream_list::open_file_numbers (void) const +octave_value stream_list::open_file_numbers () const { Matrix retval (1, m_list.size (), 0.0); @@ -7710,17 +7698,17 @@ return retval; } -octave_value stream_list::stdin_file (void) const +octave_value stream_list::stdin_file () const { return octave_value (m_stdin_file); } -octave_value stream_list::stdout_file (void) const +octave_value stream_list::stdout_file () const { return octave_value (m_stdout_file); } -octave_value stream_list::stderr_file (void) const +octave_value stream_list::stderr_file () const { return octave_value (m_stderr_file); } diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/oct-stream.h --- a/libinterp/corefcn/oct-stream.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/oct-stream.h Fri May 12 08:03:14 2023 +0200 @@ -79,13 +79,9 @@ m_errmsg () { } - // No copying! - - base_stream (const base_stream&) = delete; + OCTAVE_DISABLE_COPY_MOVE (base_stream) - base_stream& operator = (const base_stream&) = delete; - - virtual ~base_stream (void) = default; + virtual ~base_stream () = default; // The remaining functions are not specific to input or output only, // and must be provided by the derived classes. @@ -96,32 +92,32 @@ // Return current stream position. - virtual off_t tell (void) = 0; + virtual off_t tell () = 0; // Return TRUE if EOF has been reached on this stream. - virtual bool eof (void) const = 0; + virtual bool eof () const = 0; // The name of the file. - virtual std::string name (void) const = 0; + virtual std::string name () const = 0; // If the derived class provides this function and it returns a // pointer to a valid istream, scanf(), read(), getl(), and gets() // will automatically work for this stream. - virtual std::istream * input_stream (void) { return nullptr; } + virtual std::istream * input_stream () { return nullptr; } // If the derived class provides this function and it returns a // pointer to a valid ostream, flush(), write(), and printf() will // automatically work for this stream. - virtual std::ostream * output_stream (void) { return nullptr; } + virtual std::ostream * output_stream () { return nullptr; } // Return either the original output stream or one wrapped with the // encoding facet. - std::ostream * preferred_output_stream (void) + std::ostream * preferred_output_stream () { if (! m_encoding.compare ("utf-8")) return output_stream (); @@ -145,11 +141,11 @@ // Return TRUE if this stream is open. - bool is_open (void) const { return m_open_state; } + bool is_open () const { return m_open_state; } - virtual void do_close (void) { } + virtual void do_close () { } - void close (void) + void close () { if (is_open ()) { @@ -158,7 +154,7 @@ } } - virtual int file_number (void) const + virtual int file_number () const { // Kluge alert! @@ -172,7 +168,7 @@ return -1; } - bool ok (void) const { return ! m_fail; } + bool ok () const { return ! m_fail; } // Return current error message for this stream. @@ -180,11 +176,11 @@ protected: - int mode (void) const { return m_mode; } + int mode () const { return m_mode; } - mach_info::float_format float_format (void) const { return m_flt_fmt; } + mach_info::float_format float_format () const { return m_flt_fmt; } - std::string encoding (void) const { return m_encoding; } + std::string encoding () const { return m_encoding; } // Set current error state and set fail to TRUE. @@ -193,11 +189,11 @@ // Clear any error message and set fail to FALSE. - OCTINTERP_API void clear (void); + OCTINTERP_API void clear (); // Clear stream state. - OCTINTERP_API void clearerr (void); + OCTINTERP_API void clearerr (); private: @@ -273,7 +269,7 @@ // Functions that are defined for all output streams (output streams // are those that define os). - OCTINTERP_API int flush (void); + OCTINTERP_API int flush (); OCTINTERP_API int do_numeric_printf_conv (std::ostream& os, const printf_format_elt *elt, @@ -314,9 +310,9 @@ stream& operator = (const stream&) = default; - ~stream (void) = default; + ~stream () = default; - OCTINTERP_API int flush (void); + OCTINTERP_API int flush (); OCTINTERP_API std::string getl (octave_idx_type max_len, bool& err, @@ -346,13 +342,13 @@ OCTINTERP_API int seek (const octave_value& offset, const octave_value& origin); - OCTINTERP_API off_t tell (void); + OCTINTERP_API off_t tell (); - OCTINTERP_API int rewind (void); + OCTINTERP_API int rewind (); - OCTINTERP_API bool is_open (void) const; + OCTINTERP_API bool is_open () const; - OCTINTERP_API void close (void); + OCTINTERP_API void close (); OCTINTERP_API octave_value read (const Array& size, octave_idx_type block_size, @@ -408,7 +404,7 @@ OCTINTERP_API int puts (const octave_value& s, const std::string& who /* = "puts" */); - OCTINTERP_API bool eof (void) const; + OCTINTERP_API bool eof () const; OCTINTERP_API std::string error (bool clear, int& err_num); @@ -428,33 +424,33 @@ void error (const char *msg) { error (std::string (msg)); } - int file_number (void) { return m_rep ? m_rep->file_number () : -1; } + int file_number () { return m_rep ? m_rep->file_number () : -1; } - bool is_valid (void) const { return bool (m_rep); } + bool is_valid () const { return bool (m_rep); } - bool ok (void) const { return m_rep && m_rep->ok (); } + bool ok () const { return m_rep && m_rep->ok (); } operator bool () const { return ok (); } - OCTINTERP_API std::string name (void) const; + OCTINTERP_API std::string name () const; - OCTINTERP_API int mode (void) const; + OCTINTERP_API int mode () const; - OCTINTERP_API mach_info::float_format float_format (void) const; + OCTINTERP_API mach_info::float_format float_format () const; OCTINTERP_API static std::string mode_as_string (int mode); - std::string encoding (void) + std::string encoding () { return m_rep ? m_rep->encoding () : std::string (); } - std::istream * input_stream (void) + std::istream * input_stream () { return m_rep ? m_rep->input_stream () : nullptr; } - std::ostream * output_stream (void) + std::ostream * output_stream () { return (m_rep ? m_rep->output_stream () : nullptr); } @@ -465,7 +461,7 @@ return (m_rep ? m_rep->preferred_output_stream () : nullptr); } - void clearerr (void) { if (m_rep) m_rep->clearerr (); } + void clearerr () { if (m_rep) m_rep->clearerr (); } private: @@ -511,10 +507,9 @@ OCTINTERP_API stream_list (interpreter& interp); - stream_list (const stream_list&) = delete; - stream_list& operator = (const stream_list&) = delete; + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (stream_list) - OCTINTERP_API ~stream_list (void); + OCTINTERP_API ~stream_list (); OCTINTERP_API int insert (stream& os); @@ -531,15 +526,15 @@ OCTINTERP_API string_vector get_info (int fid) const; OCTINTERP_API string_vector get_info (const octave_value& fid) const; - OCTINTERP_API std::string list_open_files (void) const; + OCTINTERP_API std::string list_open_files () const; - OCTINTERP_API octave_value open_file_numbers (void) const; + OCTINTERP_API octave_value open_file_numbers () const; OCTINTERP_API int get_file_number (const octave_value& fid) const; - OCTINTERP_API octave_value stdin_file (void) const; - OCTINTERP_API octave_value stdout_file (void) const; - OCTINTERP_API octave_value stderr_file (void) const; + OCTINTERP_API octave_value stdin_file () const; + OCTINTERP_API octave_value stdout_file () const; + OCTINTERP_API octave_value stderr_file () const; private: diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/oct-strstrm.cc --- a/libinterp/corefcn/oct-strstrm.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/oct-strstrm.cc Fri May 12 08:03:14 2023 +0200 @@ -45,7 +45,7 @@ // Return current stream position. off_t -base_strstream::tell (void) +base_strstream::tell () { // Note: error is inherited from base_stream, not ::error. // This error function does not halt execution so "return ..." must exist. diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/oct-strstrm.h --- a/libinterp/corefcn/oct-strstrm.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/oct-strstrm.h Fri May 12 08:03:14 2023 +0200 @@ -46,15 +46,11 @@ const std::string& encoding = "utf-8") : base_stream (m, ff, encoding) { } - // No copying! - - base_strstream (const base_strstream&) = delete; - - base_strstream& operator = (const base_strstream&) = delete; + OCTAVE_DISABLE_COPY_MOVE (base_strstream) protected: - ~base_strstream (void) = default; + ~base_strstream () = default; public: @@ -64,17 +60,17 @@ // Return current stream position. - virtual off_t tell (void); + virtual off_t tell (); // The name of the file. - std::string name (void) const { return ""; } + std::string name () const { return ""; } - virtual std::streambuf * rdbuf (void) = 0; + virtual std::streambuf * rdbuf () = 0; - virtual bool bad (void) const = 0; + virtual bool bad () const = 0; - virtual void clear (void) = 0; + virtual void clear () = 0; }; class @@ -94,15 +90,11 @@ const std::string& encoding = "utf-8") : base_strstream (arg_md, ff, encoding), m_istream (data) { } - // No copying! - - istrstream (const istrstream&) = delete; - - istrstream& operator = (const istrstream&) = delete; + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (istrstream) protected: - ~istrstream (void) = default; + ~istrstream () = default; public: @@ -119,22 +111,22 @@ // Return nonzero if EOF has been reached on this stream. - bool eof (void) const { return m_istream.eof (); } + bool eof () const { return m_istream.eof (); } - std::istream * input_stream (void) { return &m_istream; } + std::istream * input_stream () { return &m_istream; } - std::ostream * output_stream (void) { return nullptr; } + std::ostream * output_stream () { return nullptr; } - off_t tell (void) { return m_istream.tellg (); } + off_t tell () { return m_istream.tellg (); } - std::streambuf * rdbuf (void) + std::streambuf * rdbuf () { return m_istream ? m_istream.rdbuf () : nullptr; } - bool bad (void) const { return m_istream.bad (); } + bool bad () const { return m_istream.bad (); } - void clear (void) { m_istream.clear (); } + void clear () { m_istream.clear (); } private: @@ -151,15 +143,11 @@ const std::string& encoding = "utf-8") : base_strstream (arg_md, ff, encoding), m_ostream () { } - // No copying! - - ostrstream (const ostrstream&) = delete; - - ostrstream& operator = (const ostrstream&) = delete; + OCTAVE_DISABLE_COPY_MOVE (ostrstream) protected: - ~ostrstream (void) = default; + ~ostrstream () = default; public: @@ -170,22 +158,22 @@ // Return nonzero if EOF has been reached on this stream. - bool eof (void) const { return m_ostream.eof (); } + bool eof () const { return m_ostream.eof (); } - std::istream * input_stream (void) { return nullptr; } + std::istream * input_stream () { return nullptr; } - std::ostream * output_stream (void) { return &m_ostream; } + std::ostream * output_stream () { return &m_ostream; } - std::string str (void) { return m_ostream.str (); } + std::string str () { return m_ostream.str (); } - std::streambuf * rdbuf (void) + std::streambuf * rdbuf () { return m_ostream ? m_ostream.rdbuf () : nullptr; } - bool bad (void) const { return m_ostream.bad (); } + bool bad () const { return m_ostream.bad (); } - void clear (void) { m_ostream.clear (); } + void clear () { m_ostream.clear (); } private: @@ -194,17 +182,4 @@ OCTAVE_END_NAMESPACE(octave) -#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS) - -OCTAVE_DEPRECATED (7, "use 'octave::base_strstream' instead") -typedef octave::base_strstream octave_base_strstream; - -OCTAVE_DEPRECATED (7, "use 'octave::istrstream' instead") -typedef octave::istrstream octave_istrstream; - -OCTAVE_DEPRECATED (7, "use 'octave::ostrstream' instead") -typedef octave::ostrstream octave_ostrstream; - #endif - -#endif diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/oct-tex-lexer.in.ll --- a/libinterp/corefcn/oct-tex-lexer.in.ll Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/oct-tex-lexer.in.ll Fri May 12 08:03:14 2023 +0200 @@ -237,7 +237,7 @@ return (m_scanner && m_buffer_state); } - void text_parser_tex::destroy_lexer (void) + void text_parser_tex::destroy_lexer () { if (m_buffer_state) { diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/ordschur.cc --- a/libinterp/corefcn/ordschur.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/ordschur.cc Fri May 12 08:03:14 2023 +0200 @@ -82,8 +82,7 @@ if (args.length () != 3) print_usage (); - const Array sel_arg = args( - 2).xoctave_idx_type_vector_value ("ordschur: SELECT must be an array of integers"); + const Array sel_arg = args(2).xoctave_idx_type_vector_value ("ordschur: SELECT must be an array of integers"); const octave_idx_type sel_n = sel_arg.numel (); @@ -98,10 +97,8 @@ octave_value_list retval; - const bool double_type = args(0).is_double_type () - || args(1).is_double_type (); - const bool complex_type = args(0).iscomplex () - || args(1).iscomplex (); + const bool double_type = args(0).is_double_type () || args(1).is_double_type (); + const bool complex_type = args(0).iscomplex () || args(1).iscomplex (); #define PREPARE_ARGS(TYPE, TYPE_M, TYPE_COND) \ TYPE ## Matrix U = args(0).x ## TYPE_M ## _value \ diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/pager.cc --- a/libinterp/corefcn/pager.cc Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/pager.cc Fri May 12 08:03:14 2023 +0200 @@ -114,7 +114,7 @@ return false; } -static std::string default_pager (void) +static std::string default_pager () { std::string pager_binary = sys::env::getenv ("PAGER"); @@ -125,7 +125,7 @@ } int -pager_buf::sync (void) +pager_buf::sync () { output_system& output_sys = __get_output_system__ (); @@ -144,7 +144,7 @@ } void -pager_buf::flush_current_contents_to_diary (void) +pager_buf::flush_current_contents_to_diary () { char *buf = pbase () + m_diary_skip; @@ -156,13 +156,13 @@ } void -pager_buf::set_diary_skip (void) +pager_buf::set_diary_skip () { m_diary_skip = pptr () - pbase (); } int -diary_buf::sync (void) +diary_buf::sync () { output_system& output_sys = __get_output_system__ (); @@ -183,31 +183,31 @@ return 0; } -pager_stream::pager_stream (void) : std::ostream (nullptr), m_pb (nullptr) +pager_stream::pager_stream () : std::ostream (nullptr), m_pb (nullptr) { m_pb = new pager_buf (); rdbuf (m_pb); setf (unitbuf); } -pager_stream::~pager_stream (void) +pager_stream::~pager_stream () { flush (); delete m_pb; } -std::ostream& pager_stream::stream (void) +std::ostream& pager_stream::stream () { return *this; } -void pager_stream::flush_current_contents_to_diary (void) +void pager_stream::flush_current_contents_to_diary () { if (m_pb) m_pb->flush_current_contents_to_diary (); } -void pager_stream::set_diary_skip (void) +void pager_stream::set_diary_skip () { if (m_pb) m_pb->set_diary_skip (); @@ -218,7 +218,7 @@ // called when the pager is not in use. For example, just before // getting command-line input. -void pager_stream::reset (void) +void pager_stream::reset () { delete m_pb; m_pb = new pager_buf (); @@ -226,20 +226,20 @@ setf (unitbuf); } -diary_stream::diary_stream (void) : std::ostream (nullptr), m_db (nullptr) +diary_stream::diary_stream () : std::ostream (nullptr), m_db (nullptr) { m_db = new diary_buf (); rdbuf (m_db); setf (unitbuf); } -diary_stream::~diary_stream (void) +diary_stream::~diary_stream () { flush (); delete m_db; } -std::ostream& diary_stream::stream (void) +std::ostream& diary_stream::stream () { return *this; } @@ -249,7 +249,7 @@ // called when the pager is not in use. For example, just before // getting command-line input. -void diary_stream::reset (void) +void diary_stream::reset () { delete m_db; m_db = new diary_buf (); @@ -257,7 +257,7 @@ setf (unitbuf); } -void flush_stdout (void) +void flush_stdout () { output_system& output_sys = __get_output_system__ (); @@ -302,7 +302,7 @@ "page_screen_output"); } -std::string output_system::pager_command (void) const +std::string output_system::pager_command () const { std::string cmd = m_PAGER; @@ -312,7 +312,7 @@ return cmd; } -void output_system::reset (void) +void output_system::reset () { flush_stdout (); @@ -320,7 +320,7 @@ m_diary_stream.reset (); } -void output_system::flush_stdout (void) +void output_system::flush_stdout () { if (! m_flushing_output_to_pager) { @@ -338,7 +338,7 @@ } } -void output_system::close_diary (void) +void output_system::close_diary () { // Try to flush the current buffer to the diary now, so that things // like @@ -360,7 +360,7 @@ } } -void output_system::open_diary (void) +void output_system::open_diary () { close_diary (); @@ -406,7 +406,7 @@ return false; } -void output_system::clear_external_pager (void) +void output_system::clear_external_pager () { if (m_external_pager) { @@ -419,7 +419,7 @@ } } -void output_system::start_external_pager (void) +void output_system::start_external_pager () { if (m_external_pager) return; @@ -489,14 +489,14 @@ } } -std::ostream& __stdout__ (void) +std::ostream& __stdout__ () { output_system& output_sys = __get_output_system__ (); return output_sys.__stdout__ (); } -std::ostream& __diary__ (void) +std::ostream& __diary__ () { output_system& output_sys = __get_output_system__ (); diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/pager.h --- a/libinterp/corefcn/pager.h Fri May 12 08:00:41 2023 +0200 +++ b/libinterp/corefcn/pager.h Fri May 12 08:03:14 2023 +0200 @@ -47,15 +47,19 @@ { public: - pager_buf (void) : std::stringbuf (), m_diary_skip (0) { } + pager_buf () : std::stringbuf (), m_diary_skip (0) { } + + OCTAVE_DISABLE_COPY_MOVE (pager_buf) - void flush_current_contents_to_diary (void); + ~pager_buf () = default; - void set_diary_skip (void); + void flush_current_contents_to_diary (); + + void set_diary_skip (); protected: - int sync (void); + int sync (); private: @@ -68,23 +72,19 @@ { public: - pager_stream (void); - - // No copying! + pager_stream (); - pager_stream (const pager_stream&) = delete; + OCTAVE_DISABLE_COPY_MOVE (pager_stream) - pager_stream& operator = (const pager_stream&) = delete; + ~pager_stream (); - ~pager_stream (void); + void flush_current_contents_to_diary (); - void flush_current_contents_to_diary (void); + void set_diary_skip (); - void set_diary_skip (void); + std::ostream& stream (); - std::ostream& stream (void); - - void reset (void); + void reset (); private: @@ -97,11 +97,12 @@ { public: - diary_buf (void) : std::stringbuf () { } + OCTAVE_DEFAULT_CONSTRUCT_DELETE (diary_buf) + OCTAVE_DISABLE_COPY_MOVE (diary_buf) protected: - int sync (void); + int sync (); }; class @@ -110,26 +111,22 @@ { public: - diary_stream (void); + diary_stream (); - // No copying! - - diary_stream (const diary_stream&) = delete; + OCTAVE_DISABLE_COPY_MOVE (diary_stream) - diary_stream& operator = (const diary_stream&) = delete; - - ~diary_stream (void); + ~diary_stream (); - std::ostream& stream (void); + std::ostream& stream (); - void reset (void); + void reset (); private: diary_buf *m_db; }; -extern OCTINTERP_API void flush_stdout (void); +extern OCTINTERP_API void flush_stdout (); class output_system { @@ -137,17 +134,15 @@ output_system (interpreter& interp); - output_system (const output_system&) = delete; + OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (output_system) - output_system& operator = (const output_system&) = delete; - - ~output_system (void) = default; + ~output_system () = default; - pager_stream& pager (void) { return m_pager_stream; } + pager_stream& pager () { return m_pager_stream; } - diary_stream& diary (void) { return m_diary_stream; } + diary_stream& diary () { return m_diary_stream; } - std::string diary_file_name (void) const { return m_diary_file_name; } + std::string diary_file_name () const { return m_diary_file_name; } std::string diary_file_name (const std::string& nm) { @@ -158,7 +153,7 @@ octave_value PAGER (const octave_value_list& args, int nargout); - std::string PAGER (void) const { return m_PAGER; } + std::string PAGER () const { return m_PAGER; } std::string PAGER (const std::string& s) { @@ -169,7 +164,7 @@ octave_value PAGER_FLAGS (const octave_value_list& args, int nargout); - std::string PAGER_FLAGS (void) const { return m_PAGER_FLAGS; } + std::string PAGER_FLAGS () const { return m_PAGER_FLAGS; } std::string PAGER_FLAGS (const std::string& s) { @@ -181,7 +176,7 @@ octave_value page_output_immediately (const octave_value_list& args, int nargout); - bool page_output_immediately (void) const + bool page_output_immediately () const { return m_page_output_immediately; } @@ -196,7 +191,7 @@ octave_value page_screen_output (const octave_value_list& args, int nargout); - bool page_screen_output (void) const { return m_page_screen_output; } + bool page_screen_output () const { return m_page_screen_output; } bool page_screen_output (bool flag) { @@ -205,7 +200,7 @@ return val; } - bool write_to_diary_file (void) const + bool write_to_diary_file () const { return m_write_to_diary_file; } @@ -217,7 +212,7 @@ return val; } - bool really_flush_to_pager (void) const + bool really_flush_to_pager () const { return m_really_flush_to_pager; } @@ -229,7 +224,7 @@ return val; } - bool flushing_output_to_pager (void) const + bool flushing_output_to_pager () const { return m_flushing_output_to_pager; } @@ -241,25 +236,25 @@ return val; } - std::string pager_command (void) const; + std::string pager_command () const; - std::ofstream& external_diary_file (void) { return m_external_diary_file; } + std::ofstream& external_diary_file () { return m_external_diary_file; } - void reset (void); + void reset (); - void flush_stdout (void); + void flush_stdout (); bool sync (const char *msg, int len); - void clear_external_pager (void); + void clear_external_pager (); - void open_diary (void); + void open_diary (); - void close_diary (void); + void close_diary (); - std::ostream& __stdout__ (void) { return m_pager_stream.stream (); } + std::ostream& __stdout__ () { return m_pager_stream.stream (); } - std::ostream& __diary__ (void) { return m_diary_stream.stream (); } + std::ostream& __diary__ () { return m_diary_stream.stream (); } private: @@ -300,14 +295,14 @@ bool m_flushing_output_to_pager; - void start_external_pager (void); + void start_external_pager (); void do_sync (const char *msg, int len, bool bypass_pager); }; -extern OCTINTERP_API std::ostream& __stdout__ (void); +extern OCTINTERP_API std::ostream& __stdout__ (); -extern OCTINTERP_API std::ostream& __diary__ (void); +extern OCTINTERP_API std::ostream& __diary__ (); OCTAVE_END_NAMESPACE(octave) diff -r e2911d0176dc -r 212145b8e5f0 libinterp/corefcn/perms.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libinterp/corefcn/perms.cc Fri May 12 08:03:14 2023 +0200 @@ -0,0 +1,398 @@ +//////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2023 The Octave Project Developers +// +// See the file COPYRIGHT.md in the top-level directory of this +// distribution or . +// +// 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 +// . +// +//////////////////////////////////////////////////////////////////////// + +#if defined(HAVE_CONFIG_H) +# include "config.h" +#endif + +#include + +#include "defun.h" +#include "error.h" +#include "errwarn.h" +#include "ovl.h" + +OCTAVE_BEGIN_NAMESPACE (octave) + +static inline double +Factorial (octave_idx_type n) +{ + double ret = 1; + for (octave_idx_type i = 2; i <= n; i++) + ret *= i; + return ret; +} + +// +// Use C++ template to cater for the different octave array classes. +// +template +static inline Array +GetPerms (const Array &ar_in, bool uniq_v, bool do_sort = false) +{ + octave_idx_type m = ar_in.numel (); + double nr = Factorial (m); + + // Setup index vector filled from 0..m-1 + int myvidx[m]; + for (int i = 0; i < m; i++) + myvidx[i] = i; + + // Interim array to sort ar_in for octave sort order and to implement + // "unique". + Array ar (ar_in); + + if (uniq_v) + { + ar = ar.sort (ar.dims () (1) > ar.dims () (0) ? 1 : 0, ASCENDING); + const T *Ar = ar.data (); + int ctr = 0; + int N_el = 1; + + // Number of same elements where we need to remove permutations + // Number of unique permutations is n! / (n_el1! * n_el2! * ...) + for (octave_idx_type i = 0; i < m - 1; i++) + { + myvidx[i] = ctr; + if (Ar[i + 1] != Ar[i]) + { + nr /= Factorial (N_el); + ctr = i + 1; // index of next different element + N_el = 1; + } + else + N_el++; + } + myvidx[m - 1] = ctr; + nr /= Factorial (N_el); + } + else if (do_sort) + { + ar = ar.sort (ar.dims () (1) > ar.dims () (0) ? 1 : 0, ASCENDING); + } + + // Sort vector indices for inverse lexicographic order later. + std::sort (myvidx, myvidx + m, std::greater ()); + + const T *Ar = ar.data (); + + // Set up result array + octave_idx_type n = static_cast (nr); + Array res (dim_vector (n, m)); + T *Res = res.fortran_vec (); + + // Do the actual job + octave_idx_type i = 0; + std::sort (myvidx, myvidx + m, std::greater ()); + do + { + for (octave_idx_type j = 0; j < m; j++) + Res[i + j * n] = Ar[myvidx[j]]; + i++; + } + while (std::next_permutation (myvidx, myvidx + m, std::greater ())); + + return res; +} + +// Template for non-numerical types (e.g. Cell) without sorting. +// The C++ compiler complains as the provided type octave_value does not +// support the test of equality via '==' in the above template. + +template +static inline Array +GetPermsNoSort (const Array &ar_in, bool uniq_v = false) +{ + octave_idx_type m = ar_in.numel (); + double nr = Factorial (m); + + // Setup index vector filled from 0..m-1 + int myvidx[m]; + for (int i = 0; i < m; i++) + myvidx[i] = i; + + const T *Ar = ar_in.data (); + + if (uniq_v) + { + // Mutual Comparison using is_equal to detect duplicated values + int N_el = 1; + // Number of unique permutations is n! / (n_el1! * n_el2! * ...) + for (octave_idx_type i = 0; i < m - 1; i++) + { + for (octave_idx_type j = i + 1; j < m; j++) + { + if (myvidx[j] > myvidx[i] && Ar[i].is_equal (Ar[j])) + { + myvidx[j] = myvidx[i]; // not yet processed... + N_el++; + } + else + { + nr /= Factorial (N_el); + N_el = 1; + } + } + } + nr /= Factorial (N_el); + } + + // Sort vector indices for inverse lexicographic order later. + std::sort (myvidx, myvidx + m, std::greater ()); + + // Set up result array + octave_idx_type n = static_cast (nr); + Array res (dim_vector (n, m)); + T *Res = res.fortran_vec (); + + // Do the actual job + octave_idx_type i = 0; + do + { + for (octave_idx_type j = 0; j < m; j++) + Res[i + j * n] = Ar[myvidx[j]]; + i++; + } + while (std::next_permutation (myvidx, myvidx + m, std::greater ())); + return res; +} + +DEFUN (perms, args, , + doc: /* -*- texinfo -*- +@deftypefn {} {@var{P} =} perms (@var{v}) +@deftypefnx {} {@var{P} =} perms (@var{v}, "unique") +Generate all permutations of vector @var{v} with one row per permutation. + +Results are returned in reverse lexicographic order if @var{v} is in ascending +order. If @var{v} is in a different permutation, then the result is permuted +that way too. Consequently, an input in descending order yields a result in +normal lexicographic order. The result has size +@code{factorial (@var{n}) * @var{n}}, where @var{n} is the length of @var{v}. +Any repeated elements are included in the output. + +If the optional argument @qcode{"unique"} is given then only unique +permutations are returned, using less memory and taking less time than calling +@code{unique (perms (@var{v}), "rows")}. + +Example 1 + +@example +@group +perms ([1, 2, 3]) +@result{} +3 2 1 +3 1 2 +2 3 1 +2 1 3 +1 3 2 +1 2 3 +@end group +@end example + +Example 2 + +@example +@group +perms ([1, 1, 2, 2], "unique") +@result{} +2 2 1 1 +2 1 2 1 +2 1 1 2 +1 2 2 1 +1 2 1 2 +1 1 2 2 +@end group +@end example + +Programming Note: If the @qcode{"unique"} option is not used, the length of +@var{v} should be no more than 10-12 to limit memory consumption. Even with +@qcode{"unique"}, there should be no more than 10-12 unique elements in +@var{v}. +@seealso{permute, randperm, nchoosek} + +@end deftypefn */) +{ + int nargin = args.length (); + + if (nargin < 1 || nargin > 2) + print_usage (); + + octave_value retval; + + // Parameter check "unique" + bool uniq_v = false; + if (nargin == 2) + { + const charMatrix opt = args (1).char_matrix_value (); + const char *str = opt.data (); + if (std::string (str, opt.cols ()) != "unique") + { + error ("perms: option must be the string \"unique\"."); + } + uniq_v = true; + } + + if (! (args (0).is_matrix_type () || args (0).is_range () + || args (0).iscell () || args (0).is_scalar_type () + || args (0).isstruct ())) + { + error ("perms: INPUT must be a matrix, a range, a cell array, " + "a struct or a scalar."); + } + + std::string clname = args (0).class_name (); + + // Execute main permutation code for the different classes + if (clname == "double") + retval = GetPerms (args (0).array_value (), uniq_v); + else if (clname == "single") + retval = GetPerms (args (0).float_array_value (), uniq_v); + else if (clname == "logical") + retval = GetPerms (args (0).bool_array_value (), uniq_v); + else if (clname == "char") + retval = GetPerms (args (0).char_array_value (), uniq_v); + else if (clname == "int8") + retval = GetPerms (args (0).int8_array_value (), uniq_v); + else if (clname == "int16") + retval = GetPerms (args (0).int16_array_value (), uniq_v); + else if (clname == "int32") + retval = GetPerms (args (0).int32_array_value (), uniq_v); + else if (clname == "int64") + retval = GetPerms (args (0).int64_array_value (), uniq_v); + else if (clname == "uint8") + retval = GetPerms (args (0).uint8_array_value (), uniq_v); + else if (clname == "uint16") + retval = GetPerms (args (0).uint16_array_value (), uniq_v); + else if (clname == "uint32") + retval = GetPerms (args (0).uint32_array_value (), uniq_v); + else if (clname == "uint64") + retval = GetPerms (args (0).uint64_array_value (), uniq_v); + else if (clname == "cell") + retval = GetPermsNoSort (args (0).cell_value (), uniq_v); + else if (clname == "struct") + { + const octave_map map_in (args (0).map_value ()); + string_vector fn = map_in.fieldnames (); + if (fn.numel () == 0 && map_in.numel () != 0) + { + octave_scalar_map out; + retval = out; + } + else + { + octave_map out; + if (fn.numel () == 0) + { + out = octave_map (dim_vector (1, 0)); + } + else + { + for (octave_idx_type i = 0; i < fn.numel (); i++) + { + out.assign (fn (i), GetPermsNoSort + (map_in.contents (fn (i)), uniq_v)); + } + } + retval = out; + } + } + else // none of the above class criteria were met + { + warning ("perms: unable to permute for class %s", clname.c_str ()); + // retval stays empty + } + return ovl (retval); +} + +/* + +%!assert (rows (perms (1:6)), factorial (6)) +%!assert (perms (pi), pi) +%!assert (perms ([e, pi]), [pi, e; e, pi]) +%!assert (perms ([pi, e]), [e, pi; pi, e]) +%!assert (perms ([1 2 3]), [3 2 1; 3 1 2; 2 3 1; 2 1 3; 1 3 2; 1 2 3]) +%!assert (sortrows (perms (1:5)), sortrows (perms ([2 5 4 1 3]'))) +%!assert (perms ("abc"), char ("cba", "cab", "bca", "bac", "acb", "abc")) +%!assert (sortrows (perms ("fobar")), unique (perms ("fobar"), "rows")) +%!assert (unique (perms (1:5)(:))', 1:5) +%!assert (perms (int8 (1:4)), int8 (perms (1:4))) + +%!assert (sortrows (perms ("abb", "unique")), ["abb"; "bab"; "bba"]) +%!assert (size (perms ([1 1 1 1 2 2 2 3 3], "unique")), [1260 9]) +%!assert (size (perms (int8([1 1 1 1 1 2 2 2 2 3 3 3]), "unique")), [27720 12]) + +## Should work for any array type, such as cells and structs, +## and not only for numeric data. + +%!assert <*52431> (perms ({1}), {1}) +%!assert <*52431> (perms ({0.1, "foo"}), {"foo", 0.1; 0.1, "foo"}) +%!assert <*52431> (perms ({"foo", 0.1}), {0.1, "foo"; "foo", 0.1}) +%!assert <*52431> (perms ({"foo"; 0.1}), {0.1, "foo"; "foo", 0.1}) +%!assert <*52431> (perms ({0.1; "foo"}), {"foo", 0.1; 0.1, "foo"}) +%!assert <*52431> (perms ({"foo", "bar"}), {"bar", "foo"; "foo", "bar"}) +%!assert <*52431> (perms ({"bar", "foo"}), {"foo", "bar"; "bar", "foo"}) +%! +%!assert <*52431> (perms (struct ()), struct ()) +%!assert <*52431> (perms (struct ("foo", {1, 2})), +%! struct ("foo", {2, 1; 1, 2})) +%!assert <*52431> (perms (struct ("foo", {1, 2}, "bar", {3, 4})), +%! struct ("foo", {2, 1; 1, 2}, "bar", {4, 3; 3, 4})) + +## Also sort logical input with order dependent on the input order and +## not their values. + +%!assert <*52431> (perms (logical ([1 0])), logical ([0 1;, 1 0])) +%!assert <*52431> (perms (logical ([0 1])), logical ([1 0; 0 1])) +%!assert <*52431> (perms (logical ([0 1 0])), +%! logical ([0 1 0; 0 0 1; 1 0 0; 1 0 0; 0 0 1; 0 1 0])) +%!assert <*52431> (perms (logical ([0 1 1])), +%! logical ([1 1 0; 1 0 1; 1 1 0; 1 0 1; 0 1 1; 0 1 1])) + +%!assert <*52432> (perms ([]), reshape ([], 1, 0)) +%!assert <*52432> (perms (single ([])), reshape (single ([]), 1, 0)) +%!assert <*52432> (perms (int8 ([])), reshape (int8 ([]), 1, 0)) +%!assert <*52432> (perms ({}), cell (1, 0)) + +%!test <*52432> +%! s = struct (); +%! s(1) = []; +%! assert (perms (reshape (s, 0, 0)), reshape (s, 1, 0)); +%! assert (perms (reshape (s, 0, 1)), reshape (s, 1, 0)); + +## test if "unique" works also for cell arrays +%!assert <*63965> (perms ({"foo"; "foo"}, "unique"), {"foo", "foo"}) +%!assert <*63965> (perms ({"foo", "foo", "bar"}, "unique"), ... +%! {"bar", "foo", "foo"; +%! "foo", "bar", "foo"; +%! "foo", "foo", "bar"}) + +## Test input validation +%!error perms () +%!error